Find answers from the community

Updated 6 months ago

I am having issues retrieving certain

I am having issues retrieving certain fields defined in my pydantic base model output class

class APIRequest(BaseModel):
"""Data model for API Requests"""
request_type: str
base_url: str
endpoint: str
path_parameters: Optional[Dict[str, str]]
query_parameters: Optional[Dict[str, str]]
body: Optional[dict]
headers: Optional[dict]
full_path: str

llm = OpenAI(model="gpt-3.5-turbo", temperature=0.1)
from llama_index.core import Document, VectorStoreIndex

text = """
{
"Apple Stock Price Request": {
"request_type": "GET",
"base_url": "https://api.polygon.io",
"endpoint": "/v2/last/trade/AAPL",
"query_parameters": {
"apiKey": "<insertApiKey>"
},
"path_parameters": {},
"body": {},
"headers": {},
"full_path": "https://api.polygon.io/v2/last/trade/AAPL?apiKey=<insertApiKey>"
}
}
"""

text_list = [text]
documents = [Document(text=t) for t in text_list]
index = VectorStoreIndex.from_documents(documents)

query_engine = index.as_query_engine(
output_cls=APIRequest, response_mode="compact", llm=llm
)

response = query_engine.query("API Call Body")

print(response)

{"request_type": "GET", "base_url": "https://api.polygon.io", "endpoint": "/v2/last/trade/AAPL", "path_parameters": null, "query_parameters": null, "body": null, "headers": null, "full_path": "https://api.polygon.io/v2/last/trade/AAPL?apiKey=<insertApiKey>"}

can someone help with an explanation to why the query_parameters and path_parameters are returning null despite defining them.
L
1 comment
You left them as optional (which in my experience, usually causes the LLM to just skip them)

You can try and improve this by adding descriptions for fields, or marking them as non-optional

Plain Text
class APIRequest(BaseModel):
  request_type: str = Field(description="<some description>)
  ....
Add a reply
Sign up and join the conversation on Discord