InstructorLite.Adapters.ChatCompletionsCompatible (instructor_lite v1.1.1)
View SourceAdapter for Chat Completions-compatible API endpoints, such as OpenAI or Grok.
This adapter uses structured outputs.
Params
params argument should be shaped as a Create chat completion request body.
Example
InstructorLite.instruct(%{
messages: [%{role: "user", content: "John is 25yo"}],
model: "gpt-4o-mini",
service_tier: "default"
},
response_model: %{name: :string, age: :integer},
adapter: InstructorLite.Adapters.ChatCompletionsCompatible,
adapter_context: [
api_key: Application.fetch_env!(:instructor_lite, :openai_key),
url: "https://api.openai.com/v1/chat/completions"
]
)
{:ok, %{name: "John", age: 25}}
Summary
Functions
Parse chat completion endpoint response in search of plain text output.
Updates params with prompt based on json_schema and notes.
Parse chat completion endpoint response.
Updates params with prompt for retrying a request.
Make request to API.
Functions
Parse chat completion endpoint response in search of plain text output.
Can return:
{:ok, text_output}on success.{:error, :refusal, reason}on refusal.{:error, :unexpected_response, response}if response is of unexpected shape.
Updates params with prompt based on json_schema and notes.
Also specifies default gpt-4o-mini model if not provided by a user.
Parse chat completion endpoint response.
Can return:
{:ok, parsed_json}on success.{:error, :refusal, reason}on refusal.{:error, :unexpected_response, response}if response is of unexpected shape.
Updates params with prompt for retrying a request.
Make request to API.
Options
:api_key(String.t/0) - Required. API key:http_client(atom/0) - Any module that followsReq.post/2interface The default value isReq.:http_options(keyword/0) - Options passed tohttp_client.post/2The default value is[receive_timeout: 60000].:url(String.t/0) - API endpoint to use for sending requests The default value is"https://api.openai.com/v1/chat/completions".