Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,42 @@ public async Task<RoleDialogModel> GetChatCompletionsStreamingAsync(Agent agent,
// Prepare instruction and functions
var renderData = agentService.CollectRenderData(agent);
var (instruction, functions) = agentService.PrepareInstructionAndFunctions(agent, renderData);
if (!string.IsNullOrWhiteSpace(instruction))
{
renderedInstructions.Add(instruction);
messages.Add(new SystemChatMessage(instruction));
}

// Render functions
if (options.WebSearchOptions == null)
{
foreach (var function in functions)
{
if (!agentService.RenderFunction(agent, function, renderData))
{
continue;
}

var property = agentService.RenderFunctionProperty(agent, function, renderData);

options.Tools.Add(ChatTool.CreateFunctionTool(
functionName: function.Name,
functionDescription: function.Description,
functionParameters: BinaryData.FromObjectAsJson(property)));
}
}

if (!string.IsNullOrEmpty(agent.Knowledges))
{
messages.Add(new SystemChatMessage(agent.Knowledges));
}

var samples = ProviderHelper.GetChatSamples(agent.Samples);
foreach (var sample in samples)
{
messages.Add(sample.Role == AgentRole.User ? new UserChatMessage(sample.Content) : new AssistantChatMessage(sample.Content));
}

// Build messages
var filteredMessages = conversations.Select(x => x).ToList();
var firstUserMsgIdx = filteredMessages.FindIndex(x => x.Role == AgentRole.User);
if (firstUserMsgIdx > 0)
Expand Down Expand Up @@ -419,43 +453,6 @@ public async Task<RoleDialogModel> GetChatCompletionsStreamingAsync(Agent agent,
}
}

// Build system messages
if (!string.IsNullOrWhiteSpace(instruction))
{
renderedInstructions.Add(instruction);
messages.Add(new SystemChatMessage(instruction));
}

if (!string.IsNullOrEmpty(agent.Knowledges))
{
messages.Add(new SystemChatMessage(agent.Knowledges));
}

var samples = ProviderHelper.GetChatSamples(agent.Samples);
foreach (var sample in samples)
{
messages.Add(sample.Role == AgentRole.User ? new UserChatMessage(sample.Content) : new AssistantChatMessage(sample.Content));
}

// Render functions
if (options.WebSearchOptions == null)
{
foreach (var function in functions)
{
if (!agentService.RenderFunction(agent, function, renderData))
{
continue;
}

var property = agentService.RenderFunctionProperty(agent, function, renderData);

options.Tools.Add(ChatTool.CreateFunctionTool(
functionName: function.Name,
functionDescription: function.Description,
functionParameters: BinaryData.FromObjectAsJson(property)));
}
}

var prompt = GetPrompt(messages, options);
return (prompt, messages, options);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,37 @@ private async Task<RoleDialogModel> OnUserAudioTranscriptionCompleted(RealtimeHu
// Prepare instruction and functions
var renderData = agentService.CollectRenderData(agent);
var (instruction, functions) = agentService.PrepareInstructionAndFunctions(agent, renderData);

// Build messages
if (!string.IsNullOrWhiteSpace(instruction))
{
messages.Add(new SystemChatMessage(instruction));
}

foreach (var function in functions)
{
if (!agentService.RenderFunction(agent, function, renderData))
{
continue;
}

var property = agentService.RenderFunctionProperty(agent, function, renderData);

options.Tools.Add(ChatTool.CreateFunctionTool(
functionName: function.Name,
functionDescription: function.Description,
functionParameters: BinaryData.FromObjectAsJson(property)));
}

if (!string.IsNullOrEmpty(agent.Knowledges))
{
messages.Add(new SystemChatMessage(agent.Knowledges));
}

var samples = ProviderHelper.GetChatSamples(agent.Samples);
foreach (var sample in samples)
{
messages.Add(sample.Role == AgentRole.User ? new UserChatMessage(sample.Content) : new AssistantChatMessage(sample.Content));
}

var filteredMessages = conversations.Select(x => x).ToList();
var firstUserMsgIdx = filteredMessages.FindIndex(x => x.Role == AgentRole.User);
if (firstUserMsgIdx > 0)
Expand Down Expand Up @@ -605,39 +634,6 @@ private async Task<RoleDialogModel> OnUserAudioTranscriptionCompleted(RealtimeHu
}
}

// Build system messages
if (!string.IsNullOrWhiteSpace(instruction))
{
messages.Add(new SystemChatMessage(instruction));
}

if (!string.IsNullOrEmpty(agent.Knowledges))
{
messages.Add(new SystemChatMessage(agent.Knowledges));
}

var samples = ProviderHelper.GetChatSamples(agent.Samples);
foreach (var sample in samples)
{
messages.Add(sample.Role == AgentRole.User ? new UserChatMessage(sample.Content) : new AssistantChatMessage(sample.Content));
}

// Build functions
foreach (var function in functions)
{
if (!agentService.RenderFunction(agent, function, renderData))
{
continue;
}

var property = agentService.RenderFunctionProperty(agent, function, renderData);

options.Tools.Add(ChatTool.CreateFunctionTool(
functionName: function.Name,
functionDescription: function.Description,
functionParameters: BinaryData.FromObjectAsJson(property)));
}

var prompt = GetPrompt(messages, options);
return (prompt, messages, options);
}
Expand Down
Loading