brainlid / langchain

Elixir implementation of an AI focused LangChain style framework.
https://hexdocs.pm/langchain/
Other
574 stars 68 forks source link

refactor(chat_open_ai): Harden `do_process_response` #21

Closed Cardosaum closed 11 months ago

Cardosaum commented 11 months ago

This should fix #20.

brainlid commented 11 months ago

Nice! Good catch too. I haven't encountered that one yet, but I knew it was a possibility.

Can you change the returned message of "Failed to parse response from API" to something more like: "Received invalid JSON"?

The reason is, when we get bad JSON in a function call from the ChatGPT, we can just return the following example text to as the function response to ChatGPT.

"ERROR: Received invalid JSON"

Then ChatGPT will may try again with better formatted JSON. Optionally, we could include more of the error message so ChatGPT has a better chance of fixing the problem.

Cardosaum commented 11 months ago

Oh, I see... Thanks for the additional context!

I have updated the error message as per your suggestion. Now it reads "Received invalid JSON: %Jason.DecodeError{...}".

Is there any other improvement or change you'd like to have implemented?

brainlid commented 11 months ago

❤️💛💙💜