Skip to content

Commit 8d61e50

Browse files
authored
GroqCloud integration (#75)
GroqCloud integration has been added
1 parent f6bc2aa commit 8d61e50

14 files changed

Lines changed: 136 additions & 4 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Examples.Utils;
2+
using MaIN.Core.Hub;
3+
4+
namespace Examples;
5+
6+
public class ChatExampleGroqCloud : IExample
7+
{
8+
public async Task Start()
9+
{
10+
GroqCloudExample.Setup(); //We need to provide GroqCloud API key
11+
Console.WriteLine("(GroqCloud) ChatExample is running!");
12+
13+
await AIHub.Chat()
14+
.WithModel("llama3-8b-8192")
15+
.WithMessage("Which color do people like the most?")
16+
.CompleteAsync(interactive: true);
17+
}
18+
}

Examples/Examples/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ static void RegisterExamples(IServiceCollection services)
6767
services.AddTransient<ChatWithImageGenGeminiExample>();
6868
services.AddTransient<ChatWithFilesExampleGemini>();
6969
services.AddTransient<ChatWithReasoningDeepSeekExample>();
70+
services.AddTransient<ChatExampleGroqCloud>();
7071
}
7172

7273
async Task RunSelectedExample(IServiceProvider serviceProvider)
@@ -153,9 +154,9 @@ public class ExampleRegistry(IServiceProvider serviceProvider)
153154
("\u25a0 Gemini Chat with image", serviceProvider.GetRequiredService<ChatWithImageGenGeminiExample>()),
154155
("\u25a0 Gemini Chat with files", serviceProvider.GetRequiredService<ChatWithFilesExampleGemini>()),
155156
("\u25a0 DeepSeek Chat with reasoning", serviceProvider.GetRequiredService<ChatWithReasoningDeepSeekExample>()),
157+
("\u25a0 GroqCloud Chat", serviceProvider.GetRequiredService<ChatExampleGroqCloud>()),
156158
("\u25a0 McpClient example", serviceProvider.GetRequiredService<McpExample>()),
157159
("\u25a0 McpAgent example", serviceProvider.GetRequiredService<McpAgentsExample>())
158-
159160
};
160161
}
161162
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using MaIN.Core;
2+
using MaIN.Domain.Configuration;
3+
4+
namespace Examples.Utils;
5+
6+
public class GroqCloudExample
7+
{
8+
public static void Setup()
9+
{
10+
MaINBootstrapper.Initialize(configureSettings: (options) =>
11+
{
12+
options.BackendType = BackendType.GroqCloud;
13+
options.GroqCloudKey = "<YOUR_GROQ_KEY>";
14+
});
15+
}
16+
}

Releases/0.3.1.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# 0.3.1 release
2+
3+
GroqCloud integration has been added.

src/MaIN.Core/.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package>
33
<metadata>
44
<id>MaIN.NET</id>
5-
<version>0.3.0</version>
5+
<version>0.3.1</version>
66
<authors>Wisedev</authors>
77
<owners>Wisedev</owners>
88
<icon>favicon.png</icon>

src/MaIN.Domain/Configuration/MaINSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class MaINSettings
1111
public string? OpenAiKey { get; set; }
1212
public string? GeminiKey { get; set; }
1313
public string? DeepSeekKey { get; set; }
14+
public string? GroqCloudKey { get; set; }
1415
public MongoDbSettings? MongoDbSettings { get; set; }
1516
public FileSystemSettings? FileSystemSettings { get; set; }
1617
public SqliteSettings? SqliteSettings { get; set; }
@@ -23,4 +24,5 @@ public enum BackendType
2324
OpenAi = 1,
2425
Gemini = 2,
2526
DeepSeek = 3,
27+
GroqCloud = 4,
2628
}

src/MaIN.InferPage/Program.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@
6565
apiKeyVariable = "DEEPSEEK_API_KEY";
6666
apiName = "Deepseek";
6767
break;
68+
69+
case "groqcloud":
70+
Utils.GroqCloud = true;
71+
apiKeyVariable = "GROQ_API_KEY";
72+
apiName = "GroqCloud";
73+
break;
6874
}
6975

7076
var key = Environment.GetEnvironmentVariable(apiKeyVariable);
@@ -103,6 +109,13 @@
103109
settings.BackendType = BackendType.DeepSeek;
104110
});
105111
}
112+
else if (Utils.GroqCloud)
113+
{
114+
builder.Services.AddMaIN(builder.Configuration, settings =>
115+
{
116+
settings.BackendType = BackendType.GroqCloud;
117+
});
118+
}
106119
else
107120
{
108121
if (Utils.Path == null && !KnownModels.IsModelSupported(Utils.Model!))

src/MaIN.InferPage/Utils.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public static class Utils
1010
public static bool OpenAi { get; set; }
1111
public static bool Gemini { get; set; }
1212
public static bool DeepSeek { get; set; }
13+
public static bool GroqCloud { get; set; }
1314
public static string? Path { get; set; }
1415
public static bool Reason { get; set; }
1516
}

src/MaIN.Services/Bootstrapper.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ private static IServiceCollection AddHttpClients(this IServiceCollection service
106106
});
107107
services.AddHttpClient(ServiceConstants.HttpClients.OpenAiClient);
108108
services.AddHttpClient(ServiceConstants.HttpClients.GeminiClient);
109+
services.AddHttpClient(ServiceConstants.HttpClients.DeepSeekClient);
110+
services.AddHttpClient(ServiceConstants.HttpClients.GroqCloudClient);
109111
services.AddHttpClient(ServiceConstants.HttpClients.ImageDownloadClient);
110112
services.AddHttpClient(ServiceConstants.HttpClients.ModelContextDownloadClient, client =>
111113
{

src/MaIN.Services/Constants/ServiceConstants.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public static class HttpClients
99
public const string OpenAiClient = "OpenAiClient";
1010
public const string GeminiClient = "GeminiClient";
1111
public const string DeepSeekClient = "DeepSeekClient";
12+
public const string GroqCloudClient = "GroqCloudClient";
1213
public const string ImageDownloadClient = "ImageDownloadClient";
1314
public const string ModelContextDownloadClient = "ModelContextDownloadClient";
1415
}
@@ -24,7 +25,10 @@ public static class ApiUrls
2425
public const string GeminiModels = "https://generativelanguage.googleapis.com/v1beta/models";
2526

2627
public const string DeepSeekOpenAiChatCompletions = "https://api.deepseek.com/v1/chat/completions";
27-
public const string DeepSeekModels = "https://api.deepseek.com/models";
28+
public const string DeepSeekModels = "https://api.deepseek.com/models";
29+
30+
public const string GroqCloudOpenAiChatCompletions = "https://api.groq.com/openai/v1/chat/completions";
31+
public const string GroqCloudModels = "https://api.groq.com/openai/v1/models";
2832
}
2933

3034
public static class Messages

0 commit comments

Comments
 (0)