Text Completion 생성
Deprecated: Use the Messages API instead.
[레거시] Text Completion을 생성합니다.
Text Completions API는 레거시 API입니다. 앞으로는 Messages API를 사용하는 것을 권장합니다.
향후 모델 및 기능은 Text Completions와 호환되지 않습니다. Text Completions에서 Messages로 마이그레이션하는 방법은 마이그레이션 가이드를 참조하세요.
Parameters
params CompletionNewParams
MaxTokensToSample int64The maximum number of tokens to generate before stopping.
The maximum number of tokens to generate before stopping.
Note that our models may stop before reaching this maximum. This parameter only specifies the absolute maximum number of tokens to generate.
Prompt stringThe prompt that you want Claude to complete.
The prompt that you want Claude to complete.
For proper response generation you will need to format your prompt using alternating `
Human:and
Assistant:` conversational turns. For example:
"
Human: {userQuestion}
Assistant:"
See prompt validation and our guide to prompt design for more details.
An object describing metadata about the request.
StopSequences []string OptionalSequences that will cause the model to stop generating.
Sequences that will cause the model to stop generating.
Our models stop on `"
Human:"`, and may include additional built-in stop sequences in the future. By providing the stop_sequences parameter, you may include additional strings that will cause the model to stop generating.
WorkspaceID param.Opt[string] OptionalHeader parameterOptional header to select the Workspace for this request. The value is a Workspace ID (for example, wrkspc_011CZkZaBF1tNoB5wlCeusgy).
Optional header to select the Workspace for this request. The value is a Workspace ID (for example, wrkspc_011CZkZaBF1tNoB5wlCeusgy).
Only needed for credentials that can act on more than one Workspace. A credential that belongs to a specific Workspace may omit it; if sent, it must match that Workspace.
Temperature param.Opt[float64] OptionalDeprecatedAmount of randomness injected into the response.
Amount of randomness injected into the response.
Defaults to 1.0. Ranges from 0.0 to 1.0. Use temperature closer to 0.0 for analytical / multiple choice, and closer to 1.0 for creative and generative tasks.
Note that even with temperature of 0.0, the results will not be fully deterministic.
TopK param.Opt[int64] OptionalDeprecatedOnly sample from the top K options for each subsequent token.
Only sample from the top K options for each subsequent token.
Used to remove "long tail" low probability responses. Learn more technical details here.
Recommended for advanced use cases only.
TopP param.Opt[float64] OptionalDeprecatedUse nucleus sampling.
Use nucleus sampling.
In nucleus sampling, we compute the cumulative distribution over all the options for each subsequent token in decreasing probability order and cut it off once it reaches a particular probability specified by top_p.
Recommended for advanced use cases only.
Betas []AnthropicBeta OptionalHeader parameterDeprecatedOptional header to specify the beta version(s) you want to use.
Optional header to specify the beta version(s) you want to use.
Returns
type Completion struct { Type: "completion"; ID; Completion; /* 2 more */ }
Type CompletionObject type.
Object type.
For Text Completions, this is always "completion".
ID stringUnique object identifier.
Unique object identifier.
The format and length of IDs may change over time.
The resulting completion up to and excluding the stop sequences.
StopReason stringThe reason that we stopped.
The reason that we stopped.
This may be one the following values:
"stop_sequence": we reached a stop sequence — either provided by you via thestop_sequencesparameter, or a stop sequence built into the model"max_tokens": we exceededmax_tokens_to_sampleor the model's maximum
package main
import (
"context"
"fmt"
"github.com/anthropics/anthropic-sdk-go"
"github.com/anthropics/anthropic-sdk-go/option"
)
func main() {
client := anthropic.NewClient(
option.WithAPIKey("my-anthropic-api-key"),
)
completion, err := client.Completions.New(context.TODO(), anthropic.CompletionNewParams{
MaxTokensToSample: 256,
Model: anthropic.ModelClaudeHaiku5_5,
Prompt: "\n\nHuman: Hello, world!\n\nAssistant:",
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", completion.ID)
}{
"id": "compl_018CKm6gsux7P8yMcwZbeCPw",
"completion": " Hello! My name is Claude.",
"model": "claude-2.1",
"stop_reason": "stop_sequence",
"type": "completion"
}Returns Examples
{
"id": "compl_018CKm6gsux7P8yMcwZbeCPw",
"completion": " Hello! My name is Claude.",
"model": "claude-2.1",
"stop_reason": "stop_sequence",
"type": "completion"
}