Skip to content

Commit

Permalink
feat: Added Hyperbolic custom provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Oct 13, 2024
1 parent 68006cd commit 11c6121
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/libs/OpenAI/CustomProviders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ public static class CustomProviders
/// </summary>
public const string CodestralBaseUrl = "https://codestral.mistral.ai/v1";

/// <summary>
///
/// </summary>
public const string HyperbolicBaseUrl = "https://api.hyperbolic.xyz/v1";

/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -179,6 +184,15 @@ public static OpenAiApi Codestral(string apiKey)
return new OpenAiApi(apiKey, baseUri: new Uri(CodestralBaseUrl));
}

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

/// <summary>
/// Create an API to use for Ollama.
/// </summary>
Expand Down
1 change: 1 addition & 0 deletions src/tests/OpenAI.IntegrationTests/CustomProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ public enum CustomProvider
Groq,
Mistral,
Codestral,
Hyperbolic,
}
4 changes: 4 additions & 0 deletions src/tests/OpenAI.IntegrationTests/Tests.Chat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public partial class Tests
[DataRow(CustomProvider.Groq)]
[DataRow(CustomProvider.Mistral)]
[DataRow(CustomProvider.Codestral)]
[DataRow(CustomProvider.Hyperbolic)]
public async Task GenerateFiveRandomWords(CustomProvider customProvider)
{
var pair = GetAuthorizedChatApi(customProvider);
Expand Down Expand Up @@ -56,6 +57,7 @@ public async Task GenerateFiveRandomWords(CustomProvider customProvider)
[DataRow(CustomProvider.Groq)]
[DataRow(CustomProvider.Mistral)]
//[DataRow(CustomProvider.Codestral)]
[DataRow(CustomProvider.Hyperbolic)]
public async Task GenerateFiveRandomWordsAsStream(CustomProvider customProvider)
{
var pair = GetAuthorizedChatApi(customProvider);
Expand Down Expand Up @@ -88,6 +90,7 @@ public async Task GenerateFiveRandomWordsAsStream(CustomProvider customProvider)
[DataRow(CustomProvider.Ollama)]
[DataRow(CustomProvider.LmStudio)]
[DataRow(CustomProvider.Groq)]
[DataRow(CustomProvider.Hyperbolic)]
public async Task GenerateFiveRandomWordsAsJsonObject(CustomProvider customProvider)
{
var pair = GetAuthorizedChatApi(customProvider);
Expand All @@ -111,6 +114,7 @@ public async Task GenerateFiveRandomWordsAsJsonObject(CustomProvider customProvi
[DataRow(CustomProvider.Ollama)]
[DataRow(CustomProvider.Groq)]
//[DataRow(CustomProvider.Together)]
[DataRow(CustomProvider.Hyperbolic)]
public async Task ChatWithVision(CustomProvider customProvider)
{
var pair = GetAuthorizedChatApi(customProvider, model: customProvider switch
Expand Down
21 changes: 17 additions & 4 deletions src/tests/OpenAI.IntegrationTests/Tests.Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ private static RealtimeConversationClient GetAuthenticatedRealtimeClient()
internal static (OpenAiApi Api, string Model) GetAuthorizedChatApi(CustomProvider customProvider, string? model = null)
{
const string localIpAddress = "10.10.5.85";
if (customProvider is CustomProvider.Ollama or CustomProvider.LmStudio &&
Environment.GetEnvironmentVariable("LOCAL_TESTS") is null)
if (customProvider is CustomProvider.Ollama or CustomProvider.LmStudio)// &&
//Environment.GetEnvironmentVariable("LOCAL_TESTS") is null)
{
throw new AssertInconclusiveException("This test only runs on local environment.");
}
Expand Down Expand Up @@ -111,16 +111,29 @@ internal static (OpenAiApi Api, string Model) GetAuthorizedChatApi(CustomProvide
throw new AssertInconclusiveException("CODESTRAL_API_KEY environment variable is not found.")),
model ?? "codestral-latest");
}
if (customProvider == CustomProvider.Hyperbolic)
{
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");
}

if (customProvider == CustomProvider.Ollama)
{
return (CustomProviders.Ollama(new Uri($"http://{localIpAddress}:11434/v1")),
var pair = (CustomProviders.Ollama(new Uri($"http://{localIpAddress}:11434/v1")),
model ?? "llama3.2");
//pair.Item1.HttpClient.Timeout = TimeSpan.FromSeconds(15);

return pair;
}
if (customProvider == CustomProvider.LmStudio)
{
return (CustomProviders.LmStudio(new Uri($"http://{localIpAddress}:1234/v1")),
var pair = (CustomProviders.LmStudio(new Uri($"http://{localIpAddress}:1234/v1")),
model ?? "lmstudio-community/Llama-3.2-3B-Instruct-GGUF");
//pair.Item1.HttpClient.Timeout = TimeSpan.FromSeconds(15);

return pair;
}

var apiKey =
Expand Down
1 change: 1 addition & 0 deletions src/tests/OpenAI.IntegrationTests/Tools/Tests.Tools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public partial class Tests
// [DataRow(CustomProvider.DeepSeek)]
// [DataRow(CustomProvider.OpenRouter)]
// [DataRow(CustomProvider.Together)]
// [DataRow(CustomProvider.Hyperbolic)]
public async Task WeatherTools(CustomProvider customProvider)
{
var pair = GetAuthorizedChatApi(customProvider, model: customProvider switch
Expand Down

0 comments on commit 11c6121

Please sign in to comment.