refine chat stream code
This commit is contained in:
parent
9f7aa8f4d9
commit
da097de053
|
|
@ -62,6 +62,7 @@ public class ChatStreamMiddleware
|
||||||
var hub = services.GetRequiredService<IRealtimeHub>();
|
var hub = services.GetRequiredService<IRealtimeHub>();
|
||||||
var conn = hub.SetHubConnection(conversationId);
|
var conn = hub.SetHubConnection(conversationId);
|
||||||
conn.CurrentAgentId = agentId;
|
conn.CurrentAgentId = agentId;
|
||||||
|
InitEvents(conn);
|
||||||
|
|
||||||
// load conversation and state
|
// load conversation and state
|
||||||
var convService = services.GetRequiredService<IConversationService>();
|
var convService = services.GetRequiredService<IConversationService>();
|
||||||
|
|
@ -128,6 +129,11 @@ public class ChatStreamMiddleware
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (response.Event, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitEvents(RealtimeHubConnection conn)
|
||||||
|
{
|
||||||
conn.OnModelMessageReceived = message =>
|
conn.OnModelMessageReceived = message =>
|
||||||
JsonSerializer.Serialize(new
|
JsonSerializer.Serialize(new
|
||||||
{
|
{
|
||||||
|
|
@ -147,7 +153,5 @@ public class ChatStreamMiddleware
|
||||||
{
|
{
|
||||||
@event = "clear"
|
@event = "clear"
|
||||||
});
|
});
|
||||||
|
|
||||||
return (response.Event, data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -329,17 +329,13 @@ public class GoogleRealTimeProvider : IRealTimeCompletion
|
||||||
var words = new List<string>();
|
var words = new List<string>();
|
||||||
HookEmitter.Emit<IRealtimeHook>(_services, hook => words.AddRange(hook.OnModelTranscriptPrompt(agent)), agent.Id);
|
HookEmitter.Emit<IRealtimeHook>(_services, hook => words.AddRange(hook.OnModelTranscriptPrompt(agent)), agent.Id);
|
||||||
|
|
||||||
var functions = request.Tools?.SelectMany(s => s.FunctionDeclarations).Select(x =>
|
var functions = request.Tools?.SelectMany(s => s.FunctionDeclarations).Select(x => new FunctionDef
|
||||||
{
|
{
|
||||||
var fn = new FunctionDef
|
Name = x.Name ?? string.Empty,
|
||||||
{
|
Description = x.Description ?? string.Empty,
|
||||||
Name = x.Name ?? string.Empty,
|
Parameters = x.Parameters != null
|
||||||
Description = x.Description ?? string.Empty,
|
|
||||||
Parameters = x.Parameters != null
|
|
||||||
? JsonSerializer.Deserialize<FunctionParametersDef>(JsonSerializer.Serialize(x.Parameters))
|
? JsonSerializer.Deserialize<FunctionParametersDef>(JsonSerializer.Serialize(x.Parameters))
|
||||||
: null
|
: null
|
||||||
};
|
|
||||||
return fn;
|
|
||||||
}).ToArray();
|
}).ToArray();
|
||||||
|
|
||||||
await HookEmitter.Emit<IContentGeneratingHook>(_services,
|
await HookEmitter.Emit<IContentGeneratingHook>(_services,
|
||||||
|
|
|
||||||
|
|
@ -326,15 +326,11 @@ public class RealTimeCompletionProvider : IRealTimeCompletion
|
||||||
var (prompt, messages, options) = PrepareOptions(agent, []);
|
var (prompt, messages, options) = PrepareOptions(agent, []);
|
||||||
|
|
||||||
var instruction = messages.FirstOrDefault()?.Content.FirstOrDefault()?.Text ?? agent?.Description ?? string.Empty;
|
var instruction = messages.FirstOrDefault()?.Content.FirstOrDefault()?.Text ?? agent?.Description ?? string.Empty;
|
||||||
var functions = options.Tools.Select(x =>
|
var functions = options.Tools.Select(x => new FunctionDef
|
||||||
{
|
{
|
||||||
var fn = new FunctionDef
|
Name = x.FunctionName,
|
||||||
{
|
Description = x.FunctionDescription,
|
||||||
Name = x.FunctionName,
|
Parameters = JsonSerializer.Deserialize<FunctionParametersDef>(x.FunctionParameters)
|
||||||
Description = x.FunctionDescription
|
|
||||||
};
|
|
||||||
fn.Parameters = JsonSerializer.Deserialize<FunctionParametersDef>(x.FunctionParameters);
|
|
||||||
return fn;
|
|
||||||
}).ToArray();
|
}).ToArray();
|
||||||
|
|
||||||
var realtimeModelSettings = _services.GetRequiredService<RealtimeModelSettings>();
|
var realtimeModelSettings = _services.GetRequiredService<RealtimeModelSettings>();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue