-
Notifications
You must be signed in to change notification settings - Fork 4k
.Net: Add Ollama ChatCompletion with Vision Sample #11113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rogerbarreto
merged 6 commits into
microsoft:main
from
rogerbarreto:features/ollama-chatcompletionvision-sample
Mar 24, 2025
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
7b41735
Added Vision sample with default BaseAddress definition if not provid…
rogerbarreto 5304bb8
Add descriptions and updates to sample
rogerbarreto 3af13ba
Add UT to ensure expected behavior
rogerbarreto e1d64e0
Revert default uri
rogerbarreto 3da76fb
remove using
rogerbarreto cf9ed75
Merge branch 'main' into features/ollama-chatcompletionvision-sample
rogerbarreto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
dotnet/samples/Concepts/ChatCompletion/Ollama_ChatCompletionWithVision.cs
This file contains hidden or 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,43 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using Microsoft.SemanticKernel; | ||
using Microsoft.SemanticKernel.ChatCompletion; | ||
using Resources; | ||
|
||
namespace ChatCompletion; | ||
|
||
/// <summary> | ||
/// This sample shows how to use llama3.2-vision model with different content types (text and image). | ||
/// </summary> | ||
public class Ollama_ChatCompletionWithVision(ITestOutputHelper output) : BaseTest(output) | ||
{ | ||
/// <summary> | ||
/// This sample uses a local image file and sends it to the model along | ||
/// with a text message the get the description of the image. | ||
/// </summary> | ||
[Fact] | ||
public async Task GetLocalImageDescription() | ||
{ | ||
Console.WriteLine($"======== Ollama - {nameof(GetLocalImageDescription)} ========"); | ||
|
||
var imageBytes = await EmbeddedResource.ReadAllAsync("sample_image.jpg"); | ||
|
||
var kernel = Kernel.CreateBuilder() | ||
.AddOllamaChatCompletion("llama3.2-vision") | ||
.Build(); | ||
|
||
var chatCompletionService = kernel.GetRequiredService<IChatCompletionService>(); | ||
|
||
var chatHistory = new ChatHistory("You are a friendly assistant."); | ||
|
||
chatHistory.AddUserMessage( | ||
[ | ||
new TextContent("What’s in this image?"), | ||
new ImageContent(imageBytes, "image/jpg") | ||
]); | ||
|
||
var reply = await chatCompletionService.GetChatMessageContentAsync(chatHistory); | ||
|
||
Console.WriteLine(reply.Content); | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.