Skip to content

Latest commit

 

History

History
180 lines (122 loc) · 6.28 KB

File metadata and controls

180 lines (122 loc) · 6.28 KB
page_title openai_chat_completion Resource - terraform-provider-openai
subcategory
description Generates a model response for the given chat conversation.

openai_chat_completion (Resource)

Generates a model response for the given chat conversation.

Example Usage

resource "openai_chat_completion" "example" {
  model = "gpt-4o-mini"

  messages {
    role    = "system"
    content = "You are a helpful assistant."
  }

  messages {
    role    = "user"
    content = "Hello! What's the weather like today?"
  }

  temperature = 0.7
  max_tokens  = 150
}

output "chat_response" {
  value = openai_chat_completion.example.choices[0].message[0].content
}

Schema

Required

  • messages (Attributes List) A list of messages comprising the conversation so far. (see below for nested schema)
  • model (String) ID of the model to use for the chat completion.

Optional

  • _imported_resource (String) Internal field to prevent recreation of imported resources.
  • frequency_penalty (Number) Frequency penalty parameter.
  • function_call (String, Deprecated) Deprecated. Controls how the model responds to function calls.
  • functions (Attributes List, Deprecated) Deprecated. A list of functions the model may generate JSON inputs for. (see below for nested schema)
  • imported (Boolean) Whether this resource was imported from an existing chat completion.
  • logit_bias (Map of Number) Modify the likelihood of specified tokens appearing in the completion.
  • max_tokens (Number, Deprecated) The maximum number of tokens to generate in the chat completion.
  • metadata (Map of String) A map of key-value pairs that can be used to filter chat completions.
  • n (Number) How many chat completion choices to generate for each input message.
  • presence_penalty (Number) Presence penalty parameter.
  • project_id (String) The project to use for this request.
  • stop (List of String) Up to 4 sequences where the API will stop generating further tokens.
  • store (Boolean) Whether to store the chat completion for later retrieval via API.
  • stream (Boolean) Whether to stream back partial progress.
  • temperature (Number) What sampling temperature to use, between 0 and 2.
  • tool_choice (String) Controls which (if any) tool is called by the model.
  • tools (Attributes List) A list of tools the model may call. Currently, only functions are supported as a tool. (see below for nested schema)
  • top_p (Number) Nucleus sampling parameter.
  • user (String, Deprecated) A unique identifier representing your end-user.

Read-Only

  • chat_completion_id (String) The ID of the chat completion.
  • choices (Attributes List) The list of chat completion choices the model generated. (see below for nested schema)
  • created (Number) The Unix timestamp (in seconds) of when the chat completion was created.
  • id (String) The ID of this resource.
  • model_used (String) The model used for the chat completion.
  • object (String) The object type, which is always 'chat.completion'.
  • usage (Map of Number) Usage statistics for the chat completion request.

Nested Schema for messages

Required:

  • content (String) The content of the message.
  • role (String) The role of the message author. One of 'system', 'user', 'assistant', or 'function'.

Optional:

  • function_call (Attributes List, Deprecated) Deprecated. The name and arguments of a function that should be called, as generated by the model. (see below for nested schema)
  • name (String) The name of the author of this message. Required if role is 'function'.
  • tool_calls (Attributes List) The tool calls generated by the model, such as function calls. (see below for nested schema)

Nested Schema for messages.function_call

Required:

  • arguments (String) The arguments to call the function with, as a JSON string.
  • name (String) The name of the function to call.

Nested Schema for messages.tool_calls

Read-Only:

  • function (Attributes List) The function that the model called. (see below for nested schema)
  • id (String) The ID of the tool call.
  • type (String) The type of the tool. Currently, only 'function' is supported.

Nested Schema for messages.tool_calls.function

Read-Only:

  • arguments (String) The arguments to call the function with, as a JSON string.
  • name (String) The name of the function to call.

Nested Schema for functions

Required:

  • name (String) The name of the function.
  • parameters (String) The parameters the function accepts, described as a JSON Schema object.

Optional:

  • description (String) A description of what the function does.

Nested Schema for tools

Required:

  • function (Attributes List) Function definition for the tool. (see below for nested schema)
  • type (String) The type of the tool. Currently, only 'function' is supported.

Nested Schema for tools.function

Required:

  • name (String) The name of the function.
  • parameters (String) The parameters the function accepts, described as a JSON Schema object.

Optional:

  • description (String) A description of what the function does.

Nested Schema for choices

Read-Only:

Nested Schema for choices.message

Read-Only:

Nested Schema for choices.message.function_call

Read-Only:

  • arguments (String)
  • name (String)