Skip to main content

Use Groq.com as llm

Project description

GROQ without API : GroqOn

This projects uses playwright to Access GROQ using python

Table of Contents

  1. Introduction
  2. Installation
  3. CLI Usage
  • Starting the CLI
  • Configuring the CLI
  • Starting the Server
  • Querying the Server
  • Stopping the Server
  1. Python API Usage
  • Using the AgroqClient Class
  • Using requests Library
  1. Key Features and Benefits
  2. Contribution

Introduction

Groqon is a powerful package that provides a convenient interface to interact with large language models (LLMs) hosted on Groq.com for FREE, No api is required. It offers both a command-line interface (CLI) and a Python API for seamless integration into various workflows.

Working

  • It emulates user using playwright and queries the selected model and ouputs the response as a json object.
  • It uses cookie to login.(For the first time you have to login in under 100 seconds(browser will be open for 100 sec), your cookies will be saved and will be used again next time you query).
  • This code doesn't share your cookie or any kind of data with anyone.

Note Groq has set some requests/minute limit per model. Once you hit the limit, you will get error response. Limit is 30req/min (not sure), so either use all different models (5 models * 30 req) =150 req, or just make fewer queries.

Installation

To install the Groqon package, use pip:

pip install groqon

make sure you have playwright installed, if not do this

# install firefox
playwright install firefox 

CLI Usage

The Groqon CLI provides several commands to interact with the Agroq server.

Configuring the Package

To configure Groqon settings:

groqon config [OPTIONS]

Options:

  • --cookie_file, -cf : Set the cookie file path
  • --models, -m : Set default models
  • --headless, -hl : Set headless mode
  • --n_workers, -w : Set number of workers
  • --reset_login, -rl : Set reset login option
  • --verbose, -v : Set verbose output
  • --print_output, -p : Set print output option

Starting the Server

To start the Agroq server:

groqon serve [OPTIONS]

Options:

  • --cookie_file, -cf : Path to the cookie file (default: ~/.groqon/groq_cookie.json)
  • --models, -m : Comma-separated list of models to use
  • --headless, -hl : Run in headless mode (default: True)
  • --n_workers, -w : Number of worker windows (default: 1)
  • --reset_login, -rl : Reset login information (default: False)
  • --verbose, -v : Enable verbose output (default: False)

Querying the Server

To send a query to the server:

groqon query 'who is megan fox?' [OPTIONS] 

Options:

  • --save_dir , -o : Directory to save the generated response
  • --models , -m : Comma-separated list of models to use
  • --system_prompt , -sp : System prompt for the query
  • --print_output , -p : Print output to console (default: True)
  • --temperature , -t : Temperature for text generation
  • --max_tokens , -mt : Maximum number of tokens to generate
  • --stream , -s : Enable streaming mode (default: True)
  • --top_p , -tp : Top-p sampling parameter (do not use this)
  • --stop_server , -ss : Stop the server after the query (default: False)

Stopping the Server

To stop the Agroq server:

groqon stop

Python API Usage

Making Requests to the Agroq Server

To use the Groqon package in your Python code:

Make sure you have start groqon server with groqon serve command in the background

from groqon import AgroqClient, AgroqClientConfig

# Define the configuration
config = AgroqClientConfig(
    headless=False,
    models=['llama3-8b'], # can be llama3-70b , gemma-7b , gemma2, mixtral
    system_prompt="You are a helpful assistant.",
    print_output=True,
    temperature=0.1,
    max_tokens=2048,
    stream=False
)

# Create an AgroqClient instance
agroq = AgroqClient(config=config)

# use Asynchronously =====================================

# Make a single query
async def single_query():
    response = await agroq.multi_query_async("What is the capital of France?")
    print(response)

# Make multiple queries
async def multiple_queries():
    queries = [
        "What is the capital of France?",
        "Who wrote 'To Kill a Mockingbird'?",
        "What is the largest planet in our solar system?"
    ]
    responses = await agroq.multi_query_async(queries)
    for response in responses:
        print(response)

# Run the async functions
import asyncio
asyncio.run(single_query())
asyncio.run(multiple_queries())


# use synchronously =====================================
agroq.multi_query([
  'how old is sun',
  'who is messi?'
])

Using wget or requests for API Calls

You can also make API calls to the Groqon server using wget or the requests library: Using wget:

wget -q -O - --header="Content-Type: application/json" --post-data '{"model": "gemma-7b-it","messages": [{"role": "system", "content": "Please try to provide useful, helpful and actionable answer"},{"role": "user", "content": "who is megan fox?"}],"temperature": 0.1,"max_tokens": 2048,"top_p": 1,"stream": true}' http://localhost:8888/

Using requests:

import requests

url = "http://localhost:8888"
data = {
  "model": "gemma-7b-it",
  "messages": [
      {"role": "system", "content": "Please try to provide useful, helpful and actionable answers."},
      {"role": "user", "content": "why donald trump got shot?"}
  ],
  "temperature": 0.1,
  "max_tokens": 2048,
  "top_p": 1,
  "stream": True
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=data, headers=headers)
print(response.json())

Key Features and Benefits

  • Fast Inference: Groqon leverages the power of Groq's API to provide rapid inference for large language models, significantly reducing the time required for generating responses.
  • Multiple Model Support: The package supports various LLMs, allowing users to choose the most suitable model for their specific tasks.
  • Asynchronous Processing: With its asynchronous design, Groqon can handle multiple queries simultaneously, improving overall throughput and efficiency.
  • Flexible Configuration: Users can easily customize settings such as temperature, max tokens, and system prompts to fine-tune the model's behavior.
  • CLI and Python API : Groqon offers both a command-line interface for quick interactions and a Python API for seamless integration into existing codebases.
  • Error Handling: Robust error handling ensures that issues are caught and reported, improving the reliability of the system.
  • Save and Print Options: Users can save generated responses to files and control whether outputs are printed to the console.
  • HTTP Interface: The server supports HTTP requests, making it easy to integrate with web applications and other services.
  • Worker Management: The server uses multiple workers to handle requests efficiently, improving concurrency and responsiveness.

By leveraging these features, Groqon provides a powerful and flexible solution for interacting with large language models, making it an excellent choice for developers and researchers working on natural language processing tasks.

Contribution

Feel free to contibute your ideas, features.

Buy me a Coffee

"Buy Me A Coffee"

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

groqon-0.2.0.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

groqon-0.2.0-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file groqon-0.2.0.tar.gz.

File metadata

  • Download URL: groqon-0.2.0.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.2 Linux/6.8.0-38-generic

File hashes

Hashes for groqon-0.2.0.tar.gz
Algorithm Hash digest
SHA256 903b745d50582b4bd2814abfda1d2b1749c1d5e7bd02490924e737a3d4041e73
MD5 84e0211e22a85fd0719a0d5883a4d085
BLAKE2b-256 88bfd416d8e0c4ef539f69c85d12970c40895259f54b0564ab5c2427dfc16c5b

See more details on using hashes here.

File details

Details for the file groqon-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: groqon-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 22.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.2 Linux/6.8.0-38-generic

File hashes

Hashes for groqon-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 064b84b7f7dcfac0eccee56c88c72530616336d785e0f930e7df85400c8af7c6
MD5 11b5bfde4f2a542fc228dc976eb26d3d
BLAKE2b-256 431c47b2199354c9ac4e41c64fad89a3068d2c12780f684c5e9203b4cdae5234

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page