run-llama / llama-hub

A library of data loaders for LLMs made by the community -- to be used with LlamaIndex and/or LangChain
https://llamahub.ai/
MIT License
3.44k stars 731 forks source link

[Bug]: OpenAIPydanticProgram method failed (KeyError: 'description' missing) #830

Closed FaresKi closed 8 months ago

FaresKi commented 8 months ago

Bug Description

While following the OpenAIPydanticProgram tutorial here, I've ran into KeyError('description') errors. After some extra investigation, it turns out that the problem is in the to_openai_tool method:

def to_openai_tool(pydantic_class: Type[BaseModel]) -> Dict[str, Any]:
    """Convert pydantic class to OpenAI tool."""
    schema = pydantic_class.schema()
    function = {
        "name": schema["title"],
        "description": schema["description"],
        "parameters": pydantic_class.schema(),
    }
    return {"type": "function", "function": function}

The Pydantic schema that's passed down from OpenAIPydanticProgram's from_defaults method doesn't contain the description property and current documentation doesn't describe how to pass it. I've also noticed that the type for BaseModel is Pydantic's v1 and not the latest Pydantic, so maybe the issue is located there?

Version

0.9.15.post2

Steps to Reproduce

Try the demo provided in the documentation. You should run into the same problem.

Relevant Logs/Tracbacks

No response

FaresKi commented 8 months ago

Wrong repo. Will be posting this issue in run-llama/llama-index