Skip to main content

Dead-simple Groq LLM chaining. No bloat.

Project description

groq-chain

MIT License GitHub Python

Dead-simple Groq LLM chaining. One dependency. No bloat.

LangChain is overkill for most things. groq-chain gives you prompt chaining in plain Python — pass the output of one LLM call into the next, with zero magic.


Install

pip install groq-chain

Or from source:

git clone https://github.com/iamadhitya1/groq-chain
pip install -e groq-chain/

Quick start

from groqchain import GroqChain

chain = GroqChain(api_key="gsk_...")  # or set GROQ_API_KEY env var

# Single call
result = chain.run("Summarize this in 3 bullet points: {text}", text="...")
print(result)

Chained calls

Pass the output of each step into the next automatically:

result = (
    GroqChain(api_key="gsk_...")
    .step("Extract 3 key insights from: {text}", output_key="insights", text="...")
    .step("Write a LinkedIn post based on these insights: {insights}")
    .run()
)
print(result)

Each .step() receives the previous step's output via output_key.


Get all step outputs

results = (
    GroqChain(api_key="gsk_...")
    .step("Translate to French: {text}", output_key="french", text="Hello world")
    .step("Now translate the French to Spanish: {french}", output_key="spanish")
    .run_all()
)

print(results["french"])   # Bonjour le monde
print(results["spanish"])  # Hola mundo

Inject context

chain = (
    GroqChain(api_key="gsk_...")
    .context(language="Hindi", tone="casual")
    .step("Write a {tone} greeting in {language}")
)
result = chain.run()

System prompt

chain = GroqChain(
    api_key="gsk_...",
    system="You are a senior software engineer. Be concise and technical.",
)
result = chain.run("Review this code: {code}", code="...")

All options

GroqChain(
    api_key="gsk_...",                      # or GROQ_API_KEY env var
    model="llama-3.3-70b-versatile",        # any Groq model
    temperature=0.7,
    max_tokens=1024,
    system="Optional system prompt",
)

Available Groq models:

  • llama-3.3-70b-versatile ← default
  • llama-3.1-8b-instant
  • mixtral-8x7b-32768
  • gemma2-9b-it

Real-world example — document pipeline

import os
from groqchain import GroqChain

chain = GroqChain(api_key=os.environ["GROQ_API_KEY"])

with open("contract.txt") as f:
    doc = f.read()

results = (
    chain
    .step("Summarize this legal document: {doc}", output_key="summary", doc=doc)
    .step("List any risky clauses from this summary: {summary}", output_key="risks")
    .step("Rate the overall risk from 1-10 and explain why: {risks}", output_key="rating")
    .run_all()
)

print("Summary:", results["summary"])
print("Risks:",   results["risks"])
print("Rating:",  results["rating"])

License

MIT © 2025 M Adhitya

Built at Rewrite Labs — powering AI tools used by thousands.

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

groq_chain-1.0.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

groq_chain-1.0.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file groq_chain-1.0.0.tar.gz.

File metadata

  • Download URL: groq_chain-1.0.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for groq_chain-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7abc9d6f84381f4b4777b6636e8b5ebecfd6731f7beb5f73562acd6308a70fb0
MD5 8e475bf6bda57f3d1b36b497f387dca7
BLAKE2b-256 3d481f280ea7128aecab807fc0939affd0636756566500e6f6957824ebef78a4

See more details on using hashes here.

File details

Details for the file groq_chain-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: groq_chain-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for groq_chain-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 29e74fbdd8a1b30e59ef982456e5dbd8cea8a9964b8f7b7a29657c9eb6ca2a3f
MD5 443ac6ea755da480d4b6958aa2fc8b9f
BLAKE2b-256 3d62c525dfca82fa20a5b087a81219fcfb5a98671aa4d4e80f4846a713c4643c

See more details on using hashes here.

Supported by

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