Class: OpenaiAssistant::Assistant::Create

Inherits:
Base
  • Object
show all
Defined in:
lib/openai_assistant/clients/assistant/create.rb

Overview

An openai assistant

Instance Method Summary collapse

Methods inherited from Base

#default_headers, #initialize

Constructor Details

This class inherits a constructor from OpenaiAssistant::Base

Instance Method Details

#create_assistant(model, instructions) ⇒ OpenaiAssistant::Mapper::Assistant

Returns A new response object of assistant.

Parameters:

Returns:



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/openai_assistant/clients/assistant/create.rb', line 10

def create_assistant(model, instructions)
  url = URI.parse(@openai_url)
  req_body = {
    "instructions": instructions,
    "name": "assistant",
    "tools": [{ "type": "code_interpreter" }],
    "model": model
  }.to_json
  response = @http_client.call_post(url, req_body, default_headers)
  return OpenaiAssistant::ErrorResponse.from_json(response.body) unless response.code == "200"

  OpenaiAssistant::Mapper::Assistant.from_json(JSON.parse(response.body))
end