Skip to content

Fix SSE response format. #465

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2024
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 @@ -9,5 +9,5 @@ public class TranslationOutput
public string OutputLanguage { get; set; } = LanguageType.ENGLISH;

[JsonPropertyName("texts")]
public string[] Texts { get; set; } = Array.Empty<string>();
public TranslationInput[] Texts { get; set; } = Array.Empty<TranslationInput>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public async Task<T> Translate<T>(Agent router, string messageId, T data, string

for (var i = 0; i < texts.Count; i++)
{
map[keys[i]] = translatedTexts[i];
map[keys[i]] = translatedTexts[i].Text;
}

clonedData = Assign(clonedData, map);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,11 @@ public async Task SendMessageSse([FromRoute] string agentId,
conv.SetConversationId(conversationId, input.States);
SetStates(conv, input);

var response = new ChatResponseModel();
var response = new ChatResponseModel
{
ConversationId = conversationId,
MessageId = inputMsg.MessageId,
};

Response.StatusCode = 200;
Response.Headers.Append(Microsoft.Net.Http.Headers.HeaderNames.ContentType, "text/event-stream");
Expand All @@ -266,6 +270,7 @@ public async Task SendMessageSse([FromRoute] string agentId,

await conv.SendMessage(agentId, inputMsg,
replyMessage: input.Postback,
// responsed generated
async msg =>
{
response.Text = !string.IsNullOrEmpty(msg.SecondaryContent) ? msg.SecondaryContent : msg.Content;
Expand All @@ -274,18 +279,21 @@ await conv.SendMessage(agentId, inputMsg,
response.Instruction = msg.Instruction;
response.Data = msg.Data;

await OnChunkReceived(Response, msg);
await OnChunkReceived(Response, response);
},
// executing
async msg =>
{
var message = new RoleDialogModel(AgentRole.Function, msg.Content)
var indicator = new ChatResponseModel
{
FunctionArgs = msg.FunctionArgs,
FunctionName = msg.FunctionName,
Indication = msg.Indication
ConversationId = conversationId,
MessageId = msg.MessageId,
Text = msg.Indication,
Function = "indicating",
};
await OnChunkReceived(Response, message);
await OnChunkReceived(Response, indicator);
},
// executed
async msg =>
{

Expand All @@ -299,7 +307,7 @@ await conv.SendMessage(agentId, inputMsg,
// await OnEventCompleted(Response);
}

private async Task OnChunkReceived(HttpResponse response, RoleDialogModel message)
private async Task OnChunkReceived(HttpResponse response, ChatResponseModel message)
{
var json = JsonSerializer.Serialize(message);

Expand Down