Closed JavaFXpert closed 1 year ago
yeah it happens when the output its returns is super long...
How would you have me handle it in an app? Something like, "I don't know the answer", or rather "You have discovered a bug in the application"?
I'm having this issue too. I'd like to extend the APIChain for other use cases but I can't guarantee that the API response will fit in the response prompt context window.
My first idea is that If I could set the answer chain in an APIChain object to a sequential chain, I could add a text truncation based on tokens. The LLMChain already has all the properties I'd need to calculate where to truncate the prompt (response from the API as part of the response prompt template). I would need to log or message the user that some of the prompt is getting tossed out.
The second idea is to integrate a summary prompt chain but I don't have a good feel of how to design the prompts that would work with a JSON object response that probably has a bunch of data in it. (Some kind of rle or other data compression might work but I've never seen that.) Anyway, having some kind of general memory offload into a list of documents directly out of an llm call would be very powerful. Being able to sequence a refine or reduce prompt chain on an API response while caching everything into a vector database would be ideal.
Should we add something to check the size of the response ?
I wonder if it would be beneficial to pass a JSON object to langchain.chains.summarize
, how can a JSON object be summerized ... . What could be the best solution for very large API responses ?
api_response = self.requests_wrapper.run(api_url)
self.callback_manager.on_text(
api_response, color="yellow", end="\n", verbose=self.verbose
)
# check API response size
answer = self.api_answer_chain.predict(
question=question,
api_docs=self.api_docs,
api_url=api_url,
api_response=api_response,
)
Hi, @JavaFXpert! I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.
From what I understand, you opened this issue regarding the 'open-meteo-api' tool and the error that occurs when the output exceeds the maximum context length of the model. It seems that other users have confirmed this error when the output is too long. Some possible solutions have been suggested, such as truncating the prompt or integrating a summary prompt chain.
Before we close this issue, we wanted to check if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself or it will be automatically closed in 7 days.
Thank you for your contribution!
I occasionally get this error when using the 'open-meteo-api' tool: openai.error.InvalidRequestError: This model's maximum context length is 4097 tokens, however you requested 6536 tokens (6280 in your prompt; 256 for the completion). Please reduce your prompt; or completion length.