|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Text;
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace OllamaStudy.UseExtensionsAI
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// OpenAI的API 测试
|
|
|
/// Ollama兼容OpenAI接口,可以直接使用OpenAI的SDK调用
|
|
|
/// </summary>
|
|
|
public class OpenAIAPITest
|
|
|
{
|
|
|
private ITestOutputHelper _output;
|
|
|
private IOptionsMonitor<OllamaServerOption> _ollamaOptionsMonitor;
|
|
|
private OpenAIClient _defaultOpenAIClient;
|
|
|
private ChatClient _chatClient;
|
|
|
|
|
|
public OpenAIAPITest(ITestOutputHelper outputHelper, OpenAIClient defaultOpenAIClient, IOptionsMonitor<OllamaServerOption> ollamaOptionsMonitor)
|
|
|
{
|
|
|
_output = outputHelper;
|
|
|
_defaultOpenAIClient = defaultOpenAIClient;
|
|
|
_ollamaOptionsMonitor = ollamaOptionsMonitor;
|
|
|
_chatClient = _defaultOpenAIClient.GetChatClient(_ollamaOptionsMonitor.CurrentValue.Model);
|
|
|
}
|
|
|
|
|
|
#region 各种业务Client
|
|
|
/// <summary>
|
|
|
/// 从OpenAIClient获取各种业务 Client
|
|
|
/// </summary>
|
|
|
[Fact]
|
|
|
public void GetClients_Test()
|
|
|
{
|
|
|
#pragma warning disable OPENAI001
|
|
|
Assert.NotNull(_defaultOpenAIClient);
|
|
|
|
|
|
//音频客户端
|
|
|
var audioClient = _defaultOpenAIClient.GetAudioClient(_ollamaOptionsMonitor.CurrentValue.Model);
|
|
|
Assert.NotNull(audioClient);
|
|
|
|
|
|
//聊天客户端
|
|
|
var chatClient = _defaultOpenAIClient.GetChatClient(_ollamaOptionsMonitor.CurrentValue.Model);
|
|
|
Assert.NotNull(chatClient);
|
|
|
|
|
|
//嵌入客户端
|
|
|
var embeddingClient = _defaultOpenAIClient.GetEmbeddingClient(_ollamaOptionsMonitor.CurrentValue.Model);
|
|
|
Assert.NotNull(embeddingClient);
|
|
|
|
|
|
//图像客户端
|
|
|
var imageClient = _defaultOpenAIClient.GetImageClient(_ollamaOptionsMonitor.CurrentValue.Model);
|
|
|
Assert.NotNull(imageClient);
|
|
|
|
|
|
//微调客户端
|
|
|
var moderationClient = _defaultOpenAIClient.GetModerationClient(_ollamaOptionsMonitor.CurrentValue.Model);
|
|
|
Assert.NotNull(moderationClient);
|
|
|
|
|
|
//文件客户端
|
|
|
var openAIFileClient = _defaultOpenAIClient.GetOpenAIFileClient();
|
|
|
Assert.NotNull(openAIFileClient);
|
|
|
|
|
|
//模型客户端
|
|
|
var modelClient = _defaultOpenAIClient.GetOpenAIModelClient();
|
|
|
Assert.NotNull(modelClient);
|
|
|
|
|
|
//助手客户端(仅评估)
|
|
|
var assistantClient = _defaultOpenAIClient.GetAssistantClient();
|
|
|
Assert.NotNull(assistantClient);
|
|
|
|
|
|
//批量客户端(仅评估)
|
|
|
var batchClient = _defaultOpenAIClient.GetBatchClient();
|
|
|
Assert.NotNull(batchClient);
|
|
|
|
|
|
//评估客户端(仅评估)
|
|
|
var evaluationClient = _defaultOpenAIClient.GetEvaluationClient();
|
|
|
Assert.NotNull(evaluationClient);
|
|
|
|
|
|
//微调客户端(仅评估)
|
|
|
var FineTuningClient = _defaultOpenAIClient.GetFineTuningClient();
|
|
|
Assert.NotNull(FineTuningClient);
|
|
|
|
|
|
//响应客户端(仅评估)
|
|
|
var openAIResponseClient = _defaultOpenAIClient.GetOpenAIResponseClient(_ollamaOptionsMonitor.CurrentValue.Model);
|
|
|
Assert.NotNull(openAIResponseClient);
|
|
|
|
|
|
//实时客户端(仅评估)
|
|
|
#pragma warning disable OPENAI002
|
|
|
var realtimeClient = _defaultOpenAIClient.GetRealtimeClient();
|
|
|
Assert.NotNull(realtimeClient);
|
|
|
#pragma warning restore OPENAI002
|
|
|
|
|
|
//向量存储客户端(仅评估)
|
|
|
var vectorStoreClient = _defaultOpenAIClient.GetVectorStoreClient();
|
|
|
Assert.NotNull(vectorStoreClient);
|
|
|
|
|
|
#pragma warning restore OPENAI001
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 音频
|
|
|
#endregion
|
|
|
|
|
|
#region 聊天
|
|
|
#endregion
|
|
|
|
|
|
#region 自动补全
|
|
|
#endregion
|
|
|
|
|
|
#region 嵌入
|
|
|
#endregion
|
|
|
|
|
|
#region 微调
|
|
|
#endregion
|
|
|
|
|
|
#region 文件
|
|
|
#endregion
|
|
|
|
|
|
#region 图像
|
|
|
#endregion
|
|
|
|
|
|
#region 模型
|
|
|
|
|
|
/// <summary>
|
|
|
/// 列出模型 测试
|
|
|
/// </summary>
|
|
|
[Fact]
|
|
|
public void List_Models_Test()
|
|
|
{
|
|
|
var modelClient = _defaultOpenAIClient.GetOpenAIModelClient();
|
|
|
|
|
|
OpenAI.Models.OpenAIModelCollection openAIModelCollection = modelClient.GetModels().Value;
|
|
|
|
|
|
_output.WriteLine($"Ollama服务中,共有{openAIModelCollection.Count()}个模型,包括[{string.Join(",", openAIModelCollection)}]");
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 审查
|
|
|
#endregion
|
|
|
|
|
|
#region 助手测试版
|
|
|
#endregion
|
|
|
|
|
|
#region 线程数
|
|
|
#endregion
|
|
|
|
|
|
#region 留言
|
|
|
#endregion
|
|
|
|
|
|
#region 运行
|
|
|
#endregion
|
|
|
|
|
|
#region 已弃用-音频
|
|
|
#endregion
|
|
|
}
|
|
|
}
|