Skip to content

Commit

Permalink
fix: Fixed issue with Serve/OpenAI
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Dec 10, 2024
1 parent 7151734 commit 12de181
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/Packaging.props
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
</PropertyGroup>

<PropertyGroup Label="Trimmable" Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">
<IsAotCompatible>true</IsAotCompatible>
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">true</IsAotCompatible>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<IsTrimmable>true</IsTrimmable>
<SuppressTrimAnalysisWarnings>false</SuppressTrimAnalysisWarnings>
Expand Down
86 changes: 43 additions & 43 deletions src/Serve/OpenAI/ServeController.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
using System.Text.Json.Serialization;
using OpenAI;

namespace LangChain.Serve.OpenAI;

public class ServeController(
ServeOptions options)
{
public ModelsList GetModel()
{
return new ModelsList
{
Models = options.ListModels().Select(static x => new Model12
{
Object = ModelObject.Model,
Created = DateTimeOffset.UtcNow,
Id = x,
OwnedBy = "OpenAI",
}).ToList()
};
}

public ModelsList ListModels()
{
return new ModelsList
{
Models = options.ListModels().Select(static x => new Model12
{
Object = ModelObject.Model,
Created = DateTimeOffset.UtcNow,
Id = x,
OwnedBy = "OpenAI",
}).ToList()
};
}
}

public sealed class ModelsList
{
[JsonInclude]
[JsonPropertyName("data")]
public IReadOnlyCollection<Model12> Models { get; set; } = [];
}
// using System.Text.Json.Serialization;
// using OpenAI;
//
// namespace LangChain.Serve.OpenAI;
//
// public class ServeController(
// ServeOptions options)
// {
// public ModelsList GetModel()
// {
// return new ModelsList
// {
// Models = options.ListModels().Select(static x => new Model12
// {
// Object = ModelObject.Model,
// Created = DateTimeOffset.UtcNow,
// Id = x,
// OwnedBy = "OpenAI",
// }).ToList()
// };
// }
//
// public ModelsList ListModels()
// {
// return new ModelsList
// {
// Models = options.ListModels().Select(static x => new Model12
// {
// Object = ModelObject.Model,
// Created = DateTimeOffset.UtcNow,
// Id = x,
// OwnedBy = "OpenAI",
// }).ToList()
// };
// }
// }
//
// public sealed class ModelsList
// {
// [JsonInclude]
// [JsonPropertyName("data")]
// public IReadOnlyCollection<Model15> Models { get; set; } = [];
// }
4 changes: 2 additions & 2 deletions src/Serve/OpenAI/ServeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public static WebApplication UseLangChainServeOpenAi(this WebApplication app, Ac
options(serveMiddlewareOptions);
// var repository = app.Services.GetRequiredService<IConversationRepository>();
// var conversationNameProvider = app.Services.GetRequiredService<IConversationNameProvider>();
var controller = new ServeController(serveMiddlewareOptions);
//var controller = new ServeController(serveMiddlewareOptions);

app.MapGet("/v1/models", () => Results.Ok(controller.ListModels()));
//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() ?? string.Empty);
Expand Down

0 comments on commit 12de181

Please sign in to comment.