ksylvest / omniai-openai

An implementation of the OmniAI interface for OpenAI.
https://rubydoc.info/github/ksylvest/omniai-openai
MIT License
1 stars 0 forks source link

Support for Assistants #6

Closed ksylvest closed 1 week ago

ksylvest commented 2 weeks ago

Files

Finding an File

client.files.find(id: 'file_...')

Listing all Files

client.files.all

Uploading a File

file = client.files.build(io: File.open('...', 'wb'))
file.save!

Downloading a File

file = client.files.find(id: 'file_...')
File.open('...', 'wb') do |file|
  file.content do |chunk|
    file << chunk
  end
end

Destroying a File

client.files.destroy!('file_...')
## Assistants

### Finding an Assistant

```ruby
client.assistants.find(id: 'asst_...')

Assistants

Listing all Assistants

client.assistants.all

Creating an Assistant

assistant = client.assistants.build
assistant.name = 'Ringo'
assistant.model = OmniAI::OpenAI::Chat::Model::GPT_4
assistant.description = 'The drummer for the Beatles.'
assistant.save!

Updating an Assistant

assistant = client.assistants.find(id: 'asst_...')
assistant.name = 'George'
assistant.model = OmniAI::OpenAI::Chat::Model::GPT_4
assistant.description = 'A guitarist for the Beatles.'
assistant.save!

Destroying an Assistant

client.assistants.destroy!('asst_...')

Threads

Finding a Thread

client.threads.find(id: 'thread_...')

Creating a Thread

thread = client.threads.build
thread.metadata = { user: 'Ringo' }
thread.save!

Updating a Thread

thread = client.threads.find(id: 'thread_...')
thread.metadata = { user: 'Ringo' }
thread.save!

Destroying a Threads

client.threads.destroy!('thread_...')

Messages

Finding a Message

thread = client.threads.find(id: 'thread_...')
message = thread.messages.find(id: 'msg_...')
message.save!

Listing all Messages

thread = client.threads.find(id: 'thread_...')
thread.messages.all

Creating a Message

thread = client.threads.find(id: 'thread_...')
message = thread.messages.build(role: 'user', content: 'Hello?')
message.save!

Updating a Message

thread = client.threads.find(id: 'thread_...')
message = thread.messages.build(role: 'user', content: 'Hello?')
message.save!

Runs

Finding a Run

thread = client.threads.find(id: 'thread_...')
run = thread.runs.find(id: 'run_...')
run.save!

Listing all Runs

thread = client.threads.find(id: 'thread_...')
thread.runs.all

Creating a Run

run = client.runs.find(id: 'thread_...')
run = thread.runs.build
run.metadata = { user: 'Ringo' }
run.save!

Updating a Run

thread = client.threads.find(id: 'thread_...')
run = thread.messages.find(id: 'run_...')
run.metadata = { user: 'Ringo' }
run.save!

Cancelling a Run

thread = client.threads.find(id: 'thread_...')
run = thread.runs.cancel!(id: 'run_...')