Class: GAI18n::OpenAI::Run

Inherits:
Object
  • Object
show all
Defined in:
lib/gai18n/openai/run.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Run

Returns a new instance of Run.



25
26
27
# File 'lib/gai18n/openai/run.rb', line 25

def initialize(response)
  set_attributes_from(response)
end

Instance Attribute Details

#assistant_idObject

Returns the value of attribute assistant_id.



20
21
22
# File 'lib/gai18n/openai/run.rb', line 20

def assistant_id
  @assistant_id
end

#cancelled_atObject

Returns the value of attribute cancelled_at.



20
21
22
# File 'lib/gai18n/openai/run.rb', line 20

def cancelled_at
  @cancelled_at
end

#completed_atObject

Returns the value of attribute completed_at.



20
21
22
# File 'lib/gai18n/openai/run.rb', line 20

def completed_at
  @completed_at
end

#created_atObject

Returns the value of attribute created_at.



20
21
22
# File 'lib/gai18n/openai/run.rb', line 20

def created_at
  @created_at
end

#expires_atObject

Returns the value of attribute expires_at.



20
21
22
# File 'lib/gai18n/openai/run.rb', line 20

def expires_at
  @expires_at
end

#failed_atObject

Returns the value of attribute failed_at.



20
21
22
# File 'lib/gai18n/openai/run.rb', line 20

def failed_at
  @failed_at
end

#file_idsObject

Returns the value of attribute file_ids.



20
21
22
# File 'lib/gai18n/openai/run.rb', line 20

def file_ids
  @file_ids
end

#idObject

Returns the value of attribute id.



20
21
22
# File 'lib/gai18n/openai/run.rb', line 20

def id
  @id
end

#instructionsObject

Returns the value of attribute instructions.



20
21
22
# File 'lib/gai18n/openai/run.rb', line 20

def instructions
  @instructions
end

#last_errorObject

Returns the value of attribute last_error.



20
21
22
# File 'lib/gai18n/openai/run.rb', line 20

def last_error
  @last_error
end

#metadataObject

Returns the value of attribute metadata.



20
21
22
# File 'lib/gai18n/openai/run.rb', line 20

def 
  @metadata
end

#modelObject

Returns the value of attribute model.



20
21
22
# File 'lib/gai18n/openai/run.rb', line 20

def model
  @model
end

#objectObject

Returns the value of attribute object.



20
21
22
# File 'lib/gai18n/openai/run.rb', line 20

def object
  @object
end

#started_atObject

Returns the value of attribute started_at.



20
21
22
# File 'lib/gai18n/openai/run.rb', line 20

def started_at
  @started_at
end

#statusObject

Returns the value of attribute status.



20
21
22
# File 'lib/gai18n/openai/run.rb', line 20

def status
  @status
end

#thread_idObject

Returns the value of attribute thread_id.



20
21
22
# File 'lib/gai18n/openai/run.rb', line 20

def thread_id
  @thread_id
end

#tool_callsObject

Returns the value of attribute tool_calls.



20
21
22
# File 'lib/gai18n/openai/run.rb', line 20

def tool_calls
  @tool_calls
end

#toolsObject

Returns the value of attribute tools.



20
21
22
# File 'lib/gai18n/openai/run.rb', line 20

def tools
  @tools
end

Class Method Details

.create(assistant_id:, thread_id:) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/gai18n/openai/run.rb', line 5

def create(assistant_id:, thread_id:)
  openai_client = GAI18n.config.openai_client
  parameters = {assistant_id: assistant_id}
  response = openai_client.runs.create thread_id: thread_id,
                                       parameters: parameters
  new response
end

.find(thread_id:, id:) ⇒ Object



13
14
15
16
17
# File 'lib/gai18n/openai/run.rb', line 13

def find(thread_id:, id:)
  openai_client = GAI18n.config.openai_client
  response = openai_client.runs.retrieve thread_id: thread_id, id: id
  new response
end

Instance Method Details

#accept_translationsObject



49
50
51
52
# File 'lib/gai18n/openai/run.rb', line 49

def accept_translations
  submit_tool_outputs
  submit_translations
end

#cancelled?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/gai18n/openai/run.rb', line 41

def cancelled?
  status == 'cancelled'
end

#completed?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/gai18n/openai/run.rb', line 29

def completed?
  status == 'completed'
end

#expired?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/gai18n/openai/run.rb', line 45

def expired?
  status == 'expired'
end

#failed?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/gai18n/openai/run.rb', line 37

def failed?
  status == 'failed'
end

#reloadObject



54
55
56
57
58
# File 'lib/gai18n/openai/run.rb', line 54

def reload
  openai_client = GAI18n.config.openai_client
  response = openai_client.runs.retrieve thread_id: thread_id, id: id
  set_attributes_from response
end

#requires_action?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/gai18n/openai/run.rb', line 33

def requires_action?
  status == 'requires_action'
end

#wait_until_done(count = 0) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/gai18n/openai/run.rb', line 60

def wait_until_done(count = 0)
  return self if count > 10
  reload
  halt_statuses = %w[requires_action completed failed cancelled expired]
  return self if halt_statuses.include? status
  sleep 5
  wait_until_done count + 1
end