feat(llm): support structured output in AnthropicLLM via response_format#530
feat(llm): support structured output in AnthropicLLM via response_format#530SAY-5 wants to merge 1 commit into
Conversation
NathalieCharbel
left a comment
There was a problem hiding this comment.
Thank you @SAY-5 for your contribution!
This looks really great. Apart from the non-blocking comments, I also suggest to:
- update the documentation to add an Anthropic sub-section along side VertexAI and OpenAI
- (Nice to have) update examples directory with an
anthropic_llm_structured_output.pyexample showing a simple example of how we can use SO with anthropic models), for consistency withvertexai_llm_structured_output.pyandopenai_llm_structured_output.py
|
|
||
| assert response.content == "plain response" | ||
| call_args = _as_mock(llm.client.messages.create).call_args[1] | ||
| assert "output_config" not in call_args |
There was a problem hiding this comment.
would be good to also mirror the checks on ["format"]["type"] from the async test below
| raise ImportError( | ||
| """Could not import Anthropic Python client. | ||
| Please install it with `pip install "neo4j-graphrag[anthropic]"`.""" | ||
| ) |
There was a problem hiding this comment.
we should also enable supports_structured_output flag (same as we do with OpenAILLM and VertexAILLM now that this interface supports structured output:
supports_structured_output: bool = True
|
@SAY-5 The PR is approved and we're excited to get it merged. As a friendly reminder, we still need the CLA signature before we can merge it. If you're short on time, we can take care of the remaining unblocking comments on our side. Thanks in advance for your help, and we'd appreciate a quick response from your end. |
Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
8b17a05 to
e74aaf0
Compare
Description
Closes #493.
AnthropicLLM.invoke/ainvokepreviously raisedNotImplementedErrorforresponse_format; this adds structured output support soAnthropicLLMworks alongsideOpenAILLMandVertexAILLM. A Pydantic model is converted to a JSON schema and a passthrough dict is also accepted, both forwarded as Anthropic'soutput_config; behavior is unchanged whenresponse_formatis omitted. The issue is labelledhelp wantedandgood first issueby the maintainers, and the request is "to add structured output support forAnthropicLLMalongsideOpenAILLMandVertexLLMproviders".Type of Change
Complexity
Complexity: Low
How Has This Been Tested?
Checklist
The following requirements should have been met (depending on the changes in the branch):