建立文字補全
POST/v1/complete
Deprecated: Use the Messages API instead.
[舊版] 建立文字補全。
Text Completions API 是舊版 API。我們建議日後改用 Messages API。
未來的模型與功能將不相容於 Text Completions。請參閱我們的遷移指南,以瞭解從 Text Completions 遷移至 Messages 的指引。
Parameters
Returns
建立文字補全
package com.anthropic.example;
import com.anthropic.client.AnthropicClient;
import com.anthropic.client.okhttp.AnthropicOkHttpClient;
import com.anthropic.models.completions.Completion;
import com.anthropic.models.completions.CompletionCreateParams;
import com.anthropic.models.messages.Model;
public final class Main {
private Main() {}
public static void main(String[] args) {
AnthropicClient client = AnthropicOkHttpClient.fromEnv();
CompletionCreateParams params = CompletionCreateParams.builder()
.maxTokensToSample(256L)
.model(Model.CLAUDE_HAIKU_5_5)
.prompt("\n\nHuman: Hello, world!\n\nAssistant:")
.build();
Completion completion = client.completions().create(params);
}
}Response 200
{
"id": "compl_018CKm6gsux7P8yMcwZbeCPw",
"completion": " Hello! My name is Claude.",
"model": "claude-2.1",
"stop_reason": "stop_sequence",
"type": "completion"
}Returns Examples
Response 200
{
"id": "compl_018CKm6gsux7P8yMcwZbeCPw",
"completion": " Hello! My name is Claude.",
"model": "claude-2.1",
"stop_reason": "stop_sequence",
"type": "completion"
}