Skip to content

Commit

Permalink
feat: update service and controller
Browse files Browse the repository at this point in the history
  • Loading branch information
arthuridea committed Dec 7, 2023
1 parent 3441e72 commit 6203b64
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions LLMServiceHub/Controller/v1_0/BaiduApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public async Task Chat(ChatRequest request)
public async Task<IActionResult> ApplyText2Img(PaintApplyRequest request)
{
var result = await _ernieVilgApiService.Text2ImgV2(request);
Response.BuildAIGeneratedResponseFeature();
return Ok(result);
}
}
Expand Down
2 changes: 1 addition & 1 deletion LLMServiceHub/Service/BaiduErnieVilgApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private async Task<PaintResultResponse> challengePaintResult(HttpClient client,
foreach (var image in images)
{
_logger.LogDebug($"{image}");
await _imageProvider.Save(image, $"/{DateTime.Now.ToString("yyyyMMddHHmmssffff")}.jpg");
await _imageProvider.Save(image, $"aigc\\images\\{DateTime.Now.ToString("yyyyMM")}\\{DateTime.Now.ToString("yyyyMMddHHmmssffff")}.jpg");
}
break;
}
Expand Down
12 changes: 8 additions & 4 deletions LLMServiceHub/Service/BaiduWenxinApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Text.Json.Serialization.Metadata;
using System.Threading;
using static System.Net.WebRequestMethods;
using LLMServiceHub.Common;

namespace LLMServiceHub.Service
{
Expand Down Expand Up @@ -117,6 +118,9 @@ public async Task Chat(ChatRequest request, HttpResponse response, CancellationT
};
#endregion

#region 设置响应头

#endregion

if (!request.Stream) // 非SSE推流格式,正常读取返回json
{
Expand All @@ -141,6 +145,7 @@ public async Task Chat(ChatRequest request, HttpResponse response, CancellationT
{
_chatDataProvider.ResetSession(request.ConversationId);
}
response.BuildAIGeneratedResponseFeature();
await response.WriteAsJsonAsync(result);

#endregion
Expand All @@ -164,10 +169,9 @@ public async Task Chat(ChatRequest request, HttpResponse response, CancellationT
var apiResponse = await _client.SendAsync(requestHttpMessage, HttpCompletionOption.ResponseHeadersRead);
apiResponse.EnsureSuccessStatusCode();

// 设置请求头
response.Headers.CacheControl = "no-cache";
// 设置请求头:返回SSE格式
response.ContentType = "text/event-stream;charset=utf-8";
// 设置响应头
// 设置响应头:返回SSE格式
response.BuildAIGeneratedResponseFeature(true);
// 在读取SSE推流前就开启输出!
await response.Body.FlushAsync();

Expand Down

0 comments on commit 6203b64

Please sign in to comment.