|
| 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/mlflow/mlflow_tracing.ipynb)\n", |
| 9 | + "\n", |
| 10 | + "\n", |
| 11 | + "# <a id=\"top\">MLflow quickstart</a>\n", |
| 12 | + "\n", |
| 13 | + "This notebook shows how to export traces captured by [MLflow](https://mlflow.org/docs/latest/tracing/integrations/) to Openlayer. The integration is done via the Openlayer's [OpenTelemetry endpoint](https://www.openlayer.com/docs/integrations/opentelemetry). For more information, refer to the [MLflow integration guide](https://www.openlayer.com/docs/integrations/mlflow)." |
| 14 | + ] |
| 15 | + }, |
| 16 | + { |
| 17 | + "cell_type": "code", |
| 18 | + "execution_count": null, |
| 19 | + "id": "020c8f6a", |
| 20 | + "metadata": {}, |
| 21 | + "outputs": [], |
| 22 | + "source": [ |
| 23 | + "!pip install openai mlflow" |
| 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": 1, |
| 37 | + "id": "f3f4fa13", |
| 38 | + "metadata": {}, |
| 39 | + "outputs": [], |
| 40 | + "source": [ |
| 41 | + "import os\n", |
| 42 | + "\n", |
| 43 | + "import openai\n", |
| 44 | + "\n", |
| 45 | + "os.environ[\"OPENAI_API_KEY\"] = \"YOUR_OPENAI_API_KEY_HERE\"\n", |
| 46 | + "\n", |
| 47 | + "os.environ[\"OTEL_EXPORTER_OTLP_TRACES_ENDPOINT\"] = \"https://api.openlayer.com/v1/otel/v1/traces\"\n", |
| 48 | + "os.environ[\"OTEL_EXPORTER_OTLP_TRACES_HEADERS\"] = \"Authorization=Bearer YOUR_OPENLAYER_API_KEY_HERE, x-bt-parent=pipeline_id:YOUR_OPENLAYER_PIPELINE_ID_HERE\"\n", |
| 49 | + "os.environ['OTEL_EXPORTER_OTLP_TRACES_PROTOCOL']= \"http/protobuf\"" |
| 50 | + ] |
| 51 | + }, |
| 52 | + { |
| 53 | + "cell_type": "markdown", |
| 54 | + "id": "9758533f", |
| 55 | + "metadata": {}, |
| 56 | + "source": [ |
| 57 | + "## 2. Initialize MLflow instrumentation" |
| 58 | + ] |
| 59 | + }, |
| 60 | + { |
| 61 | + "cell_type": "code", |
| 62 | + "execution_count": 2, |
| 63 | + "id": "c35d9860-dc41-4f7c-8d69-cc2ac7e5e485", |
| 64 | + "metadata": {}, |
| 65 | + "outputs": [], |
| 66 | + "source": [ |
| 67 | + "import mlflow\n", |
| 68 | + "\n", |
| 69 | + "mlflow.openai.autolog()" |
| 70 | + ] |
| 71 | + }, |
| 72 | + { |
| 73 | + "cell_type": "markdown", |
| 74 | + "id": "72a6b954", |
| 75 | + "metadata": {}, |
| 76 | + "source": [ |
| 77 | + "## 3. Use LLMs and workflows as usual\n", |
| 78 | + "\n", |
| 79 | + "That's it! Now you can continue using LLMs and workflows as usual.The trace data is automatically exported to Openlayer and you can start creating tests around it." |
| 80 | + ] |
| 81 | + }, |
| 82 | + { |
| 83 | + "cell_type": "code", |
| 84 | + "execution_count": 3, |
| 85 | + "id": "e00c1c79", |
| 86 | + "metadata": {}, |
| 87 | + "outputs": [], |
| 88 | + "source": [ |
| 89 | + "client = openai.OpenAI()" |
| 90 | + ] |
| 91 | + }, |
| 92 | + { |
| 93 | + "cell_type": "code", |
| 94 | + "execution_count": null, |
| 95 | + "id": "abaf6987-c257-4f0d-96e7-3739b24c7206", |
| 96 | + "metadata": {}, |
| 97 | + "outputs": [], |
| 98 | + "source": [ |
| 99 | + "client.chat.completions.create(\n", |
| 100 | + " model=\"gpt-4o-mini\", messages=[{\"role\": \"user\", \"content\": \"How are you doing today?\"}]\n", |
| 101 | + ")" |
| 102 | + ] |
| 103 | + } |
| 104 | + ], |
| 105 | + "metadata": { |
| 106 | + "kernelspec": { |
| 107 | + "display_name": "openlayer-assistant", |
| 108 | + "language": "python", |
| 109 | + "name": "python3" |
| 110 | + }, |
| 111 | + "language_info": { |
| 112 | + "codemirror_mode": { |
| 113 | + "name": "ipython", |
| 114 | + "version": 3 |
| 115 | + }, |
| 116 | + "file_extension": ".py", |
| 117 | + "mimetype": "text/x-python", |
| 118 | + "name": "python", |
| 119 | + "nbconvert_exporter": "python", |
| 120 | + "pygments_lexer": "ipython3", |
| 121 | + "version": "3.9.18" |
| 122 | + } |
| 123 | + }, |
| 124 | + "nbformat": 4, |
| 125 | + "nbformat_minor": 5 |
| 126 | +} |
0 commit comments