|  | 
|  | 1 | +{ | 
|  | 2 | + "cells": [ | 
|  | 3 | + { | 
|  | 4 | + "cell_type": "markdown", | 
|  | 5 | + "id": "2722b419", | 
|  | 6 | + "metadata": {}, | 
|  | 7 | + "source": [ | 
|  | 8 | + "[](https://colab.research.google.com/github/openlayer-ai/openlayer-python/blob/main/examples/tracing/groq/groq_tracing.ipynb)\n", | 
|  | 9 | + "\n", | 
|  | 10 | + "\n", | 
|  | 11 | + "# <a id=\"top\">Groq tracing</a>\n", | 
|  | 12 | + "\n", | 
|  | 13 | + "This notebook illustrates how to trace Groq LLM calls with Openlayer." | 
|  | 14 | + ] | 
|  | 15 | + }, | 
|  | 16 | + { | 
|  | 17 | + "cell_type": "code", | 
|  | 18 | + "execution_count": null, | 
|  | 19 | + "id": "020c8f6a", | 
|  | 20 | + "metadata": {}, | 
|  | 21 | + "outputs": [], | 
|  | 22 | + "source": [ | 
|  | 23 | + "!pip install groq openlayer" | 
|  | 24 | + ] | 
|  | 25 | + }, | 
|  | 26 | + { | 
|  | 27 | + "cell_type": "markdown", | 
|  | 28 | + "id": "75c2a473", | 
|  | 29 | + "metadata": {}, | 
|  | 30 | + "source": [ | 
|  | 31 | + "## 1. Set the environment variables" | 
|  | 32 | + ] | 
|  | 33 | + }, | 
|  | 34 | + { | 
|  | 35 | + "cell_type": "code", | 
|  | 36 | + "execution_count": null, | 
|  | 37 | + "id": "f3f4fa13", | 
|  | 38 | + "metadata": {}, | 
|  | 39 | + "outputs": [], | 
|  | 40 | + "source": [ | 
|  | 41 | + "import os\n", | 
|  | 42 | + "\n", | 
|  | 43 | + "# Groq env variables\n", | 
|  | 44 | + "os.environ[\"GROQ_API_KEY\"] = \"YOUR_GROQ_API_KEY_HERE\"\n", | 
|  | 45 | + "\n", | 
|  | 46 | + "# Openlayer env variables\n", | 
|  | 47 | + "os.environ[\"OPENLAYER_API_KEY\"] = \"YOUR_OPENLAYER_API_KEY_HERE\"\n", | 
|  | 48 | + "os.environ[\"OPENLAYER_INFERENCE_PIPELINE_ID\"] = \"YOUR_OPENLAYER_INFERENCE_PIPELINE_ID_HERE\"" | 
|  | 49 | + ] | 
|  | 50 | + }, | 
|  | 51 | + { | 
|  | 52 | + "cell_type": "markdown", | 
|  | 53 | + "id": "9758533f", | 
|  | 54 | + "metadata": {}, | 
|  | 55 | + "source": [ | 
|  | 56 | + "## 2. Import the `trace_groq` function" | 
|  | 57 | + ] | 
|  | 58 | + }, | 
|  | 59 | + { | 
|  | 60 | + "cell_type": "code", | 
|  | 61 | + "execution_count": null, | 
|  | 62 | + "id": "c35d9860-dc41-4f7c-8d69-cc2ac7e5e485", | 
|  | 63 | + "metadata": {}, | 
|  | 64 | + "outputs": [], | 
|  | 65 | + "source": [ | 
|  | 66 | + "import groq\n", | 
|  | 67 | + "from openlayer.lib import trace_groq\n", | 
|  | 68 | + "\n", | 
|  | 69 | + "groq_client = trace_groq(groq.Groq())" | 
|  | 70 | + ] | 
|  | 71 | + }, | 
|  | 72 | + { | 
|  | 73 | + "cell_type": "markdown", | 
|  | 74 | + "id": "72a6b954", | 
|  | 75 | + "metadata": {}, | 
|  | 76 | + "source": [ | 
|  | 77 | + "## 3. Use the traced Groq client normally" | 
|  | 78 | + ] | 
|  | 79 | + }, | 
|  | 80 | + { | 
|  | 81 | + "cell_type": "markdown", | 
|  | 82 | + "id": "76a350b4", | 
|  | 83 | + "metadata": {}, | 
|  | 84 | + "source": [ | 
|  | 85 | + "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!" | 
|  | 86 | + ] | 
|  | 87 | + }, | 
|  | 88 | + { | 
|  | 89 | + "cell_type": "code", | 
|  | 90 | + "execution_count": null, | 
|  | 91 | + "id": "e00c1c79", | 
|  | 92 | + "metadata": {}, | 
|  | 93 | + "outputs": [], | 
|  | 94 | + "source": [ | 
|  | 95 | + "chat_completion = groq_client.chat.completions.create(\n", | 
|  | 96 | + " messages=[\n", | 
|  | 97 | + " {\n", | 
|  | 98 | + " \"role\": \"system\",\n", | 
|  | 99 | + " \"content\": \"You are a helpful assistant.\"\n", | 
|  | 100 | + " },\n", | 
|  | 101 | + " {\n", | 
|  | 102 | + " \"role\": \"user\",\n", | 
|  | 103 | + " \"content\": \"Explain the importance of fast language models\",\n", | 
|  | 104 | + " }\n", | 
|  | 105 | + " ],\n", | 
|  | 106 | + " model=\"llama3-8b-8192\",\n", | 
|  | 107 | + ")" | 
|  | 108 | + ] | 
|  | 109 | + }, | 
|  | 110 | + { | 
|  | 111 | + "cell_type": "code", | 
|  | 112 | + "execution_count": null, | 
|  | 113 | + "id": "bd2cd65d-1b22-4f5d-b5cb-7700e036b863", | 
|  | 114 | + "metadata": {}, | 
|  | 115 | + "outputs": [], | 
|  | 116 | + "source": [] | 
|  | 117 | + } | 
|  | 118 | + ], | 
|  | 119 | + "metadata": { | 
|  | 120 | + "kernelspec": { | 
|  | 121 | + "display_name": "Python 3 (ipykernel)", | 
|  | 122 | + "language": "python", | 
|  | 123 | + "name": "python3" | 
|  | 124 | + }, | 
|  | 125 | + "language_info": { | 
|  | 126 | + "codemirror_mode": { | 
|  | 127 | + "name": "ipython", | 
|  | 128 | + "version": 3 | 
|  | 129 | + }, | 
|  | 130 | + "file_extension": ".py", | 
|  | 131 | + "mimetype": "text/x-python", | 
|  | 132 | + "name": "python", | 
|  | 133 | + "nbconvert_exporter": "python", | 
|  | 134 | + "pygments_lexer": "ipython3", | 
|  | 135 | + "version": "3.9.19" | 
|  | 136 | + } | 
|  | 137 | + }, | 
|  | 138 | + "nbformat": 4, | 
|  | 139 | + "nbformat_minor": 5 | 
|  | 140 | +} | 
0 commit comments