LLM Open Connector + Groq
Learn how to implement Salesforce's LLM Open Connector with the Groq platform for fast AI inference. We also cover how to deploy the connector as a Flask app on Heroku with a simple web UI for testing.
Prerequisitesโ
Before you begin, make sure that your local environment meets these prerequisites.
- Python 3.9 or later installed on your local machine
- A Heroku account (sign up at https://signup.heroku.com/)
- Heroku CLI installed (https://devcenter.heroku.com/articles/heroku-cli)
- Git installed on your local machine
- A Groq API key (sign up at https://console.groq.com/)
Set Up Your Local Environmentโ
-
Create a new directory for your project:
mkdir llm-open-connector
cd llm-open-connector -
Create a virtual environment and activate it:
python -m venv venv
source venv/bin/activate # On Windows, use `venv\Scripts\activate` -
Download these files from the einstein-platform repository:
-
Copy the downloaded files into your project directory.
-
Install the required packages:
pip install -r requirements.txt
Configure Your Local Environmentโ
-
For local testing, create a
.env
file in your project directory and add your Groq API key:GROQ_API_KEY=your_groq_api_key_here
Replace
your_groq_api_key_here
with your actual Groq API key. -
Make sure your
.gitignore
file includes the.env
file to avoid accidentally committing sensitive information.
Test Your Application Locallyโ
-
Run your Flask application:
python app.py
-
Your app should now be running on
http://127.0.0.1:5000/
. -
Test the endpoints using a tool like cURL or Postman to ensure they're working correctly.
To test the chat/completions
endpoint, run this cURL command:
curl -X POST http://127.0.0.1:5000/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "llama3-8b-8192",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is the capital of Canada?"}
],
"max_tokens": 50,
"temperature": 0.7,
"n": 1
}'
Prepare for Heroku Deploymentโ
-
Initialize a Git repository in your project directory:
git init
-
Add your files to the repository:
git add .
-
Commit your changes:
git commit -m "Initial commit"
Update Your Default Branchโ
To switch the default branch used to deploy apps from master
to main
, follow these steps:
-
Create a new branch locally:
git checkout -b main
-
Delete the old default branch locally:
git branch -D master
Now, the local environment only knows about the
main
branch. -
Reset the git repository on the Heroku Platform:
- Use the
heroku-reset
command from theheroku-repo
CLI plugin. - This will not impact the running application.
Note: Communicate this change with your team. If other developers are unaware of the reset, they might push to
master
, overwriting the reset. - Use the
-
To switch the default branch in GitHub, refer to this article: Setting the Default Branch.
Deploy to Herokuโ
-
Make sure you're logged in to the Heroku CLI:
heroku login
-
Create a new Heroku app:
heroku create your-app-name
Replace
your-app-name
with a unique name for your application. -
Set the GROQ_API_KEY config var on Heroku:
heroku config:set GROQ_API_KEY=your_groq_api_key_here -a your-app-name
Replace
your_groq_api_key_here
with your actual Groq API key. -
Deploy your app to Heroku:
git push heroku main
-
Open your deployed app:
heroku open
Your LLM Open Connector should now be deployed and accessible via the Heroku URL.
Test Your Deployed Applicationโ
You can test your deployed application in two ways:
-
Using the example UI:
- Open your browser and navigate to
https://your-app-name.herokuapp.com
- You'll see a simple interface where you can input prompts and get responses from the LLM
- Try different prompts and get super fast responses!
- Open your browser and navigate to
-
Using API endpoints: Use a tool like cURL or Postman to test the endpoints of your Flask app:
- Chat Completions:
POST https://your-app-name.herokuapp.com/chat/completions
- Chat Completions:
Conclusionโ
You have successfully created and deployed an LLM Open Connector using the Groq API and deployed it to Heroku! This connector adheres to the Salesforce LLM Open Connector API specification, allowing for seamless integration with the Einstein AI Platform using the BYOLLM feature.
With this connector, you can bring new foundation models like Llama 3 into Einstein Studio that take advantage of Groq's fast inference platform.
Remember to monitor your usage and costs associated with the Groq API, and consider implementing additional security measures, such as rate limiting, CORS restrictions, and user authentication, before using this connector in a production environment.