Class: GAI18n::OpenAI::Assistant

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Assistant

Returns a new instance of Assistant.



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/gai18n/openai/assistant.rb', line 58

def initialize(response)
  @id = response['id']
  @object = response['object']
  @created_at = response['created_at']
  @name = response['name']
  @description = response['description']
  @model = response['model']
  @instructions = response['instructions']
  @tools = response['tools']
  @file_ids = response['file_ids']
  @metadata = response['metadata']
end

Instance Attribute Details

#created_atObject (readonly)

Returns the value of attribute created_at.



55
56
57
# File 'lib/gai18n/openai/assistant.rb', line 55

def created_at
  @created_at
end

#descriptionObject (readonly)

Returns the value of attribute description.



55
56
57
# File 'lib/gai18n/openai/assistant.rb', line 55

def description
  @description
end

#file_idsObject (readonly)

Returns the value of attribute file_ids.



55
56
57
# File 'lib/gai18n/openai/assistant.rb', line 55

def file_ids
  @file_ids
end

#idObject (readonly)

Returns the value of attribute id.



55
56
57
# File 'lib/gai18n/openai/assistant.rb', line 55

def id
  @id
end

#instructionsObject (readonly)

Returns the value of attribute instructions.



55
56
57
# File 'lib/gai18n/openai/assistant.rb', line 55

def instructions
  @instructions
end

#metadataObject (readonly)

Returns the value of attribute metadata.



55
56
57
# File 'lib/gai18n/openai/assistant.rb', line 55

def 
  @metadata
end

#modelObject (readonly)

Returns the value of attribute model.



55
56
57
# File 'lib/gai18n/openai/assistant.rb', line 55

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



55
56
57
# File 'lib/gai18n/openai/assistant.rb', line 55

def name
  @name
end

#objectObject (readonly)

Returns the value of attribute object.



55
56
57
# File 'lib/gai18n/openai/assistant.rb', line 55

def object
  @object
end

#toolsObject (readonly)

Returns the value of attribute tools.



55
56
57
# File 'lib/gai18n/openai/assistant.rb', line 55

def tools
  @tools
end

Class Method Details

.createObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gai18n/openai/assistant.rb', line 5

def create
  description = ['This assisistant was created by GAI18n',
                'to help with internationalization.'].join ' '
  instructions = "You are a software localization engineer. You have been tasked with translating the English source to the target language. You will be given a key and a source string. You will be asked to translate the source string to the target language. Once translated, please call the translation.submit function with the key, translated string, and the target language. If you are asked to translate into multiple target languages, please call the translation.submit function for each target language."
  openai_client = GAI18n.config.openai_client
  model = GAI18n.config.model
  parameters = {
    model: model,
    name: "GAI18n-#{Time.now.to_i}",
    description: description,
    instructions: instructions,
    tools: [
      {
        type: "function",
        function: {
          name: "translation.submit",
          description: "Submit a translation",
          parameters: {
            type: "object",
            properties: {
              key: {
                type: "string",
                description: "The given key that's associated to the string needing translation."
              },
              translation: {
                type: "string",
                description: "The translated string."
              },
              language: {
                type: "string",
                description: "The language of the translation."
              }
            },
            required: ["key", "translation", "language"]
          }
        }
      }
    ]
  }
  response = openai_client.assistants.create parameters: parameters
  new response
end

.find(id) ⇒ Object



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

def find(id)
  openai_client = GAI18n.config.openai_client
  response = openai_client.assistants.retrieve id: id
  new response
end