diff --git a/src/Serve/OpenAI/ServeController.cs b/src/Serve/OpenAI/ServeController.cs index b5379dcd..6b955450 100644 --- a/src/Serve/OpenAI/ServeController.cs +++ b/src/Serve/OpenAI/ServeController.cs @@ -10,7 +10,7 @@ public ModelsList GetModel() { return new ModelsList { - Models = options.ListModels().Select(static x => new Model + Models = options.ListModels().Select(static x => new Model12 { Object = ModelObject.Model, Created = 0, @@ -24,7 +24,7 @@ public ModelsList ListModels() { return new ModelsList { - Models = options.ListModels().Select(static x => new Model + Models = options.ListModels().Select(static x => new Model12 { Object = ModelObject.Model, Created = 0, @@ -39,5 +39,5 @@ public sealed class ModelsList { [JsonInclude] [JsonPropertyName("data")] - public IReadOnlyCollection Models { get; set; } = []; + public IReadOnlyCollection Models { get; set; } = []; } \ No newline at end of file diff --git a/src/Serve/OpenAI/ServeExtensions.cs b/src/Serve/OpenAI/ServeExtensions.cs index 16a311f7..822da2b1 100644 --- a/src/Serve/OpenAI/ServeExtensions.cs +++ b/src/Serve/OpenAI/ServeExtensions.cs @@ -31,13 +31,13 @@ public static WebApplication UseLangChainServeOpenAi(this WebApplication app, Ac app.MapGet("/v1/models", () => Results.Ok(controller.ListModels())); app.MapPost("/v1/chat/completions", async (CreateChatCompletionRequest request) => { - var llm = serveMiddlewareOptions.GetModel(request.Model.Value1 ?? request.Model.Value2.ToValueString()); + var llm = serveMiddlewareOptions.GetModel(request.Model.Value1 ?? request.Model.Value2?.ToValueString() ?? string.Empty); var response = await llm.GenerateAsync(new ChatRequest { Messages = request.Messages.Select(x => new Message { - Content = x.User?.Content.Value1 ?? x.Assistant?.Content ?? x.System?.Content ?? string.Empty, + Content = x.User?.Content.Value1 ?? x.Assistant?.Content?.Value1 ?? x.System?.Content.Value1 ?? string.Empty, Role = x.Object switch { ChatCompletionRequestAssistantMessage => MessageRole.Ai, @@ -52,11 +52,11 @@ public static WebApplication UseLangChainServeOpenAi(this WebApplication app, Ac { Id = Guid.NewGuid().ToString(), Created = 0, - Model = request.Model.Value1 ?? request.Model.Value2.ToValueString(), + Model = request.Model.Value1 ?? request.Model.Value2?.ToValueString() ?? string.Empty, Object = CreateChatCompletionResponseObject.ChatCompletion, Choices = [ - new CreateChatCompletionResponseChoices + new CreateChatCompletionResponseChoice { Message = new ChatCompletionResponseMessage { @@ -64,11 +64,12 @@ public static WebApplication UseLangChainServeOpenAi(this WebApplication app, Ac Role = ChatCompletionResponseMessageRole.Assistant, }, Index = 0, - Logprobs = new CreateChatCompletionResponseChoicesLogprobs + Logprobs = new CreateChatCompletionResponseChoiceLogprobs { Content = [], + Refusal = [], }, - FinishReason = CreateChatCompletionResponseChoicesFinishReason.Stop, + FinishReason = CreateChatCompletionResponseChoiceFinishReason.Stop, } ], });