-
Notifications
You must be signed in to change notification settings - Fork 2
[OPEN-7543] Update OpenAI Wrapper to support Responses API #539
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
viniciusdsmello
wants to merge
7
commits into
main
Choose a base branch
from
cursor/update-openai-tracing-for-responses-api-58e5
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 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
82f5365
feat(closes OPEN-7543): update trace openai to support responses api
viniciusdsmello f020976
refactor: improve OpenAI responses API tracing in notebook example
viniciusdsmello 96986a4
fix: update OpenAI responses API tracing example to accumulate respon…
viniciusdsmello d3bb18e
refactor: streamline OpenAI responses API tracing example in notebook
viniciusdsmello 4857ace
refactor: enhance input extraction for OpenAI responses API to suppor…
viniciusdsmello b79dd9b
chore: remove OpenAI responses API tracing notebook and merge its con…
viniciusdsmello 22c83a5
fix: correct import order in OpenAI tracing notebook
viniciusdsmello 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
There are no files selected for viewing
147 changes: 147 additions & 0 deletions
147
examples/tracing/openai/openai_responses_api_tracing.ipynb
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 |
|---|---|---|
| @@ -0,0 +1,147 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "2722b419", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "[](https://colab.research.google.com/github/openlayer-ai/openlayer-python/blob/main/examples/tracing/openai/openai_responses_api_tracing.ipynb)\n", | ||
| "\n", | ||
| "\n", | ||
| "# <a id=\"top\">OpenAI Responses API monitoring with Openlayer</a>\n", | ||
| "\n", | ||
| "This notebook shows how to monitor both OpenAI's Chat Completions API and the new Responses API with Openlayer. The same `trace_openai()` function supports both APIs seamlessly." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "020c8f6a", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "!pip install openlayer openai" | ||
| ] | ||
| }, | ||
| { | ||
| "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", | ||
| "import openai\n", | ||
| "\n", | ||
| "# OpenAI API key\n", | ||
| "os.environ[\"OPENAI_API_KEY\"] = \"YOUR_OPENAI_API_KEY_HERE\"\n", | ||
| "\n", | ||
| "# Openlayer configuration\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. Create traced OpenAI client" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "c35d9860-dc41-4f7c-8d69-cc2ac7e5e485", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "from openlayer.lib import trace_openai\n", | ||
| "\n", | ||
| "# Single function traces both Chat Completions AND Responses APIs\n", | ||
| "client = trace_openai(openai.OpenAI())" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "72a6b954", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## 3. Use Chat Completions API (existing functionality)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "e00c1c79", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Chat Completions API - works exactly as before\n", | ||
| "response = client.chat.completions.create(\n", | ||
| " model=\"gpt-4o-mini\",\n", | ||
| " messages=[{\"role\": \"user\", \"content\": \"What is 2 + 2?\"}],\n", | ||
| " max_tokens=50\n", | ||
| ")\n", | ||
| "\n", | ||
| "response.choices[0].message.content" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "76a350b4", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "## 4. Use Responses API (new unified interface)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "responses-api-example", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Responses API - new unified interface with enhanced metadata\n", | ||
| "response = client.responses.create(\n", | ||
| " model=\"gpt-4o-mini\",\n", | ||
| " input=\"What is 3 + 3?\",\n", | ||
| " max_output_tokens=50\n", | ||
| ")\n", | ||
| "\n", | ||
| "# Response is automatically traced\n", | ||
| "response" | ||
| ] | ||
| } | ||
| ], | ||
| "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.18" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 5 | ||
| } | ||
Oops, something went wrong.
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.