https://github.com/RMNCLDYO/groq-ai-toolkit
A versatile CLI and Python wrapper for Groq AI's breakthrough LPU Inference Engine. Streamline the creation of chatbots and generate dynamic text with speeds of up to 300 tokens/sec.
https://github.com/RMNCLDYO/groq-ai-toolkit
artificial-intelligence groq groq-ai groq-ai-api groq-api groqai groqaiapi groqapi language-processing language-processing-unit languageprocessingunit large-laguage-model large-language-models llama2-70b llm llms lpu lpu-inference-engine mixtral-8x7b
Last synced: about 2 months ago
JSON representation
A versatile CLI and Python wrapper for Groq AI's breakthrough LPU Inference Engine. Streamline the creation of chatbots and generate dynamic text with speeds of up to 300 tokens/sec.
- Host: GitHub
- URL: https://github.com/RMNCLDYO/groq-ai-toolkit
- Owner: RMNCLDYO
- License: mit
- Created: 2024-03-05T17:55:52.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-03T19:47:23.000Z (about 1 year ago)
- Last Synced: 2024-04-03T20:49:26.853Z (about 1 year ago)
- Topics: artificial-intelligence, groq, groq-ai, groq-ai-api, groq-api, groqai, groqaiapi, groqapi, language-processing, language-processing-unit, languageprocessingunit, large-laguage-model, large-language-models, llama2-70b, llm, llms, lpu, lpu-inference-engine, mixtral-8x7b
- Language: Python
- Homepage:
- Size: 124 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
- jimsghstars - RMNCLDYO/groq-ai-toolkit - A versatile CLI and Python wrapper for Groq AI's breakthrough LPU Inference Engine. Streamline the creation of chatbots and generate dynamic text with speeds of up to 800 tokens/sec. (Python)
README
## Overview
The Groq AI Toolkit makes it easy to use Groq's breakthrough LPU Inference Engine for creating chatbots and generating text with near-real-time responses (800 tokens/sec). It's designed for everyone, from beginners to experienced developers, allowing quick addition of AI features to projects with simple commands. While it offers simplicity and lightweight integration, it doesn't compromise on power; experienced developers can access the full suite of advanced options available via the API, ensuring robust customization and control. This toolkit is perfect for those looking to efficiently tap into advanced AI without getting bogged down in technical details, yet it still provides the depth needed for complex project requirements.## Key Features
- **Conversational AI**: Create interactive, real-time chat experiences (chatbots) or AI assistants.
- **Text Generation**: Produce coherent and contextually relevant text and answers from simple prompts.
- **Ultra-Fast Performance**: Achieve near-real-time responses with an impressive speed of 800 tokens per second.
- **Highly Customizable**: Tailor settings like streaming, JSON outputs, system prompts and more to suit your specific requirements.
- **Lightweight Integration**: Efficiently designed with minimal dependencies, requiring only the `requests` package for core functionality.## Prerequisites
- `Python 3.x`
- An API key from Groq AI## Dependencies
The following Python packages are required:
- `requests`: For making HTTP requests to Groq's API.The following Python packages are optional:
- `python-dotenv`: For managing API keys and other environment variables.## Installation
To use the Groq AI Toolkit, clone the repository to your local machine and install the required Python packages.Clone the repository:
```bash
git clone https://github.com/RMNCLDYO/groq-ai-toolkit.git
```Navigate to the repositories folder:
```bash
cd groq-ai-toolkit
```Install the required dependencies:
```bash
pip install -r requirements.txt
```## Configuration
1. Obtain an API key from [Groq AI](https://console.groq.com/).
2. You have three options for managing your API key:
Click here to view the API key configuration options
- **Setting it as an environment variable on your device (recommended for everyday use)**
- Navigate to your terminal.
- Add your API key like so:
```shell
export GROQ_API_KEY=your_api_key
```
This method allows the API key to be loaded automatically when using the wrapper or CLI.
- **Using an .env file (recommended for development):**
- Install python-dotenv if you haven't already: `pip install python-dotenv`.
- Create a .env file in the project's root directory.
- Add your API key to the .env file like so:
```makefile
GROQ_API_KEY=your_api_key
```
This method allows the API key to be loaded automatically when using the wrapper or CLI, assuming you have python-dotenv installed and set up correctly.
- **Direct Input:**
- If you prefer not to use a `.env` file, you can directly pass your API key as an argument to the CLI or the wrapper functions.
***CLI***
```shell
--api_key "your_api_key"
```
***Wrapper***
```shell
api_key="your_api_key"
```
This method requires manually inputting your API key each time you initiate an API call, ensuring flexibility for different deployment environments.
## Usage
The Groq AI Toolkit can be used in two different modes: `Chat` and `Text`. Each mode is designed for specific types of interactions with Groq's open models.## Chat Mode
Chat mode is intended for chatting with an AI model (similar to a chatbot) or building conversational applications.#### Example Usage
***CLI***
```bash
python cli.py --chat
```***Wrapper***
```python
from groq import ChatChat().run()
```> An executable version of this example can be found [here](./examples/example_chat.py). (*You must move this file to the root folder before running the program.*)
## Text Mode
Text mode is suitable for generating text content based on a provided prompt.#### Example Usage
***CLI***
```bash
python cli.py --text --prompt "Explain the importance of low latency LLMs."
```***Wrapper***
```python
from groq import TextText().run(prompt="Explain the importance of low latency LLMs.")
```> An executable version of this example can be found [here](./examples/example_text.py). (*You must move this file to the root folder before running the program.*)
## Advanced Configuration
### CLI and Wrapper Options
| **Description** | **CLI Flags** | **CLI Usage** | **Wrapper Usage** |
|--------------------------------------|--------------------------|--------------------------------------------------------|------------------------------------------------------|
| Enable chat mode | `-c`, `--chat` | --chat | *See mode usage above.* |
| Enable text mode | `-t`, `--text` | --text | *See mode usage above.* |
| User prompt | `-p`, `--prompt` | --prompt "Explain the importance of low latency LLMs." | prompt="Explain the importance of low latency LLMs." |
| API key for authentication | `-a`, `--api_key` | --api_key "your_api_key" | api_key="your_api_key" |
| Model name | `-m`, `--model` | --model "llama-3.1-8b-instant" | model="llama-3.1-8b-instant" |
| System prompt (instructions) | `-sp`, `--system_prompt` | --system_prompt "You are a helpful assistant." | system_prompt="You are a helpful assistant." |
| Enable streaming mode | `-st`, `--stream` | --stream | stream=True |
| Enable json mode | `-js`, `--json` | --json | json=True |
| Sampling temperature | `-tm`, `--temperature` | --temperature 0.7 | temperature=0.7 |
| Maximum number of tokens to generate | `-mt`, `--max_tokens` | --max_tokens 1024 | max_tokens=1024 |
| Nucleus sampling threshold | `-tp`, `--top_p` | --top_p 0.9 | top_p=0.9 |
| Seed used for sampling | `-sd`, `-seed` | --seed 123456789 | seed=123456789 |
| Stop sequence for completion | `-ss`, `--stop` | --stop "\n" | stop="\n" |> *To exit the program at any time, you can type **`exit`** or **`quit`**. This command works similarly whether you're interacting with the program via the CLI or through the Python wrapper ensuring that you can easily and safely conclude your work with the Groq AI Toolkit without having to resort to interrupt signals or forcibly closing the terminal or command prompt.*
## Available Models
| **Model** | **Max Tokens** |
|-------------------------------------|----------------|
| `llama-3.1-70b-versatile` (Preview) | 131072 |
| `llama-3.1-8b-instant` (Preview) | 131072 |
| `llava-v1.5-7b-4096-preview` | 4096 |
| `llama-guard-3-8b` | 8192 |
| `llama3-70b-8192` | 8192 |
| `llama3-8b-8192` | 8192 |
| `llama2-70b-4096` | 4096 |
| `mixtral-8x7b-32768` | 32768 |
| `gemma-7b-it` | 8192 |
| `gemma2-9b-it` | 8192 |> [!NOTE]
> *While in Preview, Groq is limiting 3.1 models to max tokens of 8k.*## Contributing
Contributions are welcome!Please refer to [CONTRIBUTING.md](.github/CONTRIBUTING.md) for detailed guidelines on how to contribute to this project.
## Reporting Issues
Encountered a bug? We'd love to hear about it. Please follow these steps to report any issues:1. Check if the issue has already been reported.
2. Use the [Bug Report](.github/ISSUE_TEMPLATE/bug_report.md) template to create a detailed report.
3. Submit the report [here](https://github.com/RMNCLDYO/groq-ai-toolkit/issues).Your report will help us make the project better for everyone.
## Feature Requests
Got an idea for a new feature? Feel free to suggest it. Here's how:1. Check if the feature has already been suggested or implemented.
2. Use the [Feature Request](.github/ISSUE_TEMPLATE/feature_request.md) template to create a detailed request.
3. Submit the request [here](https://github.com/RMNCLDYO/groq-ai-toolkit/issues).Your suggestions for improvements are always welcome.
## Versioning and Changelog
Stay up-to-date with the latest changes and improvements in each version:- [CHANGELOG.md](.github/CHANGELOG.md) provides detailed descriptions of each release.
## Security
Your security is important to us. If you discover a security vulnerability, please follow our responsible disclosure guidelines found in [SECURITY.md](.github/SECURITY.md). Please refrain from disclosing any vulnerabilities publicly until said vulnerability has been reported and addressed.## License
Licensed under the MIT License. See [LICENSE](LICENSE) for details.