GroqSharp is a community maintained C# client library for interacting with GroqCloud. Designed to provide a simple and flexible interface, it enables seamless integration of Groq services into your C# applications.
GroqSharp is designed to simplify your interactions with GroqCloud by offering:
- Fluent API: Configure client options and parameters fluently for convenient setup.
- Structured Responses: Utilize specific JSON response structures for predictable outputs.
- Function Integration: Integrate and manage function calling within your applications.
- Retry Mechanism: Implement configurable retry policies to handle transient errors when working with structured data effectively.
- Streaming Support: Support for streaming responses to process data as it becomes available, providing real-time interaction capabilities.
GroqSharp's function/tool integration support allows developers to extend the functionality of the Groq platform within their applications, making it easier to implement complex workflows and data manipulations directly within chat interfaces.
Install GroqSharp via NuGet:
dotnet add package GroqSharp
For security and flexibility, it is recommended to store your API key in an environment variable. This prevents hardcoding sensitive information in your source code:
var apiKey = Environment.GetEnvironmentVariable("GROQ_API_KEY");
var apiModel = "llama3-70b-8192"; // Or other supported model
var groqClient = new GroqClient(apiKey, apiModel);
Configure your client using a fluent API:
IGroqClient groqClient = new GroqClient(apiKey, apiModel)
.SetTemperature(0.5)
.SetMaxTokens(512)
.SetTopP(1)
.SetStop("NONE")
.SetStructuredRetryPolicy(5); // Retry up to 5 times on failure
Explore sample projects that demonstrate various capabilities of GroqSharp:
- Chat Basics - Basic chat functionalities.
- Chat Streaming - Streaming responses for dynamic interaction.
- Structured Data - Handling structured JSON responses.
- Structured Poco - Map structured JSON responses to POCOs.
- Tool Integration - Using custom tools for enhanced functionalities.
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
This library is licensed under the MIT License. See the LICENSE file for more details.
GroqSharp offers a flexible and efficient way to incorporate Groq's capabilities into your C# projects, ensuring secure and configurable interaction management.