Skip to content

Commit cfdc72c

Browse files
authored
Merge pull request #7 from BLaZeKiLL/wip/ollama-chat-fix
Ollama Chat fix
2 parents db4839e + 8c65477 commit cfdc72c

File tree

3 files changed

+13
-34
lines changed

3 files changed

+13
-34
lines changed

Codeblaze.SemanticKernel.Connectors.Ollama/ChatCompletion/OllamaChatCompletionService.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ public class OllamaChatCompletionService(
1818
public async Task<IReadOnlyList<ChatMessageContent>> GetChatMessageContentsAsync(ChatHistory chatHistory, PromptExecutionSettings? executionSettings = null,
1919
Kernel? kernel = null, CancellationToken cancellationToken = new())
2020
{
21-
var system = string.Join("\n", chatHistory.Where(x => x.Role == AuthorRole.System).Select(x => x.Content));
22-
var user = chatHistory.Last(x => x.Role == AuthorRole.User);
21+
var chat = string.Join("\n", chatHistory.Select(x => x.Content));
2322

2423
var data = new
2524
{
2625
model = Attributes["model_id"] as string,
27-
prompt = user.Content,
28-
system,
26+
prompt = chat,
2927
stream = false,
3028
options = executionSettings?.ExtensionData,
3129
};
@@ -43,14 +41,12 @@ public async IAsyncEnumerable<StreamingChatMessageContent> GetStreamingChatMessa
4341
PromptExecutionSettings? executionSettings = null, Kernel? kernel = null,
4442
[EnumeratorCancellation] CancellationToken cancellationToken = new())
4543
{
46-
var system = string.Join("\n", chatHistory.Where(x => x.Role == AuthorRole.System).Select(x => x.Content));
47-
var user = chatHistory.Last(x => x.Role == AuthorRole.User);
44+
var chat = string.Join("\n", chatHistory.Select(x => x.Content));
4845

4946
var data = new
5047
{
5148
model = Attributes["model_id"] as string,
52-
prompt = user.Content,
53-
system,
49+
prompt = chat,
5450
stream = true,
5551
options = executionSettings?.ExtensionData,
5652
};

Codeblaze.SemanticKernel.Console/Program.cs

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -49,51 +49,34 @@ void Run()
4949

5050
async Task Prompt()
5151
{
52-
NeoKernelService kernel = null;
52+
KernelService kernel = null;
5353

5454
AnsiConsole.Status().Start("Initializing...", ctx =>
5555
{
5656
ctx.Spinner(Spinner.Known.Star);
5757
ctx.SpinnerStyle(Style.Parse("green"));
5858

59-
kernel = new NeoKernelService(config);
59+
kernel = new KernelService(config);
6060

6161
ctx.Status("Initialized");
6262
});
6363

6464
var prompt = AnsiConsole.Prompt(new TextPrompt<string>("What are you looking to do today?\n").PromptStyle("teal"));
6565

66-
Neo4jResult result = null;
66+
string result = null;
6767

6868
await AnsiConsole.Status().StartAsync("Processing...", async ctx =>
6969
{
7070
ctx.Spinner(Spinner.Known.Star);
7171
ctx.SpinnerStyle(Style.Parse("green"));
7272

7373
ctx.Status($"Processing input to generate cypher");
74-
result = await kernel.Run(prompt);
74+
result = await kernel.BasicPrompt(prompt);
7575
});
7676

77-
if (result.Success)
78-
{
79-
AnsiConsole.WriteLine("");
80-
AnsiConsole.Write(new Rule("[cyan]Cypher[/]") { Justification = Justify.Center });
81-
AnsiConsole.WriteLine(result.Cypher);
82-
AnsiConsole.Write(new Panel(new JsonText(JsonSerializer.Serialize(result.Result)))
83-
.Header("Cypher Result")
84-
.Expand()
85-
.RoundedBorder()
86-
.BorderColor(Color.Green));
87-
AnsiConsole.WriteLine("");
88-
}
89-
else
90-
{
91-
AnsiConsole.WriteLine("");
92-
AnsiConsole.Write(new Rule("[red]Cypher[/]") { Justification = Justify.Center });
93-
AnsiConsole.WriteLine(result.Cypher);
94-
AnsiConsole.Write(new Rule("[red]Cypher Execution Error[/]") { Justification = Justify.Center });
95-
AnsiConsole.WriteLine("");
96-
}
77+
AnsiConsole.Write(new Rule("[cyan][/]") { Justification = Justify.Center });
78+
AnsiConsole.WriteLine($"Result: {result}");
79+
AnsiConsole.Write(new Rule("[cyan][/]") { Justification = Justify.Center });
9780
}
9881

9982
#pragma warning disable SKEXP0003

Codeblaze.SemanticKernel.Console/Services/KernelService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public KernelService(IConfiguration config)
1616

1717
builder.Services.AddTransient<HttpClient>();
1818

19-
builder
20-
.AddOllamaTextGeneration(config["Ollama:Model"], config["Ollama:BaseUrlGeneration"]);
19+
builder.AddOllamaChatCompletion(config["Ollama:Model"], config["Ollama:BaseUrlGeneration"]);
20+
builder.AddOllamaTextGeneration(config["Ollama:Model"], config["Ollama:BaseUrlGeneration"]);
2121

2222
_Kernel = builder.Build();
2323
}

0 commit comments

Comments
 (0)