Skip to content

Commit

Permalink
fix: Small fixes for Serve sample.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Apr 1, 2024
1 parent eb75afd commit 07eccec
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions examples/LangChain.Samples.Serve/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using LangChain.Providers;
using LangChain.Providers.Ollama;
using LangChain.Serve;
using LangChain.Utilities.Classes.Repository;
using LangChain.Serve.Classes.Repository;
using static LangChain.Chains.Chain;
using Message = LangChain.Providers.Message;

Expand All @@ -15,10 +15,10 @@
builder.Services.AddLangChainServe();

// 2. Create a model
var model = new OllamaChatModel(new OllamaProvider(options:new OllamaOptions()
var model = new OllamaChatModel(new OllamaProvider(options: new OllamaOptions
{
Temperature = 0,
Stop = new[] { "User:" },
Stop = ["User:"],
}),"mistral:latest");


Expand Down Expand Up @@ -64,9 +64,9 @@

// get response and send it as AI answer
var response = await chain.Run("text");
return new StoredMessage()
return new StoredMessage
{
Author = MessageAuthor.AI,
Author = MessageAuthor.Ai,
Content = response ?? string.Empty,
};
});
Expand All @@ -79,14 +79,23 @@
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
app.Run();
return;

async Task<ConversationBufferMemory> ConvertToConversationBuffer(List<StoredMessage> list)
{
var conversationBufferMemory = new ConversationBufferMemory();
conversationBufferMemory.Formatter.HumanPrefix = "User";
conversationBufferMemory.Formatter.AiPrefix = "Assistant";
var conversationBufferMemory = new ConversationBufferMemory
{
Formatter =
{
HumanPrefix = "User",
AiPrefix = "Assistant",
}
};
List<Message> converted = list
.Select(x => new Message(x.Content, x.Author == MessageAuthor.User ? MessageRole.Human : MessageRole.Ai)).ToList();
.Select(x => new Message(x.Content, x.Author == MessageAuthor.User ? MessageRole.Human : MessageRole.Ai))
.ToList();

await conversationBufferMemory.ChatHistory.AddMessages(converted);

return conversationBufferMemory;
}

0 comments on commit 07eccec

Please sign in to comment.