Creates a completion for the provided prompt and parameters.
Parameters
Returns
Create completion
package main
import (
"context"
"fmt"
"github.com/openai/openai-go"
"github.com/openai/openai-go/option"
)
func main() {
client := openai.NewClient(
option.WithAPIKey("My API Key"),
)
completion, err := client.Completions.New(context.TODO(), openai.CompletionNewParams{
Model: openai.CompletionNewParamsModelGPT3_5TurboInstruct,
Prompt: openai.CompletionNewParamsPromptUnion{
OfString: openai.String("This is a test."),
},
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", completion)
}
{
"id": "id",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"logprobs": {
"text_offset": [
0
],
"token_logprobs": [
0
],
"tokens": [
"string"
],
"top_logprobs": [
{
"foo": 0
}
]
},
"text": "text"
}
],
"created": 0,
"model": "model",
"object": "text_completion",
"system_fingerprint": "system_fingerprint",
"usage": {
"completion_tokens": 0,
"prompt_tokens": 0,
"total_tokens": 0,
"completion_tokens_details": {
"accepted_prediction_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 0,
"rejected_prediction_tokens": 0
},
"prompt_tokens_details": {
"audio_tokens": 0,
"cached_tokens": 0
}
}
}Returns Examples
{
"id": "id",
"choices": [
{
"finish_reason": "stop",
"index": 0,
"logprobs": {
"text_offset": [
0
],
"token_logprobs": [
0
],
"tokens": [
"string"
],
"top_logprobs": [
{
"foo": 0
}
]
},
"text": "text"
}
],
"created": 0,
"model": "model",
"object": "text_completion",
"system_fingerprint": "system_fingerprint",
"usage": {
"completion_tokens": 0,
"prompt_tokens": 0,
"total_tokens": 0,
"completion_tokens_details": {
"accepted_prediction_tokens": 0,
"audio_tokens": 0,
"reasoning_tokens": 0,
"rejected_prediction_tokens": 0
},
"prompt_tokens_details": {
"audio_tokens": 0,
"cached_tokens": 0
}
}
}