You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Connect_To_Ollama.cs 1.3 kB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. // Connect_To_Ollama.cs
  3. #region using_statement
  4. using System.ClientModel;
  5. using AutoGen.Core;
  6. using AutoGen.OpenAI.Extension;
  7. using OpenAI;
  8. #endregion using_statement
  9. namespace AutoGen.OpenAI.Sample;
  10. public class Connect_To_Ollama
  11. {
  12. public static async Task RunAsync()
  13. {
  14. #region create_agent
  15. // api-key is not required for local server
  16. // so you can use any string here
  17. var openAIClient = new OpenAIClient(new ApiKeyCredential("api-key"), new OpenAIClientOptions
  18. {
  19. Endpoint = new Uri("http://localhost:11434/v1/"), // remember to add /v1/ at the end to connect to Ollama openai server
  20. });
  21. var model = "llama3";
  22. var agent = new OpenAIChatAgent(
  23. chatClient: openAIClient.GetChatClient(model),
  24. name: "assistant",
  25. systemMessage: "You are a helpful assistant designed to output JSON.",
  26. seed: 0)
  27. .RegisterMessageConnector()
  28. .RegisterPrintMessage();
  29. #endregion create_agent
  30. #region send_message
  31. await agent.SendAsync("Can you write a piece of C# code to calculate 100th of fibonacci?");
  32. #endregion send_message
  33. }
  34. }