Skip to content

🐛 Bug Report: [LLama Index] Doesn't set the correct value for model and temperature when using StructuredLLM #3148

@Lap1n

Description

@Lap1n

Which component is this bug for?

LlamaIndex Instrumentation

📜 Description

The set_llm_chat_request_model_attributes function in LLama Index fails to access the correct fields for the model and temperature attributes when using StructuredLLM.

Specifically, it tries to access model_dict.model instead of model_dict.llm.model. The same issue occurs for the temperature field.

It is very likely that this issue also occurs with completions calls as well.

Below is the error log observed:

Invalid type NoneType for attribute 'gen_ai.request.model' value. Expected one of ['bool', 'str', 'bytes', 'int', 'float'] or a sequence of those types

👟 Reproduction steps

  1. Use a StructuredLLM instance.
  2. Run achat function
  3. Observe the error log indicating invalid NoneType for gen_ai.request.model
class Invoice(BaseModel):
    """A representation of information from an invoice."""

    invoice_id: str = Field(
        description="A unique identifier for this invoice, often a number"
    )
    date: datetime = Field(description="The date this invoice was created")
    line_items: list[LineItem] = Field(
        description="A list of all the items in this invoice"
    )

from llama_index.llms.openai import OpenAI

llm = OpenAI(model="gpt-4o")
sllm = llm.as_structured_llm(Invoice)
 messages = [
            ChatMessage(role="system", content="dummy prompt"),
            ChatMessage(role="user", content="dummy prompt"),
]

response = sllm.achat(messages)

👍 Expected behavior

The set_llm_chat_request_model_attributes function should correctly access the model and temperature fields from model_dict.llm.model and model_dict.llm.temperature (or equivalent), ensuring proper attribute values are set.

👎 Actual Behavior with Screenshots

The function incorrectly accesses model_dict.model and model_dict.temperature, resulting in a NoneType error for the model and temperature fields.

🤖 Python Version

3.12

📃 Provide any additional context for the Bug.

No response

👀 Have you spent some time to check if this bug has been raised before?

  • I checked and didn't find similar issue

Are you willing to submit PR?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions