Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add custom provider cerebras #117

Merged
merged 1 commit into from
Oct 26, 2024
Merged
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
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
Loading