How to Integrate Groq with Cycls
This guide walks you through integrating Groq with Cycls to create an asynchronous application that can process and respond to user messages using Groq’s API.
Prerequisites
To be able to use Groq’s API, you first need to create an account in Groq. Follow the steps below to register and get your API Key:
- Go to https://console.groq.com/login and Create your account or login.
- Access GroqCloud, and navigate to API Keys.
- Click on the Create API Key button to create a new API Key.
- Copy and save your new API Key, as Groq won’t allow you to see it in the future.
- Once you have the API Key you need to set it to a
.env
file:
Integrating with Groq
By following these steps, you can integrate Groq with Cycls to create an asynchronous application that processes and responds to user messages using Groq’s API.
Set Up Your Environment
First, install the necessary dependencies. Make sure you have the dotenv
package to load environment variables and the groq
package for interacting with the Groq API.
Import Required Modules
Import the necessary modules, including AsyncApp
from Cycls, load_dotenv
from dotenv
, and Groq
from the groq
package. Also, import os
to access environment variables.
Load Environment Variables
Use load_dotenv
to load your environment variables from a .env
file. Ensure you have CYCLS_SECRET_KEY
and GROQ_API_KEY
defined in your .env
file.
Initialize the Groq Client
Create an instance of the Groq client using the API key from your environment variables.
Initialize the AsyncApp
Create an instance of AsyncApp
with the necessary parameters.
Define the Entry Point
Define the entry point function for your application. This function will process incoming messages and use the Groq client to generate a response.
Publish Your App
Finally, publish your app by calling the publish
method.
Run Your App
Run your app in the directory containing main.py
:
Complete Example
Here is the complete code for integrating Groq with Cycls: