-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[.Net] add ollama-sample and adds more tests (#2776)
* add ollama-sample and adds more tests * Update AutoGen.Ollama.Sample.csproj
- Loading branch information
1 parent
8d55334
commit 702c010
Showing
8 changed files
with
163 additions
and
30 deletions.
There are no files selected for viewing
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
24 changes: 24 additions & 0 deletions
24
dotnet/sample/AutoGen.Ollama.Sample/AutoGen.Ollama.Sample.csproj
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>$(TestTargetFramework)</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<GenerateDocumentationFile>True</GenerateDocumentationFile> | ||
<NoWarn>$(NoWarn);CS8981;CS8600;CS8602;CS8604;CS8618;CS0219;SKEXP0054;SKEXP0050;SKEXP0110</NoWarn> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\AutoGen.DotnetInteractive\AutoGen.DotnetInteractive.csproj" /> | ||
<ProjectReference Include="..\..\src\AutoGen.Ollama\AutoGen.Ollama.csproj" /> | ||
<ProjectReference Include="..\..\src\AutoGen.SourceGenerator\AutoGen.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
<ProjectReference Include="..\..\src\AutoGen\AutoGen.csproj" /> | ||
<PackageReference Include="FluentAssertions" Version="$(FluentAssertionVersion)" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="images\*.png"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Chat_With_LLaMA.cs | ||
|
||
using AutoGen.Core; | ||
using AutoGen.Ollama.Extension; | ||
|
||
namespace AutoGen.Ollama.Sample; | ||
|
||
public class Chat_With_LLaMA | ||
{ | ||
public static async Task RunAsync() | ||
{ | ||
using var httpClient = new HttpClient() | ||
{ | ||
BaseAddress = new Uri("https://2xbvtxd1-11434.usw2.devtunnels.ms") | ||
}; | ||
|
||
var ollamaAgent = new OllamaAgent( | ||
httpClient: httpClient, | ||
name: "ollama", | ||
modelName: "llama3:latest", | ||
systemMessage: "You are a helpful AI assistant") | ||
.RegisterMessageConnector() | ||
.RegisterPrintMessage(); | ||
|
||
var reply = await ollamaAgent.SendAsync("Can you write a piece of C# code to calculate 100th of fibonacci?"); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Chat_With_LLaVA.cs | ||
|
||
using AutoGen.Core; | ||
using AutoGen.Ollama.Extension; | ||
|
||
namespace AutoGen.Ollama.Sample; | ||
|
||
public class Chat_With_LLaVA | ||
{ | ||
public static async Task RunAsync() | ||
{ | ||
using var httpClient = new HttpClient() | ||
{ | ||
BaseAddress = new Uri("https://2xbvtxd1-11434.usw2.devtunnels.ms") | ||
}; | ||
|
||
var ollamaAgent = new OllamaAgent( | ||
httpClient: httpClient, | ||
name: "ollama", | ||
modelName: "llava:latest", | ||
systemMessage: "You are a helpful AI assistant") | ||
.RegisterMessageConnector() | ||
.RegisterPrintMessage(); | ||
|
||
var image = Path.Combine("images", "background.png"); | ||
var binaryData = BinaryData.FromBytes(File.ReadAllBytes(image), "image/png"); | ||
var imageMessage = new ImageMessage(Role.User, binaryData); | ||
var textMessage = new TextMessage(Role.User, "what's in this image?"); | ||
var reply = await ollamaAgent.SendAsync(chatHistory: [textMessage, imageMessage]); | ||
|
||
// You can also use MultiModalMessage to put text and image together in one message | ||
// In this case, all the messages in the multi-modal message will be put into single piece of message | ||
// where the text is the concatenation of all the text messages seperated by \n | ||
// and the images are all the images in the multi-modal message | ||
var multiModalMessage = new MultiModalMessage(Role.User, [textMessage, imageMessage]); | ||
|
||
reply = await ollamaAgent.SendAsync(chatHistory: [multiModalMessage]); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Program.cs | ||
|
||
using AutoGen.Ollama.Sample; | ||
|
||
await Chat_With_LLaVA.RunAsync(); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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