Skip to content

[feature] Support OpenAI client attribute extraction by patching client #1554

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
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

spike-spiegel-21
Copy link
Contributor

@spike-spiegel-21 spike-spiegel-21 commented May 2, 2025

Please have a look at this PR before merging: #1551

This enables tracing LlmAttributes for OpenAI client by patching it in Observer.

Example:

client = OpenAI(api_key="<your-openai-api-key>")

@observe(model="gpt-4o-mini", type="llm", llm_provider="openai", client=client)
def generate_response(input: str) -> str:
    response = client.chat.completions.create(
        model="gpt-4o-mini", 
        messages=[
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": input},
        ],
        temperature=0.7,
        tools=tools,
        tool_choice="auto"
    )
    return response

Note: Sample test in test_open_client_trace.py.

Copy link

vercel bot commented May 2, 2025

@spike-spiegel-21 is attempting to deploy a commit to the Confident AI Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant