Class: Anthropic::Resources::Completions
- Inherits:
-
Object
- Object
- Anthropic::Resources::Completions
- Defined in:
- lib/anthropic/resources/completions.rb
Instance Method Summary collapse
-
#create(max_tokens_to_sample: , model: , prompt: , metadata: nil, stop_sequences: nil, temperature: nil, top_k: nil, top_p: nil, betas: nil, request_options: {}) ⇒ Anthropic::Models::Completion
See #create_streaming for streaming counterpart.
-
#create_streaming(max_tokens_to_sample: , model: , prompt: , metadata: nil, stop_sequences: nil, temperature: nil, top_k: nil, top_p: nil, betas: nil, request_options: {}) ⇒ Anthropic::Internal::Stream<Anthropic::Models::Completion>
See #create for non-streaming counterpart.
-
#initialize(client:) ⇒ Completions
constructor
private
A new instance of Completions.
Constructor Details
#initialize(client:) ⇒ Completions
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Completions.
127 128 129 |
# File 'lib/anthropic/resources/completions.rb', line 127 def initialize(client:) @client = client end |
Instance Method Details
#create(max_tokens_to_sample: , model: , prompt: , metadata: nil, stop_sequences: nil, temperature: nil, top_k: nil, top_p: nil, betas: nil, request_options: {}) ⇒ Anthropic::Models::Completion
See #create_streaming for streaming counterpart.
Some parameter documentations has been truncated, see Models::CompletionCreateParams for more details.
[Legacy] Create a Text Completion.
The Text Completions API is a legacy API. We recommend using the Messages API going forward.
Future models and features will not be compatible with Text Completions. See our migration guide for guidance in migrating from Text Completions to Messages.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/anthropic/resources/completions.rb', line 46 def create(params) parsed, = Anthropic::CompletionCreateParams.dump_request(params) if parsed[:stream] = "Please use `#create_streaming` for the streaming use case." raise ArgumentError.new() end header_params = {betas: "anthropic-beta"} @client.request( method: :post, path: "v1/complete", headers: parsed.slice(*header_params.keys).transform_keys(header_params), body: parsed.except(*header_params.keys), model: Anthropic::Completion, options: {timeout: 600, **} ) end |
#create_streaming(max_tokens_to_sample: , model: , prompt: , metadata: nil, stop_sequences: nil, temperature: nil, top_k: nil, top_p: nil, betas: nil, request_options: {}) ⇒ Anthropic::Internal::Stream<Anthropic::Models::Completion>
See #create for non-streaming counterpart.
Some parameter documentations has been truncated, see Models::CompletionCreateParams for more details.
[Legacy] Create a Text Completion.
The Text Completions API is a legacy API. We recommend using the Messages API going forward.
Future models and features will not be compatible with Text Completions. See our migration guide for guidance in migrating from Text Completions to Messages.
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/anthropic/resources/completions.rb', line 102 def create_streaming(params) parsed, = Anthropic::CompletionCreateParams.dump_request(params) unless parsed.fetch(:stream, true) = "Please use `#create` for the non-streaming use case." raise ArgumentError.new() end parsed.store(:stream, true) header_params = {betas: "anthropic-beta"} @client.request( method: :post, path: "v1/complete", headers: { "accept" => "text/event-stream", **parsed.slice(*header_params.keys) }.transform_keys(header_params), body: parsed.except(*header_params.keys), stream: Anthropic::Internal::Stream, model: Anthropic::Completion, options: {timeout: 600, **} ) end |