alexrudall / anthropic Goto Github PK
View Code? Open in Web Editor NEWAnthropic (Claude) API + Ruby! 🤖🌌
License: MIT License
Anthropic (Claude) API + Ruby! 🤖🌌
License: MIT License
Is your feature request related to a problem? Please describe.
Building the payload for messages it's prone to errors and it gets more complex when you need to add images. I was thinking if a layer that handle that for you would be useful for this library or it's something that it should be left to other projects such as boxcars.
Describe the solution you'd like
Abstraction layers that handle building a messages array for the payload.
Describe alternatives you've considered
A class that handles the building of the message's payload, something a Anthropic::MessagesBuilder, that it would build the payload according to what is required (User message without previous messages, chat history, user message with an image or multiple images, etc.)
A class for Messages (it could be Anthropic::Message with attributes ´role´ (´user´ or ´assistant´) and ´content´. Content can be text or image.
It could also be a small gem just for this one. I'm also wondering if it would be just okay use other gems such boxcars or lanchainrb, or it would be a nice addition to this gem.
Additional context
Add any other context or screenshots about the feature request here.
As I tested the new streaming functionality, I found that when the parameters are not quite right it semi-silently fails:
3.3.0 :044 > params
=>
{:model=>"claude-3-haiku-20240307",
:temperature=>0.9,
:max_tokens=>4096,
:messages=>
[{:role=>"user",
:content=>
"Some kind of preamble that doesn't have arguments.\n\nSample Script Contents 1\n\nAnother section yay\n\nSample Script Contents 1 and Input Item in Special Instruction\n\nThis section has a lot of lines\nIt is here to test the lines.\n\nLet's have some more text:\n\nThis will prevent RuboCop from checking the Sample Script Contents 2 syntax style throughout your entire codebase. Make sure to place this under the correct hierarchy in your .rubocop.yml file, typically at the root level or under a specific target if you have Sample Script Contents 1 configurations for different parts of your project."}],
:stream=>true,
:preprocess_stream=>:text}
3.3.0 :045 > @client.messages(parameters:params)
=> {"type"=>"error", "error"=>{"type"=>"invalid_request_error", "message"=>"preprocess_stream: Extra inputs are not permitted"}}
I wonder if these kinds of errors (invalid requests in particular) should actually result in an Anthropic::Error
being raised.
I can add this code if you think it makes sense.
Since the complete endpoint is now depricated and Anthropic is recommending migrating to messages, are there any plans to add support for the new messages endpoint?
Line 154 in http.rb on env
is nil
on valid requests. This causes merge
to error on line 157
return unless env&.status != 200
Example:
response = anthropic_client.messages(
parameters: {
temperature: 0.7,
model: model,
messages: message_data
max_tokens: 100,
preprocess_stream: :text,
stream: proc do |incremental_response, delta|
next if delta.blank?
Rails.logger.info "Incremental response: #{incremental_response}"
Rails.logger.info "Delta: #{delta}"
end
})
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.