-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stainless Bot
committed
Aug 29, 2024
1 parent
e1e2237
commit bdf3f36
Showing
3 changed files
with
484 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,140 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "2722b419", | ||
"metadata": {}, | ||
"source": [ | ||
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/openlayer-ai/openlayer-python/blob/main/examples/tracing/groq/groq_tracing.ipynb)\n", | ||
"\n", | ||
"\n", | ||
"# <a id=\"top\">Groq tracing</a>\n", | ||
"\n", | ||
"This notebook illustrates how to trace Groq LLM calls with Openlayer." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "020c8f6a", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!pip install groq openlayer" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "75c2a473", | ||
"metadata": {}, | ||
"source": [ | ||
"## 1. Set the environment variables" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "f3f4fa13", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"\n", | ||
"# Groq env variables\n", | ||
"os.environ[\"GROQ_API_KEY\"] = \"YOUR_GROQ_API_KEY_HERE\"\n", | ||
"\n", | ||
"# Openlayer env variables\n", | ||
"os.environ[\"OPENLAYER_API_KEY\"] = \"YOUR_OPENLAYER_API_KEY_HERE\"\n", | ||
"os.environ[\"OPENLAYER_INFERENCE_PIPELINE_ID\"] = \"YOUR_OPENLAYER_INFERENCE_PIPELINE_ID_HERE\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "9758533f", | ||
"metadata": {}, | ||
"source": [ | ||
"## 2. Import the `trace_groq` function" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "c35d9860-dc41-4f7c-8d69-cc2ac7e5e485", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import groq\n", | ||
"from openlayer.lib import trace_groq\n", | ||
"\n", | ||
"groq_client = trace_groq(groq.Groq())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "72a6b954", | ||
"metadata": {}, | ||
"source": [ | ||
"## 3. Use the traced Groq client normally" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "76a350b4", | ||
"metadata": {}, | ||
"source": [ | ||
"That's it! Now you can continue using the traced Groq client normally. The data is automatically published to Openlayer and you can start creating tests around it!" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "e00c1c79", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"chat_completion = groq_client.chat.completions.create(\n", | ||
" messages=[\n", | ||
" {\n", | ||
" \"role\": \"system\",\n", | ||
" \"content\": \"You are a helpful assistant.\"\n", | ||
" },\n", | ||
" {\n", | ||
" \"role\": \"user\",\n", | ||
" \"content\": \"Explain the importance of fast language models\",\n", | ||
" }\n", | ||
" ],\n", | ||
" model=\"llama3-8b-8192\",\n", | ||
")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "bd2cd65d-1b22-4f5d-b5cb-7700e036b863", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.19" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains 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
Oops, something went wrong.