Skip to content

Commit d79c577

Browse files
committed
feat: Added Cohere custom provider.
1 parent 243b439 commit d79c577

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ using var api = CustomProviders.SambaNova("API_KEY");
190190
using var api = CustomProviders.Mistral("API_KEY");
191191
using var api = CustomProviders.Codestral("API_KEY");
192192
using var api = CustomProviders.Cerebras("API_KEY");
193+
using var api = CustomProviders.Cohere("API_KEY");
193194
using var api = CustomProviders.Ollama();
194195
using var api = CustomProviders.LmStudio();
195196
```

src/libs/tryAGI.OpenAI/CustomProviders.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public static class CustomProviders
7171
/// </summary>
7272
public const string HyperbolicBaseUrl = "https://api.hyperbolic.xyz/v1";
7373

74+
/// <summary>
75+
///
76+
/// </summary>
77+
public const string CohereBaseUrl = "https://api.cohere.ai/compatibility/v1";
78+
7479
/// <summary>
7580
///
7681
/// </summary>
@@ -212,6 +217,15 @@ public static OpenAiClient Hyperbolic(string apiKey)
212217
return new OpenAiClient(apiKey, baseUri: new Uri(HyperbolicBaseUrl));
213218
}
214219

220+
/// <summary>
221+
/// Create an API to use for Cohere.
222+
/// </summary>
223+
/// <returns></returns>
224+
public static OpenAiClient Cohere(string apiKey)
225+
{
226+
return new OpenAiClient(apiKey, baseUri: new Uri(CohereBaseUrl));
227+
}
228+
215229
/// <summary>
216230
/// Create an API to use for Ollama.
217231
/// </summary>

src/tests/OpenAI.IntegrationTests/CustomProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,5 @@ public enum CustomProvider
2020
Codestral,
2121
Hyperbolic,
2222
Cerebras,
23+
Cohere,
2324
}

src/tests/OpenAI.IntegrationTests/Tests.Helpers.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ internal static (OpenAiClient Api, string Model) GetAuthorizedChatApi(CustomProv
149149
throw new AssertInconclusiveException("XAI_API_KEY environment variable is not found.")),
150150
model ?? "grok-beta");
151151
}
152+
if (customProvider == CustomProvider.Cohere)
153+
{
154+
return (CustomProviders.Cohere(apiKey:
155+
Environment.GetEnvironmentVariable("COHERE_API_KEY") ??
156+
throw new AssertInconclusiveException("COHERE_API_KEY environment variable is not found.")),
157+
model ?? "command-r-08-2024");
158+
}
152159

153160
var apiKey =
154161
Environment.GetEnvironmentVariable("OPENAI_API_KEY") ??

0 commit comments

Comments
 (0)