feat: 提交
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
using Azure;
|
||||
using Azure.AI.OpenAI;
|
||||
using OpenAI.Chat;
|
||||
using Volo.Abp.Domain.Services;
|
||||
|
||||
namespace Yi.Framework.AiHub.Domain.Managers;
|
||||
|
||||
public class OpenAiManager : DomainService
|
||||
{
|
||||
public static async Task TestAsync()
|
||||
{
|
||||
var endpoint = new Uri("https://japan-ccnetcore-resource.cognitiveservices.azure.com/");
|
||||
// var deploymentName = "gpt-4.1-mini";
|
||||
var deploymentName = "o4-mini";
|
||||
var apiKey = "FaccnRh7Zvz25OCGH07kHPe2z1aCXMliLdr3esgWHgXQ2aivwFgDJQQJ99BFACi0881XJ3w3AAAAACOGAJ2G";
|
||||
|
||||
AzureOpenAIClient azureClient = new(
|
||||
endpoint,
|
||||
new AzureKeyCredential(apiKey));
|
||||
ChatClient chatClient = azureClient.GetChatClient(deploymentName);
|
||||
|
||||
List<ChatMessage> messages = new List<ChatMessage>()
|
||||
{
|
||||
new UserChatMessage("使用c#写一个贪吃蛇代码"),
|
||||
};
|
||||
|
||||
var response = chatClient.CompleteChatStreamingAsync(messages);
|
||||
|
||||
await foreach (StreamingChatCompletionUpdate update in response)
|
||||
{
|
||||
foreach (ChatMessageContentPart updatePart in update.ContentUpdate)
|
||||
{
|
||||
System.Console.Write(updatePart.Text);
|
||||
}
|
||||
}
|
||||
|
||||
System.Console.WriteLine("结束");
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="..\..\..\common.props" />
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Azure.AI.OpenAI" Version="2.2.0-beta.4" />
|
||||
<PackageReference Include="Volo.Abp.Ddd.Domain" Version="$(AbpVersion)" />
|
||||
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\framework\Yi.Framework.Mapster\Yi.Framework.Mapster.csproj" />
|
||||
<ProjectReference Include="..\..\..\framework\Yi.Framework.SemanticKernel\Yi.Framework.SemanticKernel.csproj" />
|
||||
<ProjectReference Include="..\..\..\framework\Yi.Framework.SqlSugarCore.Abstractions\Yi.Framework.SqlSugarCore.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\Yi.Framework.AiHub.Domain.Shared\Yi.Framework.AiHub.Domain.Shared.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.SemanticKernel;
|
||||
using Volo.Abp.Caching;
|
||||
using Volo.Abp.Domain;
|
||||
using Yi.Framework.AiHub.Domain.Shared;
|
||||
using Yi.Framework.Mapster;
|
||||
using Yi.Framework.SemanticKernel;
|
||||
|
||||
namespace Yi.Framework.AiHub.Domain
|
||||
{
|
||||
[DependsOn(
|
||||
typeof(YiFrameworkAiHubDomainSharedModule),
|
||||
typeof(YiFrameworkMapsterModule),
|
||||
typeof(AbpDddDomainModule),
|
||||
typeof(YiFrameworkSemanticKernelModule)
|
||||
typeof(AbpDddDomainModule)
|
||||
)]
|
||||
public class YiFrameworkAiHubDomainModule : AbpModule
|
||||
{
|
||||
@@ -21,5 +18,10 @@ namespace Yi.Framework.AiHub.Domain
|
||||
var configuration = context.Services.GetConfiguration();
|
||||
var services = context.Services;
|
||||
}
|
||||
|
||||
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
|
||||
{
|
||||
await Yi.Framework.AiHub.Domain.Managers.OpenAiManager.Test2Async();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user