autogen/dotnet/test/Autogen.Ollama.Tests/OllamaTextEmbeddingServiceTests.cs
Israel de la Cruz 1c3ae92d39
[.Net] feature: Ollama integration (#2693)
* [.Net] feature: Ollama integration with

* [.Net] ollama agent improvements and reorganization

* added ollama fact logic

* [.Net] added ollama embeddings service

* [.Net] Ollama embeddings integration

* cleaned the agent and connector code

* [.Net] cleaned ollama agent tests

* [.Net] standardize api key fact ollama host variable

* [.Net] fixed solution issue

---------

Co-authored-by: Xiaoyun Zhang <bigmiao.zhang@gmail.com>
2024-05-15 16:54:08 +00:00

28 lines
1.2 KiB
C#

// Copyright (c) Microsoft Corporation. All rights reserved.
// OllamaTextEmbeddingServiceTests.cs
using AutoGen.Tests;
using FluentAssertions;
namespace Autogen.Ollama.Tests;
public class OllamaTextEmbeddingServiceTests
{
[ApiKeyFact("OLLAMA_HOST", "OLLAMA_EMBEDDING_MODEL_NAME")]
public async Task GenerateAsync_ReturnsEmbeddings_WhenApiResponseIsSuccessful()
{
string host = Environment.GetEnvironmentVariable("OLLAMA_HOST")
?? throw new InvalidOperationException("OLLAMA_HOST is not set.");
string embeddingModelName = Environment.GetEnvironmentVariable("OLLAMA_EMBEDDING_MODEL_NAME")
?? throw new InvalidOperationException("OLLAMA_EMBEDDING_MODEL_NAME is not set.");
var httpClient = new HttpClient
{
BaseAddress = new Uri(host)
};
var request = new TextEmbeddingsRequest { Model = embeddingModelName, Prompt = "Llamas are members of the camelid family", };
var service = new OllamaTextEmbeddingService(httpClient);
TextEmbeddingsResponse response = await service.GenerateAsync(request);
response.Should().NotBeNull();
}
}