From 6aef401f66a7fce4d714ba5c9104d3a62fff3a14 Mon Sep 17 00:00:00 2001 From: Pratyush Shukla Date: Tue, 10 Dec 2024 19:05:06 +0530 Subject: [PATCH 1/4] add grok examples --- examples/xai_examples/grok_examples.ipynb | 238 ++++++++++++++++++++++ 1 file changed, 238 insertions(+) create mode 100755 examples/xai_examples/grok_examples.ipynb diff --git a/examples/xai_examples/grok_examples.ipynb b/examples/xai_examples/grok_examples.ipynb new file mode 100755 index 000000000..9aea7f894 --- /dev/null +++ b/examples/xai_examples/grok_examples.ipynb @@ -0,0 +1,238 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# XAI Examples\n", + "This notebook demonstrates how to use XAI with AgentOps via the OpenAI python client. \n", + "\n", + "We are going to use the latest Grok model from XAI to create a transliteration chatbot that can understand the major languages of the world and translate them to a user's native language! We will use AgentOps to track the chatbot's performance." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "First let's install the required packages" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%pip install -U openai\n", + "%pip install -U agentops" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Then import them" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from openai import OpenAI\n", + "import agentops\n", + "import os\n", + "from dotenv import load_dotenv" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Next, we'll grab our API keys. You can use dotenv like below or however else you like to load environment variables" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "load_dotenv()\n", + "XAI_API_KEY = os.getenv(\"XAI_API_KEY\") or \"\"\n", + "AGENTOPS_API_KEY = os.getenv(\"AGENTOPS_API_KEY\") or \"\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Next we initialize the AgentOps client." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "agentops.init(AGENTOPS_API_KEY, default_tags=[\"xai-example\", \"grok\"])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "And we are all set! Note the seesion url above. We will use it to track the chatbot.\n", + "\n", + "Let's initialize the OpenAI client with the XAI API key and base url." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "client = OpenAI(\n", + " api_key=XAI_API_KEY,\n", + " base_url=\"https://api.x.ai/v1\",\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now we will set the system and instruction prompts for the chatbot. We will set the native language to Spanish and the user prompt to transliterate an excerpt from Haruki Murakami's \"Kafka On The Shore\"." + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "SYSTEM_PROMPT = \"\"\"\n", + "You are a highly intelligent, multilingual assistant designed to understand user prompts in English and respond in the user's specified native language. \n", + "Your key responsibilities include:\n", + "1. Translating and generating meaningful, contextually appropriate responses in the user's native language.\n", + "2. Ensuring the output is accurate, coherent, and in Unicode format for proper display in the specified language.\n", + "3. Adhering to the nuances of the specified language's grammar, tone, and cultural context.\n", + "\n", + "When asked to respond in a language, generate the response entirely in that language without using English unless explicitly requested.\n", + "\n", + "If the specified language is unfamiliar or ambiguous, politely ask for clarification in English.\n", + "\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "native_language = \"Spanish\"\n", + "\n", + "USER_PROMPT = \"\"\"\n", + "Sometimes fate is like a small sandstorm that keeps changing directions. You change direction but the sandstorm chases you. \n", + "You turn again, but the storm adjusts. Over and over you play this out, like some ominous dance with death just before dawn. Why? \n", + "Because this storm isn’t something that blew in from far away, something that has nothing to do with you. This storm is you. \n", + "Something inside of you. So all you can do is give in to it, step right inside the storm, closing your eyes and plugging up your ears so the sand doesn’t get in, and walk through it, step by step. \n", + "There’s no sun there, no moon, no direction, no sense of time. Just fine white sand swirling up into the sky like pulverized bones. \n", + "That’s the kind of sandstorm you need to imagine.\n", + "\n", + "And you really will have to make it through that violent, metaphysical, symbolic storm. \n", + "No matter how metaphysical or symbolic it might be, make no mistake about it: it will cut through flesh like a thousand razor blades. People will bleed there, and you will bleed too. \n", + "Hot, red blood. You’ll catch that blood in your hands, your own blood and the blood of others.\n", + "\n", + "And once the storm is over you won’t remember how you made it through, how you managed to survive. You won’t even be sure, in fact, whether the storm is really over. \n", + "But one thing is certain. When you come out of the storm you won’t be the same person who walked in. That’s what this storm’s all about.\n", + "\"\"\"\n", + "\n", + "INSTRUCTION_PROMPT = f\"\"\"\n", + "You are a multilingual chatbot. Take the user's prompt: \"{USER_PROMPT}\" and respond naturally in {native_language}. \n", + "Ensure that the response is in Unicode characters appropriate for {native_language}.\n", + "\"\"\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now we will use the OpenAI client to generate the response by passing in the system and instruction prompts." + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "response = client.chat.completions.create(\n", + " model=\"grok-beta\",\n", + " messages=[\n", + " {\"role\": \"system\", \"content\": SYSTEM_PROMPT},\n", + " {\"role\": \"user\", \"content\": INSTRUCTION_PROMPT}\n", + " ],\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(f\"Original Response:\\n{USER_PROMPT}\")\n", + "generated_response = response.choices[0].message.content\n", + "print(f\"Response in {native_language}:\\n{generated_response}\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Awesome! We can now transliterate from English to any language! And all of this can be tracked with AgentOps by going to the session url above." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "agentops.end_session(\"Success\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We end the session with a success state and a success reason. This is useful if you want to track the success or failure of the chatbot. In that case you can set the end state to failure and provide a reason. By default the session will have an indeterminate end state." + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "ops", + "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.10.15" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 0ca89838cb86e7b57826eafe81e80d023cd734c7 Mon Sep 17 00:00:00 2001 From: Pratyush Shukla Date: Tue, 10 Dec 2024 19:06:37 +0530 Subject: [PATCH 2/4] add grok vision example --- .../xai_examples/grok_vision_examples.ipynb | 209 ++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100755 examples/xai_examples/grok_vision_examples.ipynb diff --git a/examples/xai_examples/grok_vision_examples.ipynb b/examples/xai_examples/grok_vision_examples.ipynb new file mode 100755 index 000000000..dda0e0539 --- /dev/null +++ b/examples/xai_examples/grok_vision_examples.ipynb @@ -0,0 +1,209 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# XAI Vision Examples\n", + "This notebook demonstrates how to use XAI with AgentOps via the OpenAI python client. \n", + "\n", + "We are going to use the latest Grok model from XAI to create a program that will capture the text in an image and explain it. We will use AgentOps to track the program's performance." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "First let's install the required packages" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "%pip install -U openai\n", + "%pip install -U agentops" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Then import them" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "from openai import OpenAI\n", + "import agentops\n", + "import os\n", + "from dotenv import load_dotenv" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Next, we'll grab our API keys. You can use dotenv like below or however else you like to load environment variables" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "load_dotenv()\n", + "XAI_API_KEY = os.getenv(\"XAI_API_KEY\") or \"\"\n", + "AGENTOPS_API_KEY = os.getenv(\"AGENTOPS_DEV_API_KEY\") or \"\"" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Next we initialize the AgentOps client." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "agentops.init(AGENTOPS_API_KEY, default_tags=[\"xai-example\", \"grok-vision\",])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "And we are all set! Note the seesion url above. We will use it to track the program's performance.\n", + "\n", + "Let's initialize the OpenAI client with the XAI API key and base url." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "client = OpenAI(\n", + " api_key=XAI_API_KEY,\n", + " base_url=\"https://api.x.ai/v1\",\n", + ")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Next we will set the system and instruction prompts for the program." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "SYSTEM_PROMPT = \"\"\"You are an expert image analysis assistant. When presented with an image, carefully examine and describe its contents in detail. \n", + "\n", + "For this task, your goal is to:\n", + "1. Identify all key elements, objects, people, or text in the image\n", + "2. Provide a comprehensive description of what you observe\n", + "3. Explain the context or historical significance if applicable\n", + "4. Describe the image in a clear, objective, and informative manner\n", + "\n", + "Please be precise, thorough, and focus on providing meaningful insights about the visual content.\"\"\"\n", + "\n", + "USER_PROMPT = [\n", + " {\n", + " \"type\": \"text\",\n", + " \"text\": \"Analyze the image and provide a detailed description of what you see.\"\n", + " },\n", + " {\n", + " \"type\": \"image_url\",\n", + " \"image_url\": {\"url\": \"https://upload.wikimedia.org/wikipedia/commons/f/ff/First_Computer_Bug%2C_1945.jpg\"}\n", + " }\n", + "]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now we will use the OpenAI client to process the image and generate a response." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "response = client.chat.completions.create(\n", + " model=\"grok-vision-beta\",\n", + " messages=[\n", + " {\"role\": \"system\", \"content\": SYSTEM_PROMPT},\n", + " {\"role\": \"user\", \"content\": USER_PROMPT}\n", + " ],\n", + " max_tokens=4096,\n", + ")\n", + "\n", + "print(response.choices[0].message.content)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Awesome! It returns a fascinating response explaining the image and also deciphering the text content. All of this can be tracked with AgentOps by going to the session url above." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "agentops.end_session(\"Success\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We end the session with a success state and a success reason. This is useful if you want to track the success or failure of the chatbot. In that case you can set the end state to failure and provide a reason. By default the session will have an indeterminate end state." + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "ops", + "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.10.15" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From ff6c7c7709dc7324a80880ab2db1bd5f26572e18 Mon Sep 17 00:00:00 2001 From: Pratyush Shukla Date: Thu, 12 Dec 2024 01:12:09 +0530 Subject: [PATCH 3/4] add xai docs --- docs/images/external/xai/xai-logo.png | Bin 0 -> 12570 bytes docs/mint.json | 3 +- docs/v1/examples/examples.mdx | 3 + docs/v1/integrations/xai.mdx | 122 ++++++++++++++++++++++++++ 4 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 docs/images/external/xai/xai-logo.png create mode 100644 docs/v1/integrations/xai.mdx diff --git a/docs/images/external/xai/xai-logo.png b/docs/images/external/xai/xai-logo.png new file mode 100644 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%pR{Sh%_- z6<x!MMyO#Q9xc><6F`ID-bxa~#b{#k1r_YSi zDHG?K1aEkyL|N>A%|H1V!F+$xO;@=`ZXZCX4FP+P2Ant^;HvH7=L-K}+tj!HrJ}w= zMSbhxts2_f)U~(nR908lR#%T3y(|6yyx>haankL~|Nn*W&lJHPlz D0FY4f literal 0 HcmV?d00001 diff --git a/docs/mint.json b/docs/mint.json index ea3cc2684..55c7246e4 100644 --- a/docs/mint.json +++ b/docs/mint.json @@ -100,7 +100,8 @@ "v1/integrations/multion", "v1/integrations/ollama", "v1/integrations/openai", - "v1/integrations/rest" + "v1/integrations/rest", + "v1/integrations/xai" ] }, { diff --git a/docs/v1/examples/examples.mdx b/docs/v1/examples/examples.mdx index c148e6728..468a2643d 100644 --- a/docs/v1/examples/examples.mdx +++ b/docs/v1/examples/examples.mdx @@ -63,6 +63,9 @@ mode: "wide" Create a REST server that performs and observes agent tasks + } iconType="image" href="/v1/integrations/xai"> + Observe the power of Grok and Grok Vision with AgentOps + ## Video Guides diff --git a/docs/v1/integrations/xai.mdx b/docs/v1/integrations/xai.mdx new file mode 100644 index 000000000..da1f93de6 --- /dev/null +++ b/docs/v1/integrations/xai.mdx @@ -0,0 +1,122 @@ +--- +title: xAI +description: "Observe the power of Grok and Grok Vision with AgentOps" +--- + +import CodeTooltip from '/snippets/add-code-tooltip.mdx' +import EnvTooltip from '/snippets/add-env-tooltip.mdx' + +[xAI](https://x.ai) develops the Grok and Grok Vision models. Explore their developer docs [here](https://docs.x.ai/docs). + + + + + ```bash pip + pip install agentops + ``` + ```bash poetry + poetry add agentops + ``` + + + + + You can use either OpenAI or Anthropic to use the xAI models. + + + ```bash pip + pip install openai + ``` + ```bash poetry + poetry add openai + ``` + + + ```bash pip + pip install anthropic + ``` + ```bash poetry + poetry add anthropic + ``` + + + + + + ```python python + import agentops + + agentops.init() + + # Your code here... + + agentops.end_session("Success") + ``` + + + + ```python .env + AGENTOPS_API_KEY= + ``` + + Read more about environment variables in [Advanced Configuration](/v1/usage/advanced-configuration) + + + Execute your program and visit [app.agentops.ai/drilldown](https://app.agentops.ai/drilldown) to observe your XAI analysis! 🔍 + + AgentOps automatically tracks your XAI metrics and visualizations in the Dashboard + + + + +## Full Examples + + +```python openai +from openai import OpenAI + +XAI_API_KEY = "you xai api key" +client = OpenAI( + api_key=XAI_API_KEY, + base_url="https://api.x.ai/v1", +) + +completion = client.chat.completions.create( + model="grok-beta", + messages=[ + {"role": "system", "content": "You are Grok, a chatbot inspired by the Hitchhikers Guide to the Galaxy."}, + {"role": "user", "content": "What is the meaning of life, the universe, and everything?"}, + ], +) + +print(completion.choices[0].message) +``` + +```python anthropic +from anthropic import Anthropic + +XAI_API_KEY = "you xai api key" +client = Anthropic( + api_key=XAI_API_KEY, + base_url="https://api.x.ai", +) +message = client.messages.create( + model="grok-beta", + max_tokens=128, + system="You are Grok, a chatbot inspired by the Hitchhiker's Guide to the Galaxy.", + messages=[ + { + "role": "user", + "content": "What is the meaning of life, the universe, and everything?", + }, + ], +) +print(message.content) +``` + + + + + + + From d551cb4821d45d71756662932b70ce0a8c1eb432 Mon Sep 17 00:00:00 2001 From: Pratyush Shukla Date: Thu, 12 Dec 2024 01:24:47 +0530 Subject: [PATCH 4/4] add more content --- docs/v1/integrations/xai.mdx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/v1/integrations/xai.mdx b/docs/v1/integrations/xai.mdx index da1f93de6..472152726 100644 --- a/docs/v1/integrations/xai.mdx +++ b/docs/v1/integrations/xai.mdx @@ -21,8 +21,9 @@ import EnvTooltip from '/snippets/add-env-tooltip.mdx' - You can use either OpenAI or Anthropic to use the xAI models. + xAI models can be accessed via OpenAI or Anthropic clients. + To install the OpenAI client, run: ```bash pip pip install openai @@ -31,6 +32,7 @@ import EnvTooltip from '/snippets/add-env-tooltip.mdx' poetry add openai ``` + To install the Anthropic client, run: ```bash pip pip install anthropic