-
Notifications
You must be signed in to change notification settings - Fork 1.1k
docs(sample-app): add Groq getting started guide for beginners #4469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
priyanshiranawat15
wants to merge
4
commits into
traceloop:main
Choose a base branch
from
priyanshiranawat15:docs/sample-app-groq-readme
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
87c230e
docs(sample-app): add Groq getting started guide for beginners
priyanshiranawat15 74a7e29
fix(sample-app): address CodeRabbit review feedback
priyanshiranawat15 3a33571
docs(sample-app): add step-by-step Groq guide with terminal screenshots
priyanshiranawat15 8e07048
docs(sample-app): add dedicated joke output screenshot to README
priyanshiranawat15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,140 @@ | ||
| # sample-app | ||
| # Sample App | ||
|
|
||
| Project description here. | ||
| Runnable examples for tracing LLM applications with [OpenLLMetry](https://github.com/traceloop/openllmetry). | ||
|
|
||
| This guide walks you through the **Groq** example — a good starting point because Groq offers a free API tier and responses are fast. | ||
|
|
||
| ## What you'll learn | ||
|
|
||
| Running `groq_example.py` shows how OpenLLMetry: | ||
|
|
||
| 1. Initializes tracing with `Traceloop.init()` | ||
| 2. Groups your code into a **workflow** and **task** using decorators | ||
| 3. Automatically records the Groq LLM call as an OpenTelemetry span | ||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Python 3.10–3.12 (see `.python-version`) | ||
| - [Node.js](https://nodejs.org/) (for monorepo commands) | ||
| - [uv](https://docs.astral.sh/uv/) (Python package manager used by this repo) | ||
| - A free [Groq API key](https://console.groq.com/keys) | ||
|
|
||
| ## Setup | ||
|
|
||
| ### 1. Install dependencies | ||
|
|
||
| From the **repository root**: | ||
|
|
||
| ```bash | ||
| npm ci | ||
| npx nx run sample-app:install | ||
| ``` | ||
|
|
||
| ### 2. Configure your API key | ||
|
|
||
| ```bash | ||
| cd packages/sample-app | ||
| cp .env.example .env | ||
| ``` | ||
|
|
||
| Edit `.env` and set your Groq key: | ||
|
|
||
| ```bash | ||
| GROQ_API_KEY=gsk-your-key-here | ||
| ``` | ||
|
|
||
| Load the environment variables before running the example: | ||
|
|
||
| ```bash | ||
| export $(grep -v '^#' .env | xargs) | ||
| ``` | ||
|
|
||
| ## Run the Groq example | ||
|
|
||
| ```bash | ||
| cd packages/sample-app | ||
| uv run python sample_app/groq_example.py | ||
| ``` | ||
|
|
||
| ### Expected output | ||
|
|
||
| You should see: | ||
|
|
||
| 1. **Trace JSON** printed to your terminal (spans for the workflow, task, and Groq chat call) | ||
| 2. **A joke** about OpenTelemetry printed at the end | ||
|
|
||
| Example trace hierarchy: | ||
|
|
||
| ``` | ||
| joke_generator.workflow ← top-level workflow | ||
| └── generate_joke.task ← your task function | ||
| └── chat llama-3.3-70b-versatile ← automatic Groq instrumentation | ||
| ``` | ||
|
|
||
| Each span includes metadata such as the model name, token usage, and the prompt/response (when content tracing is enabled). | ||
|
|
||
| ## How the example works | ||
|
|
||
| ```python | ||
| from traceloop.sdk import Traceloop | ||
| from traceloop.sdk.decorators import task, workflow | ||
|
|
||
| Traceloop.init(app_name="groq_example", disable_batch=True) | ||
|
|
||
| @task(name="generate_joke") | ||
| def generate_joke(): | ||
| # Groq call is traced automatically | ||
| ... | ||
|
|
||
| @workflow(name="joke_generator") | ||
| def joke_generator(): | ||
| generate_joke() | ||
| ``` | ||
|
|
||
| See [`sample_app/groq_example.py`](./sample_app/groq_example.py) for the full script. | ||
|
|
||
| ## Exporting traces (optional) | ||
|
|
||
| By default, traces print to your terminal via `ConsoleSpanExporter`. | ||
|
|
||
| To send traces to the [Traceloop cloud](https://app.traceloop.com) instead, set in `.env`: | ||
|
|
||
| ```bash | ||
| TRACELOOP_API_KEY=your-traceloop-api-key | ||
| ``` | ||
|
|
||
| See the [getting started guide](https://traceloop.com/docs/openllmetry/getting-started-python) for other backends (Datadog, Grafana, etc.). | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| | Problem | Fix | | ||
| |---------|-----| | ||
| | `Missing Traceloop API key` | Ignore if traces still print to terminal, or set `TRACELOOP_API_KEY` | | ||
| | `GROQ_API_KEY` not set | Export the variable: `export GROQ_API_KEY=gsk-...` | | ||
| | Model not found (404) | Check [Groq models docs](https://console.groq.com/docs/models) and update `MODEL` in `groq_example.py` | | ||
| | `proxies` TypeError from Groq | Known `groq`/`httpx` version mismatch — run with `uv run --with 'groq>=0.18' python sample_app/groq_example.py` | | ||
|
|
||
| ## More examples | ||
|
|
||
| Browse [`sample_app/`](./sample_app/) for other providers and frameworks: | ||
|
|
||
| | Category | Examples | | ||
| |----------|----------| | ||
| | LLM providers | `openai_streaming.py`, `anthropic_joke_example.py`, `cohere_example.py` | | ||
| | Local models | `ollama_streaming.py` | | ||
| | Frameworks | `langchain_app.py`, `langgraph_example.py`, `crewai_example.py` | | ||
| | Vector DBs | `chroma_app.py`, `pinecone_app.py`, `qdrant_app.py` | | ||
|
|
||
| ## Development commands | ||
|
|
||
| From the repository root: | ||
|
|
||
| ```bash | ||
| npx nx run sample-app:lint | ||
| npx nx run sample-app:test | ||
| ``` | ||
|
|
||
| ## Contributing | ||
|
|
||
| - [Contributing guide](https://traceloop.com/docs/openllmetry/contributing/overview) | ||
| - [Slack community](https://traceloop.com/slack) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.