Skip to main content

Dead-simple Groq LLM chaining in Python. Chain prompts with .step() — no LangChain needed.

Project description

groq-chain

PyPI 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.

groq-chain demo

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"])

Author

M. Adhitya — Founder of Rewrite Labs, final-year B.Tech Computer Engineering student at IITRAM Ahmedabad. Builds AI products and open source libraries.

License

MIT © 2025 M. Adhitya

Built at Rewrite Labs

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.1.tar.gz (5.9 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.1-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: groq_chain-1.0.1.tar.gz
  • Upload date:
  • Size: 5.9 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.1.tar.gz
Algorithm Hash digest
SHA256 dc37e7e974be5d91fae6d0a6f0ea18d81f7cf256f20982786bae846b0e49de74
MD5 514bcf512a92daa17d4063c7497c03f2
BLAKE2b-256 8f8d898fd5c2762f0807758fefb6da975cbd8d365295cc806fdb4368415d33a8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: groq_chain-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.2 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 796a6c85836b57bbcdf72875f4ccd0ba3989e7636b2a127b5f7f0155c6039bda
MD5 6adae27fcdb707da29007c869a5cc168
BLAKE2b-256 a4bb8a7baefc97fa3134cdd1858e58ddd8fc9dc17ab8c5985db1b196b067d653

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