Skip to content

opentelemetry-instrumentation-openai-v2: crash with with_raw_response: 'LegacyAPIResponse' object has no attribute 'model' #4002

@beforeeight

Description

@beforeeight

Describe your environment

Package version: 2.2b0

What happened?

File: patch.py
Line: 397
set_span_attribute(
span, GenAIAttributes.GEN_AI_RESPONSE_MODEL, result.model
)

should add " if getattr(result, "model", None) " , cause sometime result has no attribute "model"

Steps to Reproduce

    client = openai.OpenAI()

    messages = [
        {
            "role": "user",
            "content": TEST_CHAT_INPUT,
        }
    ]

    raw_response = client.chat.completions.with_raw_response.create(model=TEST_CHAT_MODEL, messages=messages)
    chat_completion = raw_response.parse()
    assert chat_completion.choices[0].message.content

and stream

    client = openai.OpenAI()

    messages = [
        {
            "role": "user",
            "content": TEST_CHAT_INPUT,
        }
    ]

    raw_response = client.chat.completions.with_raw_response.create(
        model=TEST_CHAT_MODEL, messages=messages, stream=True
    )

    # Explicit parse of the raw response
    chat_completion = raw_response.parse()

    chunks = [chunk.choices[0].delta.content or "" for chunk in chat_completion if chunk.choices]
    assert "".join(chunks)

Expected Result

no crash

Actual Result

exception raised

Additional context

No response

Would you like to implement a fix?

Yes

Tip

React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggen-aiRelated to generative AI

    Type

    No type

    Projects

    Status

    New issues

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions