Created
September 21, 2024 12:26
-
-
Save wullemsb/f170b3c2471c1e4fe8b14366a321e4cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var uri = new Uri("http://localhost:11434"); //Default Ollama endpoint | |
var ollama = new OllamaApiClient(uri); | |
ollama.SelectedModel = "llama3.1:latest"; | |
string GetWeather(string location, string format) | |
{ | |
//Call the weather API here | |
return $"The weather in {location} is 25 degrees {format}"; | |
} | |
var chat = new Chat(ollama); | |
while (true) | |
{ | |
Console.Write("User>"); | |
var message = Console.ReadLine(); | |
Console.Write("Assistant>"); | |
await foreach (var answerToken in chat.Send(message, tools: [tool]))//We pass our tool when calling the LLM | |
Console.Write(answerToken); | |
//Check the latest message to see if a tool was called | |
foreach (var toolCall in chat.Messages.Last().ToolCalls) | |
{ | |
var arguments = string.Join(",",toolCall.Function.Arguments.Select(kvp => $"{kvp.Key}: {kvp.Value}")); | |
Console.WriteLine($"Tool called:{toolCall.Function.Name} with following arguments: {arguments}"); | |
} | |
Console.WriteLine(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment