Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ let builder =
// TODO: request your API key in your 🤗 hugging face private settings
let API_KEY = "TODO_REPLACE_ME"
let MODEL_ID = "microsoft/Phi-3-mini-4k-instruct" // pick the model you prefer!
let API_URL = $"https://api-inference.huggingface.co/"
let API_URL = $"https://router.huggingface.co/"

let b = Kernel.CreateBuilder().AddHuggingFaceChatCompletion(
MODEL_ID,
Expand Down
2 changes: 1 addition & 1 deletion dotnet/samples/Demos/TelemetryWithAppInsights/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ private static Kernel GetKernel(ILoggerFactory loggerFactory)
{
builder.AddHuggingFaceChatCompletion(
model: TestConfiguration.HuggingFace.ModelId,
endpoint: new Uri("https://api-inference.huggingface.co"),
endpoint: new Uri("https://router.huggingface.co"),
apiKey: TestConfiguration.HuggingFace.ApiKey,
serviceId: HuggingFaceServiceKey);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public async Task DefaultAddressShouldBeUsedAsync()
await sut.GetChatMessageContentAsync(chatHistory);

//Assert
Assert.StartsWith("https://api-inference.huggingface.co/", this._messageHandlerStub.RequestUri?.AbsoluteUri, StringComparison.OrdinalIgnoreCase);
Assert.StartsWith("https://router.huggingface.co/v1/chat/completions", this._messageHandlerStub.RequestUri?.AbsoluteUri, StringComparison.OrdinalIgnoreCase);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public async Task ModelUrlShouldBeBuiltSuccessfullyAsync()
await sut.GenerateEmbeddingsAsync([]);

//Assert
Assert.Equal("https://fake-random-test-host/fake-path/pipeline/feature-extraction/fake-model", this._messageHandlerStub.RequestUri?.AbsoluteUri);
Assert.Equal("https://fake-random-test-host/fake-path/models/fake-model/pipeline/feature-extraction", this._messageHandlerStub.RequestUri?.AbsoluteUri);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public async Task ModelUrlShouldBeBuiltSuccessfullyAsync()
await sut.GenerateAsync([]);

//Assert
Assert.Equal("https://fake-random-test-host/fake-path/pipeline/feature-extraction/fake-model", this._messageHandlerStub.RequestUri?.AbsoluteUri);
Assert.Equal("https://fake-random-test-host/fake-path/models/fake-model/pipeline/feature-extraction", this._messageHandlerStub.RequestUri?.AbsoluteUri);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public async Task DefaultAddressShouldBeUsedAsync()
await sut.GetTextContentsAsync(this._imageContentInput);

//Assert
Assert.StartsWith("https://api-inference.huggingface.co/models", this._messageHandlerStub.RequestUri?.AbsoluteUri, StringComparison.OrdinalIgnoreCase);
Assert.StartsWith("https://router.huggingface.co/hf-inference/models", this._messageHandlerStub.RequestUri?.AbsoluteUri, StringComparison.OrdinalIgnoreCase);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public async Task DefaultAddressShouldBeUsedAsync()
await sut.GetTextContentsAsync("fake-text");

//Assert
Assert.StartsWith("https://api-inference.huggingface.co/models", this._messageHandlerStub.RequestUri?.AbsoluteUri, StringComparison.OrdinalIgnoreCase);
Assert.StartsWith("https://router.huggingface.co/hf-inference/models", this._messageHandlerStub.RequestUri?.AbsoluteUri, StringComparison.OrdinalIgnoreCase);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ internal HuggingFaceClient(
string? modelId = null,
Uri? endpoint = null,
string? apiKey = null,
ILogger? logger = null)
ILogger? logger = null,
Uri? defaultEndpoint = null)
{
Verify.NotNull(httpClient);

Expand All @@ -44,7 +45,7 @@ internal HuggingFaceClient(
throw new InvalidOperationException("A valid model id or endpoint must be provided.");
}

endpoint ??= new Uri("https://api-inference.huggingface.co");
endpoint ??= defaultEndpoint ?? new Uri("https://router.huggingface.co/hf-inference");
this.Separator = endpoint.AbsolutePath.EndsWith("/", StringComparison.InvariantCulture) ? string.Empty : "/";
this.Endpoint = endpoint;
this.ModelId = modelId;
Expand Down Expand Up @@ -300,7 +301,7 @@ public async Task<IList<ReadOnlyMemory<float>>> GenerateEmbeddingsAsync(
}

private Uri GetEmbeddingGenerationEndpoint(string? modelId)
=> string.IsNullOrWhiteSpace(modelId) ? this.Endpoint : new($"{this.Endpoint}{this.Separator}pipeline/feature-extraction/{modelId}");
=> string.IsNullOrWhiteSpace(modelId) ? this.Endpoint : new($"{this.Endpoint}{this.Separator}models/{modelId}/pipeline/feature-extraction");

#endregion

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ internal HuggingFaceMessageApiClient(
modelId,
endpoint,
apiKey,
logger);
logger,
new Uri("https://router.huggingface.co"));
}

internal async IAsyncEnumerable<StreamingChatMessageContent> StreamCompleteChatMessageAsync(
Expand Down
2 changes: 1 addition & 1 deletion dotnet/src/IntegrationTests/testsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"ChatCompletionModelId": "tgi",
"ApiKey": "",
"TextGenerationEndpoint": "http://localhost:8080/",
"EmbeddingEndpoint": "https://api-inference.huggingface.co/",
"EmbeddingEndpoint": "https://router.huggingface.co/hf-inference/",
"ChatCompletionEndpoint": "http://localhost:8080/"
},
"GoogleAI": {
Expand Down
Loading