-
-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Langchain::LLM::Base#chat()
accepts a new response_schema:
parameter to force the response to adhere to JSON schema
#593
base: main
Are you sure you want to change the base?
Conversation
Langchain::LLM::Base#chat()
accepts a new response_schema:
parameter to force the response to adhere to JSON schema
This is good and it is a move in the right direction but there are some key points that are missing:
There are other more advanced features like streaming and threading or Ruby fibers so that you can process calls in parallel (different from parallel function calling) etc that I want to add Instructor-rb. Those scaling features are the money makers and the reason why Instructor has been successful. |
# @return [Hash] JSON schema structured response | ||
def response_schema | ||
if tool_calls | ||
JSON.parse(tool_calls.first.dig("function", "arguments")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you have a module called Langchain::LLM::OpenAIResponse
you should use it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens when the LLM sends back an array of objects?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't work with parallel function-calling right now if that's what you're asking.
|
QQ. Yesterday I learnt at RubyDay of a recent Data class (since 3.2) for immutable hashes (https://www.shakacode.com/blog/ruby-3-2-adds-a-new-data-class/). This seems like a perfect fit - not much for the json_schema but to force the result to fit into a Data which you might construct based on the [ I say this because I'm using it to accept different Gemini responses (good vs error response) by forcing it into two wlel-known, different schema. ] |
@palladius I was thinking of returning a simple hash so that the user could do whatever they want with it? |
This PR introduces a new parameter
response_schema:
to the LLMchat()
methods that, using Function Calling, forces the response to adhere to a specific schema. Example usage: