Skip to content

Dotnet - System.Text.Json.JsonException when using Uri object #15

@davejitsu

Description

@davejitsu

Code:

var llmEndPoint = "http://localhost:11434";
var llmUri = new Uri(llmEndPoint);

var modelId = "phi3:medium";
var embedderModelId = "nomic-embed-text";

var builder = Kernel.CreateBuilder()
    .AddOpenAIChatCompletion(modelId, llmUri, null)
    .AddOllamaTextEmbeddingGeneration(embedderModelId, llmUri);

builder.Services.AddTransient();
var kernel = builder.Build();

var embeddingGenerator = kernel.GetRequiredService>();
var embeddings = await embeddingGenerator.GenerateEmbeddingAsync("What is the capital of France?");

Error:
System.Text.Json.JsonException: ''p' is invalid after a single JSON value. Expected end of data. Path: $ | LineNumber: 0 | BytePositionInLine: 4.'

Http Response:
StatusCode: 404, ReasonPhrase: 'Not Found', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent

Cause: There is a trailing / when using Uri object
Expected: http://localhost:11434/api/embeddings
Actual: http://localhost:11434//api/embeddings

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions