feat: support for claude
Done so far:
- [x] basic md_json mode support
- [x] basic text support
- [x] do_streaming_chat_completion/2 in anthropic.ex
- [x] to_openai_response/1 needs to be more robust
In progress:
- [ ] vision support
- [ ] tool mode for anthropic https://docs.anthropic.com/claude/docs/functions-external-tools#function-calling-format = handle formatting request and parsing response *
I am taking time off for week or so. Might not be actively able to actively contibute to this PR until 4 april.
Can review changes, comments. :)
https://github.com/brainlid/langchain/pull/86/files
Reference PR.
Sax parser for supporting claude native XML format.
https://github.com/qcam/saxy
Examples of using Sax parsing with Saxy (which I used recently), if that's useful!
- https://hexdocs.pm/saxy/getting-started-with-sax.html
- https://github.com/etalab/transport-site/pull/3836
Examples of using Sax parsing with Saxy (which I used recently), if that's useful!
- https://hexdocs.pm/saxy/getting-started-with-sax.html
- Premier script pour "résumer" un gros fichier NeTEx etalab/transport-site#3836
Super useful. Gem. 🌸🌸
Will continue working on this pr after holidays finish. :)
https://twitter.com/jxnlco/status/1773536962403533187
Maybe don't need to do XML stuff. Json mode has been reported to work reliably
{"anthropic-beta", "tools-2024-04-04"} this header is required to use tools now
The function to conform to openai structure should be:
# %{
# "content" => [
# %{
# "text" => "ACTUAL RESPONSE ",
# "type" => "text"
# }
# ],
# "id" => "msg_01W35ZRGGrPaL4fXqgB5fHDs",
# "model" => "claude-3-haiku-20240307",
# "role" => "assistant",
# "stop_reason" => "end_turn",
# "stop_sequence" => nil,
# "type" => "message",
# "usage" => %{"input_tokens" => 243, "output_tokens" => 132}
# }
defp to_openai_response(%{"content" => [%{"text" => text}]} = _params) do
%{
"choices" => [
%{
"message" => %{"content" => text}
}
]
}
end
Added PR but removed my fork so i could submit something else to main repo, but it's still here: https://github.com/TwistingTwists/instructor_ex/pull/1/files
Will work on it over the weekend. Thanks for this @noozo !
@cigrainger : Streaming response works.
Will add an example in a few minutes. Feel free to checkout this branch.
This might not be mergable, at the moment, because it includes lots of goodies from other branches as well. But it works.
Big thanks to @noozo , @thbar for the tips ! :)
Also, since I was testing Gemini as well, I rebased Andres Alejos 's work and put this in the same PR.
can remove this if needed.
almost done with #33
Gave it a try and got the following error:
** (MatchError) no match of right hand side value: {:error, :adapter_error, %{"error" => %{"message" => "tool_choice: Input tag 'function' found using 'type' does not match any of the expected tags: 'auto', 'any', 'tool'", "type" => "invalid_request_error"}, "type" => "error"}}
@cigrainger ,{:error, error} is always a tuple of two. Also updated the signature of the chat_completion function.
eagerly waiting for this 🎉
@frozencap : feel free to try it out today from git directly. Open to feedback.
{:instructor_ex, git: "https://github.com/TwistingTwists/instructor_ex/", branch: "claude_json"}
breaks with ecto 3.12
breaks with ecto 3.12
Thanks for reporting. will do it over weekend