Class: OmniAI::OpenAI::Assistant
- Inherits:
-
Object
- Object
- OmniAI::OpenAI::Assistant
- Defined in:
- lib/omniai/openai/assistant.rb
Overview
An OpenAI assistants implementation.
Constant Summary collapse
- HEADERS =
{ 'OpenAI-Beta': 'assistants=v2' }.freeze
Instance Attribute Summary collapse
- #deleted ⇒ Boolean?
- #description ⇒ String?
- #id ⇒ String?
- #instructions ⇒ String?
- #metadata ⇒ Hash
- #model ⇒ String?
- #name ⇒ String?
- #tools ⇒ Array<Hash>?
Class Method Summary collapse
- .all(limit: nil, client: Client.new) ⇒ Array<OmniAI::OpenAI::Assistant>
- .destroy!(id:, client: Client.new) ⇒ void
- .find(id:, client: Client.new) ⇒ OmniAI::OpenAI::Assistant
Instance Method Summary collapse
- #destroy! ⇒ OmniAI::OpenAI::Assistant
-
#initialize(client: Client.new, id: nil, name: nil, model: OmniAI::Chat::DEFAULT_MODEL, description: nil, instructions: nil, metadata: {}, tools: []) ⇒ Assistant
constructor
A new instance of Assistant.
- #inspect ⇒ String
- #save! ⇒ OmniAI::OpenAI::Assistant
Constructor Details
#initialize(client: Client.new, id: nil, name: nil, model: OmniAI::Chat::DEFAULT_MODEL, description: nil, instructions: nil, metadata: {}, tools: []) ⇒ Assistant
Returns a new instance of Assistant.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/omniai/openai/assistant.rb', line 48 def initialize( client: Client.new, id: nil, name: nil, model: OmniAI::Chat::DEFAULT_MODEL, description: nil, instructions: nil, metadata: {}, tools: [] ) @client = client @id = id @name = name @model = model @description = description @instructions = instructions @metadata = @tools = tools end |
Instance Attribute Details
#deleted ⇒ Boolean?
35 36 37 |
# File 'lib/omniai/openai/assistant.rb', line 35 def deleted @deleted end |
#description ⇒ String?
23 24 25 |
# File 'lib/omniai/openai/assistant.rb', line 23 def description @description end |
#id ⇒ String?
11 12 13 |
# File 'lib/omniai/openai/assistant.rb', line 11 def id @id end |
#instructions ⇒ String?
27 28 29 |
# File 'lib/omniai/openai/assistant.rb', line 27 def instructions @instructions end |
#metadata ⇒ Hash
31 32 33 |
# File 'lib/omniai/openai/assistant.rb', line 31 def @metadata end |
#model ⇒ String?
19 20 21 |
# File 'lib/omniai/openai/assistant.rb', line 19 def model @model end |
#name ⇒ String?
15 16 17 |
# File 'lib/omniai/openai/assistant.rb', line 15 def name @name end |
#tools ⇒ Array<Hash>?
39 40 41 |
# File 'lib/omniai/openai/assistant.rb', line 39 def tools @tools end |
Class Method Details
.all(limit: nil, client: Client.new) ⇒ Array<OmniAI::OpenAI::Assistant>
90 91 92 93 94 95 96 97 98 99 |
# File 'lib/omniai/openai/assistant.rb', line 90 def self.all(limit: nil, client: Client.new) response = client.connection .accept(:json) .headers(HEADERS) .get("/#{OmniAI::OpenAI::Client::VERSION}/assistants", params: { limit: }.compact) raise HTTPError, response.flush unless response.status.ok? response.parse['data'].map { |data| parse(data:, client:) } end |
.destroy!(id:, client: Client.new) ⇒ void
This method returns an undefined value.
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/omniai/openai/assistant.rb', line 104 def self.destroy!(id:, client: Client.new) response = client.connection .accept(:json) .headers(HEADERS) .delete("/#{OmniAI::OpenAI::Client::VERSION}/assistants/#{id}") raise HTTPError, response.flush unless response.status.ok? response.parse end |
.find(id:, client: Client.new) ⇒ OmniAI::OpenAI::Assistant
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/omniai/openai/assistant.rb', line 76 def self.find(id:, client: Client.new) response = client.connection .accept(:json) .headers(HEADERS) .get("/#{OmniAI::OpenAI::Client::VERSION}/assistants/#{id}") raise HTTPError, response.flush unless response.status.ok? parse(data: response.parse) end |
Instance Method Details
#destroy! ⇒ OmniAI::OpenAI::Assistant
130 131 132 133 134 135 136 |
# File 'lib/omniai/openai/assistant.rb', line 130 def destroy! raise OmniAI::Error, 'cannot destroy a non-persisted assistant' unless @id data = self.class.destroy!(id: @id, client: @client) @deleted = data['deleted'] self end |
#inspect ⇒ String
69 70 71 |
# File 'lib/omniai/openai/assistant.rb', line 69 def inspect "#<#{self.class.name} id=#{@id.inspect} name=#{@name.inspect} model=#{@model.inspect}>" end |
#save! ⇒ OmniAI::OpenAI::Assistant
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/omniai/openai/assistant.rb', line 117 def save! response = @client.connection .accept(:json) .headers(HEADERS) .post("/#{OmniAI::OpenAI::Client::VERSION}/assistants#{"/#{@id}" if @id}", json: payload) raise HTTPError, response.flush unless response.status.ok? parse(data: response.parse) self end |