feat: 完成ai网关改造
This commit is contained in:
@@ -25,7 +25,10 @@ public class AzureChatService : IChatService
|
||||
new AzureKeyCredential(apiKey));
|
||||
ChatClient chatClient = azureClient.GetChatClient(deploymentName);
|
||||
|
||||
var response = chatClient.CompleteChatStreamingAsync(messages, cancellationToken: cancellationToken);
|
||||
var response = chatClient.CompleteChatStreamingAsync(messages, new ChatCompletionOptions()
|
||||
{
|
||||
MaxOutputTokenCount = 2048
|
||||
}, cancellationToken: cancellationToken);
|
||||
|
||||
await foreach (StreamingChatCompletionUpdate update in response)
|
||||
{
|
||||
|
||||
@@ -19,14 +19,6 @@ public class AzureRestChatService : IChatService
|
||||
{
|
||||
// 设置API URL
|
||||
var apiUrl = $"{aiModelDescribe.Endpoint}models/chat/completions";
|
||||
|
||||
|
||||
var ss = messages.Select(x => new
|
||||
{
|
||||
role = x.GetRoleAsString(),
|
||||
content = x.Content.FirstOrDefault()?.Text
|
||||
}).ToList();
|
||||
|
||||
// 准备请求内容
|
||||
var requestBody = new
|
||||
{
|
||||
|
||||
@@ -20,10 +20,15 @@ public class UsageStatisticsAggregateRoot : FullAuditedAggregateRoot<Guid>
|
||||
public string ModelId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 总token使用
|
||||
/// 输入使用token使用
|
||||
/// </summary>
|
||||
public decimal TotalTokens { get; set; }
|
||||
public decimal InputTokens { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 输出使用token使用
|
||||
/// </summary>
|
||||
public decimal OutputTokens { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 对话次数
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Volo.Abp.Domain;
|
||||
using Yi.Framework.AiHub.Domain.AiChat;
|
||||
using Yi.Framework.AiHub.Domain.AiChat.Impl;
|
||||
using Yi.Framework.AiHub.Domain.Shared;
|
||||
using Yi.Framework.Mapster;
|
||||
|
||||
@@ -16,17 +18,16 @@ namespace Yi.Framework.AiHub.Domain
|
||||
{
|
||||
var configuration = context.Services.GetConfiguration();
|
||||
var services = context.Services;
|
||||
|
||||
|
||||
// Configure<AiGateWayOptions>(configuration.GetSection("AiGateWay"));
|
||||
//
|
||||
// services.AddKeyedTransient<IChatService, AzureChatService>(nameof(AzureChatService));
|
||||
// services.AddKeyedTransient<IChatService, AzureRestChatService>(nameof(AzureRestChatService));
|
||||
services.AddKeyedTransient<IChatService, AzureChatService>(nameof(AzureChatService));
|
||||
services.AddKeyedTransient<IChatService, AzureRestChatService>(nameof(AzureRestChatService));
|
||||
}
|
||||
|
||||
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
|
||||
{
|
||||
var service = context.ServiceProvider;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user