Class: Rubygpt::Requester::ChatRequester

Inherits:
BaseRequester show all
Defined in:
lib/rubygpt/requester/chat_requester.rb

Overview

Performs CRUD operations for OpenAI Chat Completion Objects platform.openai.com/docs/api-reference/chat

Instance Attribute Summary

Attributes inherited from BaseRequester

#api_endpoint, #client

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ ChatRequester

Initializes the ChatRequester

Parameters:

  • client (Client)

    The client object



11
12
13
14
# File 'lib/rubygpt/requester/chat_requester.rb', line 11

def initialize(client)
  @api_endpoint = "chat/completions"
  super(client)
end

Instance Method Details

#create(args = {}) ⇒ Response::ChatCompletion

Performs a POST request to the API endpoint platform.openai.com/docs/api-reference/chat/create

Parameters:

  • args (String) (defaults to: {})

    The single message to send. Message will be sent with system role

  • args (Array) (defaults to: {})

    The array of messages to send. Each message can be a string or a hash

  • args (Hash) (defaults to: {})

    The arguments for the request body, including messages

Options Hash (args):

  • :messages (Array)

    The messages to send

Returns:



25
26
27
28
# File 'lib/rubygpt/requester/chat_requester.rb', line 25

def create(args = {})
  # TODO: handle args[:stream] for streaming completions
  Response::ChatCompletion.new client.post(api_endpoint, create_request_body(args))
end