Skip to content

Commit

Permalink
fix: Fixed Serve.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Aug 16, 2024
1 parent 14fb067 commit 837a043
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/Serve/OpenAI/ServeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -39,5 +39,5 @@ public sealed class ModelsList
{
[JsonInclude]
[JsonPropertyName("data")]
public IReadOnlyCollection<Model> Models { get; set; } = [];
public IReadOnlyCollection<Model12> Models { get; set; } = [];
}
13 changes: 7 additions & 6 deletions src/Serve/OpenAI/ServeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -52,23 +52,24 @@ 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
{
Content = response.Messages.Last().Content,
Role = ChatCompletionResponseMessageRole.Assistant,
},
Index = 0,
Logprobs = new CreateChatCompletionResponseChoicesLogprobs
Logprobs = new CreateChatCompletionResponseChoiceLogprobs
{
Content = [],
Refusal = [],
},
FinishReason = CreateChatCompletionResponseChoicesFinishReason.Stop,
FinishReason = CreateChatCompletionResponseChoiceFinishReason.Stop,
}
],
});
Expand Down

0 comments on commit 837a043

Please sign in to comment.