Module: Instructor

Defined in:
lib/instructor.rb,
lib/instructor/mode.rb,
lib/instructor/version.rb,
lib/instructor/openai/patch.rb,
lib/instructor/openai/response.rb

Overview

The Instructor module provides functionality for interacting with OpenAI’s chat API.

Defined Under Namespace

Modules: Mode, OpenAI Classes: Error, ValidationError

Constant Summary collapse

VERSION =
'0.1.3'

Class Method Summary collapse

Class Method Details

.modeObject



21
22
23
# File 'lib/instructor.rb', line 21

def self.mode
  @mode
end

.patch(openai_client, mode: Instructor::Mode::TOOLS.function) ⇒ OpenAI::Client

Patches the OpenAI client to add the following functionality:

  • Retries on exceptions

  • Accepts and validates a response model

  • Accepts a validation_context argument

Parameters:

  • openai_client (OpenAI::Client)

    The OpenAI client to be patched.

  • mode (Symbol) (defaults to: Instructor::Mode::TOOLS.function)

    The mode to be used. Default is ‘Instructor::Mode::TOOLS.function`.

Returns:

  • (OpenAI::Client)

    The patched OpenAI client.



33
34
35
36
# File 'lib/instructor.rb', line 33

def self.patch(openai_client, mode: Instructor::Mode::TOOLS.function)
  @mode = mode
  openai_client.prepend(Instructor::OpenAI::Patch)
end