Find answers from the community

L
Lak
Offline, last seen 3 months ago
Joined September 25, 2024
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.
1 comment
L