perf: 优化sse流式传输
This commit is contained in:
@@ -56,9 +56,14 @@ public class AzureRestChatService : IChatService
|
|||||||
httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {_options.ApiKey}");
|
httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {_options.ApiKey}");
|
||||||
// 其他头信息如Content-Type在StringContent中设置
|
// 其他头信息如Content-Type在StringContent中设置
|
||||||
|
|
||||||
var content = new StringContent(jsonBody, Encoding.UTF8, "application/json");
|
// 构造 POST 请求
|
||||||
|
var request = new HttpRequestMessage(HttpMethod.Post, apiUrl);
|
||||||
|
|
||||||
|
// 设置请求内容(示例)
|
||||||
|
request.Content =new StringContent(jsonBody, Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
// 发送POST请求
|
// 发送POST请求
|
||||||
HttpResponseMessage response = await httpClient.PostAsync(apiUrl, content, cancellationToken);
|
HttpResponseMessage response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
|
||||||
// 确认响应成功
|
// 确认响应成功
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user