Skip to content

Commit

Permalink
add custom provider cerebras
Browse files Browse the repository at this point in the history
  • Loading branch information
danijerez authored and HavenDV committed Oct 26, 2024
1 parent 5b767cd commit 7d94ce1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ using var api = CustomProviders.Perplexity("API_KEY");
using var api = CustomProviders.SambaNova("API_KEY");
using var api = CustomProviders.Mistral("API_KEY");
using var api = CustomProviders.Codestral("API_KEY");
using var api = CustomProviders.Cerebras("API_KEY");
using var api = CustomProviders.Ollama();
using var api = CustomProviders.LmStudio();
```
Expand Down
16 changes: 15 additions & 1 deletion src/libs/OpenAI/CustomProviders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ public static class CustomProviders
///
/// </summary>
public const string LmStudioBaseUrl = "http://localhost:1234/v1";


/// <summary>
/// https://inference-docs.cerebras.ai/openai
/// </summary>
public const string CerebrasBaseUrl = "https://api.cerebras.ai/v1";

/// <summary>
/// Creates an API to use for GitHub Models: https://github.com/marketplace/models
/// </summary>
Expand Down Expand Up @@ -210,4 +215,13 @@ public static OpenAiApi LmStudio(Uri? baseUri = null)
{
return new OpenAiApi(baseUri: baseUri ?? new Uri(LmStudioBaseUrl));
}

/// <summary>
/// Create an API to use for Cerebras.
/// </summary>
/// <returns></returns>
public static OpenAiApi Cerebras(string apiKey)
{
return new OpenAiApi(apiKey, baseUri: new Uri(CerebrasBaseUrl));
}
}
1 change: 1 addition & 0 deletions src/tests/OpenAI.IntegrationTests/CustomProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ public enum CustomProvider
Mistral,
Codestral,
Hyperbolic,
Cerebras
}
9 changes: 8 additions & 1 deletion src/tests/OpenAI.IntegrationTests/Tests.Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,14 @@ internal static (OpenAiApi Api, string Model) GetAuthorizedChatApi(CustomProvide

return pair;
}

if (customProvider == CustomProvider.Cerebras)
{
return (CustomProviders.Cerebras(apiKey:
Environment.GetEnvironmentVariable("CEREBRAS_API_KEY") ??
throw new AssertInconclusiveException("CEREBRAS_API_KEY environment variable is not found.")),
model ?? "llama3.1-70b");
}

var apiKey =
Environment.GetEnvironmentVariable("OPENAI_API_KEY") ??
throw new AssertInconclusiveException("OPENAI_API_KEY environment variable is not found.");
Expand Down

0 comments on commit 7d94ce1

Please sign in to comment.