-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OpenRouterClient; Fix models validation issue
- Loading branch information
Showing
22 changed files
with
198 additions
and
74 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
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
4 changes: 2 additions & 2 deletions
4
...enAI.ChatGpt/AsyncEnumerableExtensions.cs → ...t/Extensions/AsyncEnumerableExtensions.cs
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
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
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
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,29 @@ | ||
using OpenAI.ChatGpt.Models.ChatCompletion; | ||
|
||
namespace OpenAI.ChatGpt; | ||
|
||
/// <summary> | ||
/// OpenRouter.ai client | ||
/// </summary> | ||
/// <remarks> | ||
/// Docs: https://openrouter.ai/docs | ||
/// </remarks> | ||
public class OpenRouterClient : OpenAiClient | ||
{ | ||
private const string DefaultHost = "https://openrouter.ai/api/v1/"; | ||
|
||
public OpenRouterClient(string apiKey, string? host = DefaultHost) | ||
: base(apiKey, host ?? DefaultHost) | ||
{ | ||
#pragma warning disable CS0618 // Type or member is obsolete | ||
ChatCompletionModels.DisableModelNameValidation(); | ||
#pragma warning restore CS0618 // Type or member is obsolete | ||
} | ||
|
||
public OpenRouterClient(HttpClient httpClient) : base(httpClient) | ||
{ | ||
#pragma warning disable CS0618 // Type or member is obsolete | ||
ChatCompletionModels.DisableModelNameValidation(); | ||
#pragma warning restore CS0618 // Type or member is obsolete | ||
} | ||
} |
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
13 changes: 10 additions & 3 deletions
13
tests/OpenAI.ChatGpt.IntegrationTests/ChatGptTranslatorServiceTests.cs
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
13 changes: 6 additions & 7 deletions
13
...enAiClientTests/AzureOpenAiClientTests.cs → ...sts/ClientTests/AzureOpenAiClientTests.cs
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
12 changes: 7 additions & 5 deletions
12
...nAiClientTests/ChatCompletionsApiTests.cs → ...ts/ClientTests/ChatCompletionsApiTests.cs
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
15 changes: 15 additions & 0 deletions
15
tests/OpenAI.ChatGpt.IntegrationTests/ClientTests/ChatCompletionsVisionTests.cs
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,15 @@ | ||
using OpenAI.ChatGpt.IntegrationTests.ClientTests.Fixtures; | ||
|
||
namespace OpenAI.ChatGpt.IntegrationTests.ClientTests; | ||
|
||
public class ChatCompletionsVisionTests : IClassFixture<OpenAiClientFixture> | ||
{ | ||
private readonly ITestOutputHelper _outputHelper; | ||
private readonly IOpenAiClient _client; | ||
|
||
public ChatCompletionsVisionTests(ITestOutputHelper outputHelper, OpenAiClientFixture fixture) | ||
{ | ||
_outputHelper = outputHelper; | ||
_client = fixture.Client; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
tests/OpenAI.ChatGpt.IntegrationTests/ClientTests/Fixtures/AzureOpenAiClientFixture.cs
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,14 @@ | ||
namespace OpenAI.ChatGpt.IntegrationTests.ClientTests.Fixtures; | ||
|
||
public class AzureOpenAiClientFixture | ||
{ | ||
public IOpenAiClient Client { get; } | ||
|
||
public AzureOpenAiClientFixture() | ||
{ | ||
var endpointUrl = Helpers.GetRequiredValueFromConfiguration("AZURE_OPENAI_ENDPOINT_URL"); | ||
var azureKey = Helpers.GetRequiredValueFromConfiguration("AZURE_OPENAI_API_KEY"); | ||
var deploymentName = Helpers.GetRequiredValueFromConfiguration("AZURE_OPENAI_DEPLOYMENT_NAME"); | ||
Client = new AzureOpenAiClient(endpointUrl, deploymentName, azureKey, "2023-12-01-preview"); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
tests/OpenAI.ChatGpt.IntegrationTests/ClientTests/Fixtures/OpenAiClientFixture.cs
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,7 @@ | ||
namespace OpenAI.ChatGpt.IntegrationTests.ClientTests.Fixtures; | ||
|
||
public class OpenAiClientFixture | ||
{ | ||
public IOpenAiClient Client { get; private set; } | ||
= new OpenAiClient(Helpers.GetOpenAiKey()); | ||
} |
7 changes: 7 additions & 0 deletions
7
tests/OpenAI.ChatGpt.IntegrationTests/ClientTests/Fixtures/OpenRouterClientFixture.cs
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,7 @@ | ||
namespace OpenAI.ChatGpt.IntegrationTests.ClientTests.Fixtures; | ||
|
||
public class OpenRouterClientFixture | ||
{ | ||
public IOpenAiClient Client { get; private set; } | ||
= new OpenRouterClient(Helpers.GetOpenRouterKey()); | ||
} |
15 changes: 11 additions & 4 deletions
15
...sts/OpenAiClient_GetStructuredResponse.cs → ...sts/OpenAiClient_GetStructuredResponse.cs
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
28 changes: 28 additions & 0 deletions
28
tests/OpenAI.ChatGpt.IntegrationTests/ClientTests/OpenRouterClientTests.cs
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 @@ | ||
using OpenAI.ChatGpt.IntegrationTests.ClientTests.Fixtures; | ||
|
||
namespace OpenAI.ChatGpt.IntegrationTests.ClientTests; | ||
|
||
public class OpenRouterClientTests | ||
{ | ||
public class ChatCompletionsApiTests : IClassFixture<OpenRouterClientFixture> | ||
{ | ||
private readonly ITestOutputHelper _outputHelper; | ||
private readonly IOpenAiClient _client; | ||
|
||
public ChatCompletionsApiTests(ITestOutputHelper outputHelper, OpenRouterClientFixture fixture) | ||
{ | ||
_outputHelper = outputHelper; | ||
_client = fixture.Client; | ||
} | ||
|
||
[Fact] | ||
public async void Get_response_from_mistral7B_for_one_message() | ||
{ | ||
string model = "mistralai/mistral-7b-instruct"; | ||
var dialog = Dialog.StartAsUser("Who are you?"); | ||
string response = await _client.GetChatCompletions(dialog, 80, model: model); | ||
_outputHelper.WriteLine(response); | ||
response.Should().NotBeNullOrEmpty(); | ||
} | ||
} | ||
} |
Oops, something went wrong.