Skip to content

Commit

Permalink
feat: Added xAi custom provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Nov 15, 2024
1 parent a79b914 commit 4ce248f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ using var api = CustomProviders.GitHubModels("GITHUB_TOKEN");
using var api = CustomProviders.Azure("API_KEY", "ENDPOINT");
using var api = CustomProviders.DeepInfra("API_KEY");
using var api = CustomProviders.Groq("API_KEY");
using var api = CustomProviders.XAi("API_KEY");
using var api = CustomProviders.DeepSeek("API_KEY");
using var api = CustomProviders.Fireworks("API_KEY");
using var api = CustomProviders.OpenRouter("API_KEY");
Expand Down
14 changes: 14 additions & 0 deletions src/libs/OpenAI/CustomProviders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public static class CustomProviders
/// </summary>
public const string GroqBaseUrl = "https://api.groq.com/openai/v1/";

/// <summary>
///
/// </summary>
public const string XAiBaseUrl = "https://api.x.ai/v1/";

/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -117,6 +122,15 @@ public static OpenAiApi Groq(string apiKey)
return new OpenAiApi(apiKey, baseUri: new Uri(GroqBaseUrl));
}

/// <summary>
/// Create an API to use for xAI.
/// </summary>
/// <returns></returns>
public static OpenAiApi XAi(string apiKey)
{
return new OpenAiApi(apiKey, baseUri: new Uri(XAiBaseUrl));
}

/// <summary>
/// Create an API to use for DeepSeek.
/// </summary>
Expand Down
3 changes: 2 additions & 1 deletion src/tests/OpenAI.IntegrationTests/CustomProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ public enum CustomProvider
Ollama,
LmStudio,
Groq,
XAi,
Mistral,
Codestral,
Hyperbolic,
Cerebras
Cerebras,
}
6 changes: 5 additions & 1 deletion src/tests/OpenAI.IntegrationTests/Tests.Chat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public partial class Tests
[DataRow(CustomProvider.Ollama)]
[DataRow(CustomProvider.LmStudio)]
[DataRow(CustomProvider.Groq)]
[DataRow(CustomProvider.XAi)]
[DataRow(CustomProvider.Mistral)]
[DataRow(CustomProvider.Codestral)]
[DataRow(CustomProvider.Hyperbolic)]
Expand Down Expand Up @@ -55,6 +56,7 @@ public async Task GenerateFiveRandomWords(CustomProvider customProvider)
[DataRow(CustomProvider.Ollama)]
[DataRow(CustomProvider.LmStudio)]
[DataRow(CustomProvider.Groq)]
[DataRow(CustomProvider.XAi)]
[DataRow(CustomProvider.Mistral)]
//[DataRow(CustomProvider.Codestral)]
[DataRow(CustomProvider.Hyperbolic)]
Expand Down Expand Up @@ -90,6 +92,7 @@ public async Task GenerateFiveRandomWordsAsStream(CustomProvider customProvider)
[DataRow(CustomProvider.Ollama)]
[DataRow(CustomProvider.LmStudio)]
[DataRow(CustomProvider.Groq)]
[DataRow(CustomProvider.XAi)]
[DataRow(CustomProvider.Hyperbolic)]
public async Task GenerateFiveRandomWordsAsJsonObject(CustomProvider customProvider)
{
Expand All @@ -113,8 +116,9 @@ public async Task GenerateFiveRandomWordsAsJsonObject(CustomProvider customProvi
[DataRow(CustomProvider.OpenAi)]
[DataRow(CustomProvider.Ollama)]
[DataRow(CustomProvider.Groq)]
[DataRow(CustomProvider.XAi)]
//[DataRow(CustomProvider.Together)]
[DataRow(CustomProvider.Hyperbolic)]
//[DataRow(CustomProvider.Hyperbolic)]
public async Task ChatWithVision(CustomProvider customProvider)
{
var pair = GetAuthorizedChatApi(customProvider, model: customProvider switch
Expand Down
2 changes: 1 addition & 1 deletion src/tests/OpenAI.IntegrationTests/Tests.Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ internal static (OpenAiApi Api, string Model) GetAuthorizedChatApi(CustomProvide
return (CustomProviders.Hyperbolic(apiKey:
Environment.GetEnvironmentVariable("HYPERBOLIC_API_KEY") ??
throw new AssertInconclusiveException("HYPERBOLIC_API_KEY environment variable is not found.")),
model ?? "meta-llama/Llama-3.2-90B-Vision-Instruct");
model ?? "meta-llama/Llama-3.2-3B-Instruct");
}

if (customProvider == CustomProvider.Ollama)
Expand Down

0 comments on commit 4ce248f

Please sign in to comment.