eh-openai 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/LICENSE.txt +21 -0
- data/README.md +53 -0
- data/Rakefile +8 -0
- data/lib/openai/assistant_client.rb +61 -0
- data/lib/openai/base.rb +52 -0
- data/lib/openai/exceptions/exception.rb +20 -0
- data/lib/openai/models/assistant.rb +52 -0
- data/lib/openai/models/list_assistants.rb +14 -0
- data/lib/openai/models/list_data.rb +26 -0
- data/lib/openai/models/list_messages.rb +14 -0
- data/lib/openai/models/message.rb +53 -0
- data/lib/openai/models/run.rb +90 -0
- data/lib/openai/query_params/sort_order.rb +8 -0
- data/lib/openai/version.rb +5 -0
- data/lib/openai.rb +8 -0
- data/openai.gemspec +40 -0
- metadata +65 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 68bb4318e180f9ac9acd22b2a4354d7337e07ca35b69f51a2720ef58cec2f324
|
4
|
+
data.tar.gz: aef263167785c8d9da085f2d288c7e67faf0a204a46aa540bc78918003b3aba8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bf9126f180bccf0df1de28dcc4ad8ba94ee053488502e71b4547addbf34bd4887bf4880d89f537a66fe823feb73287bcbeb6464383762d10bd033b7ae2b318ae
|
7
|
+
data.tar.gz: ec4b7a0612cbd2a33c0403b6ab164ab92ee65284f88a3a45a9dc52bc1e6ad4a687c41b13ff36a24437fc23ed6bddf09b79d3ca4c9859ef928b9d5485e0939d6e
|
data/.rspec
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at linh.le@employmenthero.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
# OpenAI - Assistant
|
2
|
+
|
3
|
+
Ruby interface for calling OpenAI Assistant APIs
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
8
|
+
|
9
|
+
Install the gem and add to the application's Gemfile by executing:
|
10
|
+
|
11
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
16
|
+
|
17
|
+
## Features
|
18
|
+
|
19
|
+
- Get list assistants
|
20
|
+
- Get assistant details by assistant id
|
21
|
+
- Get assistant run status of thread id and run id
|
22
|
+
- Get list thread message by thread id
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
First, obtain an API key from https://platform.openai.com/api-keys.
|
27
|
+
```ruby
|
28
|
+
require "openai"
|
29
|
+
|
30
|
+
client = OpenAI::AssistantClient.new(apiKey = 'API_KEY')
|
31
|
+
|
32
|
+
# Get list assistants
|
33
|
+
client.get_list_assistants
|
34
|
+
client.get_list_assistants(limit = 2, order = SortOrder::ASC)
|
35
|
+
|
36
|
+
# Get assistant details by assistant id
|
37
|
+
client.get_assistant_by_id('asst_NUocaU9L32vGuCEPwXdzA17Ya')
|
38
|
+
|
39
|
+
# Get assistant run status of thread id and run id
|
40
|
+
client.get_run_status_by_thead_id_and_run_id(thread_id = 'thread_r0UdZWKXGMAyLfGOAIYbHNka', run_id = 'step_44RuaZU4oe8naEUwC2mK7gGf')
|
41
|
+
|
42
|
+
# Get list thread message by thread id
|
43
|
+
client.get_list_messages_by_thread_id(thread_id = 'thread_r0UdZWKXGMAyLfGOAIYbHNka')
|
44
|
+
client.get_list_messages_by_thread_id(thread_id = 'thread_r0UdZWKXGMAyLfGOAIYbHNka', limit = 2, order = SortOrder::ASC)
|
45
|
+
```
|
46
|
+
|
47
|
+
## License
|
48
|
+
|
49
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
50
|
+
|
51
|
+
## Code of Conduct
|
52
|
+
|
53
|
+
Everyone interacting in the OpenaiAssistant project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/openai_assistant/blob/main/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
require_relative 'base'
|
2
|
+
require_relative 'models/list_assistants'
|
3
|
+
require_relative 'models/list_messages'
|
4
|
+
require_relative 'models/run'
|
5
|
+
require_relative 'query_params/sort_order'
|
6
|
+
|
7
|
+
module OpenAI
|
8
|
+
class AssistantClient < RestBase
|
9
|
+
|
10
|
+
def initialize(api_key)
|
11
|
+
@api_key = api_key
|
12
|
+
end
|
13
|
+
|
14
|
+
# Get list assistants
|
15
|
+
# @param limit A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
|
16
|
+
# @param order Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.
|
17
|
+
# @param after A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
|
18
|
+
# @param before A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
|
19
|
+
# @return A list of [OpenAIAssistant::Model::Assistant] objects.
|
20
|
+
#
|
21
|
+
def get_list_assistants(limit = 20, order = SortOrder::ASC, after = nil, before = nil)
|
22
|
+
api_response = call_get('/assistants', {
|
23
|
+
'limit' => limit, 'order' => order, 'after' => after, 'before' => before
|
24
|
+
}.select { |_,v| !v.nil? })
|
25
|
+
Model::ListAssistants.new(api_response)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Get assistant details by assistant_id
|
29
|
+
# @param @required assistant_id The ID of the assistant to retrieve.
|
30
|
+
# @return The [OpenAIAssistant::Model::Assistant] object matching the specified ID.
|
31
|
+
def get_assistant_by_id(assistant_id)
|
32
|
+
api_response = call_get("/assistants/#{assistant_id}")
|
33
|
+
Model::Assistant.new(api_response)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Retrieves a run status by thread_id and run_id
|
37
|
+
# @param @required thread_id The ID of the thread that was run.
|
38
|
+
# @param @required run_id The ID of the run to retrieve.
|
39
|
+
# @return The [OpenAIAssistant::Model::Run] object matching the specified ID.
|
40
|
+
def get_run_status_by_thead_id_and_run_id(thread_id, run_id)
|
41
|
+
api_response = call_get("/threads/#{thread_id}/runs/#{run_id}")
|
42
|
+
Model::Run.new(api_response)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Returns a list of messages for a given thread.
|
46
|
+
# @param @required thread_id The ID of the thread the messages belong to.
|
47
|
+
# @param limit A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20.
|
48
|
+
# @param order Sort order by the created_at timestamp of the objects. asc for ascending order and desc for descending order.
|
49
|
+
# @param after A cursor for use in pagination. after is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include after=obj_foo in order to fetch the next page of the list.
|
50
|
+
# @param before A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list.
|
51
|
+
# @param run_id Filter messages by the run ID that generated them.
|
52
|
+
# @return A list of [OpenAIAssistant::Model::Message] objects.
|
53
|
+
def get_list_messages_by_thread_id(thread_id, limit = 20, order = SortOrder::DESC, after = nil, before = nil, run_id = nil)
|
54
|
+
api_response = call_get("/threads/#{thread_id}/messages", {
|
55
|
+
'limit' => limit, 'order' => order, 'after' => after, 'before' => before, 'run_id' => run_id
|
56
|
+
}.select { |_,v| !v.nil? })
|
57
|
+
Model::ListMessages.new(api_response)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
data/lib/openai/base.rb
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
require_relative 'exceptions/exception'
|
5
|
+
|
6
|
+
module OpenAI
|
7
|
+
|
8
|
+
class RestBase
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
OPENAI_API_BASEURL = "https://api.openai.com/v1"
|
13
|
+
|
14
|
+
def default_headers
|
15
|
+
{
|
16
|
+
'Content-Type' => 'application/json',
|
17
|
+
'Authorization' => "Bearer #{@api_key}",
|
18
|
+
'OpenAI-Beta' => 'assistants=v2'
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def call_get(url_path, params = {}, headers = default_headers)
|
23
|
+
# 1. Encode the parameters for inclusion in the URL
|
24
|
+
encoded_params = URI.encode_www_form(params)
|
25
|
+
|
26
|
+
# 2. Create URL
|
27
|
+
url = OPENAI_API_BASEURL + url_path
|
28
|
+
|
29
|
+
# 3. Combine the base URL and encoded parameters
|
30
|
+
full_url = "#{url}?#{encoded_params}"
|
31
|
+
|
32
|
+
# 4. Create a URL object from the full URL
|
33
|
+
uri = URI(full_url)
|
34
|
+
|
35
|
+
# 5. Create a new HTTP GET request
|
36
|
+
http = Net::HTTP::Get.new(uri, headers)
|
37
|
+
|
38
|
+
# 6. Send the request and get the response
|
39
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http_|
|
40
|
+
http_.request(http)
|
41
|
+
end
|
42
|
+
|
43
|
+
# 7. Check for response
|
44
|
+
if response.is_a?(Net::HTTPSuccess)
|
45
|
+
JSON.parse(response.body)
|
46
|
+
else
|
47
|
+
raise OpenAPIException.new(JSON.parse(response.body)['error'])
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module OpenAI
|
2
|
+
class OpenAPIException < StandardError
|
3
|
+
|
4
|
+
attr_reader :message
|
5
|
+
|
6
|
+
attr_reader :type
|
7
|
+
|
8
|
+
attr_reader :param
|
9
|
+
|
10
|
+
attr_reader :code
|
11
|
+
|
12
|
+
def initialize(attributes)
|
13
|
+
attributes.each do |key, value|
|
14
|
+
instance_variable_set("@#{key}", value)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
module OpenAI::Model
|
3
|
+
# Represents an OpenAI Assistant
|
4
|
+
class Assistant
|
5
|
+
|
6
|
+
# @return [String] The identifier, which can be referenced in API endpoints.
|
7
|
+
attr_reader :id
|
8
|
+
|
9
|
+
# @return [String] The object type, which is always assistant.
|
10
|
+
attr_reader :object
|
11
|
+
|
12
|
+
# @return [Integer] The Unix timestamp (in seconds) for when the assistant was created.
|
13
|
+
attr_reader :created_at
|
14
|
+
|
15
|
+
# @return [String | nil] The name of the assistant. The maximum length is 256 characters.
|
16
|
+
attr_reader :name
|
17
|
+
|
18
|
+
# @return [String | nil] The description of the assistant. The maximum length is 512 characters.
|
19
|
+
attr_reader :description
|
20
|
+
|
21
|
+
# @return [String] ID of the model to use.
|
22
|
+
attr_reader :model
|
23
|
+
|
24
|
+
# @return [String | nil] The system instructions that the assistant uses. The maximum length is 256,000 characters.
|
25
|
+
attr_reader :instructions
|
26
|
+
|
27
|
+
# @return [Array] A list of tool enabled on the assistant. There can be a maximum of 128 tools per assistant. Tools can be of types code_interpreter, file_search, or function
|
28
|
+
attr_reader :tools
|
29
|
+
|
30
|
+
# @return [String | nul] A set of resources that are used by the assistant's tools. The resources are specific to the type of tool. For example, the code_interpreter tool requires a list of file IDs, while the file_search tool requires a list of vector store IDs.
|
31
|
+
attr_reader :tool_resources
|
32
|
+
|
33
|
+
# @return [Hash] Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maximum of 512 characters long.
|
34
|
+
attr_reader :metadata
|
35
|
+
|
36
|
+
# @return [Numeric | nil] What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
|
37
|
+
attr_reader :temperature
|
38
|
+
|
39
|
+
# @return [Numeric | nil] An alternative to sampling with temperature, called nucleus sampling, where the model considers the results of the tokens with top_p probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or temperature but not both.
|
40
|
+
attr_reader :top_p
|
41
|
+
|
42
|
+
# @return [String] Specifies the format that the model must output.
|
43
|
+
attr_reader :response_format
|
44
|
+
|
45
|
+
def initialize(attributes)
|
46
|
+
attributes.each do |key, value|
|
47
|
+
instance_variable_set("@#{key}", value)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module OpenAI::Model
|
2
|
+
|
3
|
+
class ListData
|
4
|
+
# @return [Array[Assistant]] List assistants
|
5
|
+
attr_reader :data
|
6
|
+
|
7
|
+
# @return [String] first id
|
8
|
+
attr_reader :first_id
|
9
|
+
|
10
|
+
# @return [String] last id
|
11
|
+
attr_reader :last_id
|
12
|
+
|
13
|
+
# @return [bool] has more
|
14
|
+
attr_reader :has_more
|
15
|
+
|
16
|
+
def initialize(attributes)
|
17
|
+
attributes.each do |key, value|
|
18
|
+
instance_variable_set("@#{key}", key == 'data' ? parse_data(value) : value)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def parse_data(value)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
|
2
|
+
module OpenAI::Model
|
3
|
+
class Message
|
4
|
+
|
5
|
+
# @return [String] The identifier, which can be referenced in API endpoints.
|
6
|
+
attr_reader :id
|
7
|
+
|
8
|
+
# @return [String] The object type, which is always thread.message
|
9
|
+
attr_reader :object
|
10
|
+
|
11
|
+
# @return [Integer] The Unix timestamp (in seconds) for when the message was created.
|
12
|
+
attr_reader :created_at
|
13
|
+
|
14
|
+
# @return [Integer] The thread ID that this message belongs to.
|
15
|
+
attr_reader :thread_id
|
16
|
+
|
17
|
+
# @return [String] The status of the message, which can be either in_progress, incomplete, or completed.
|
18
|
+
attr_reader :status
|
19
|
+
|
20
|
+
# @return [String | nil] On an incomplete message, details about why the message is incomplete.
|
21
|
+
attr_reader :incomplete_details
|
22
|
+
|
23
|
+
# @return [Integer | nil] The Unix timestamp (in seconds) for when the message was completed.
|
24
|
+
attr_reader :completed_at
|
25
|
+
|
26
|
+
# @return [Integer | nil] The Unix timestamp (in seconds) for when the message was marked as incomplete.
|
27
|
+
attr_reader :incomplete_at
|
28
|
+
|
29
|
+
# @return [String] The entity that produced the message. One of user or assistant.
|
30
|
+
attr_reader :role
|
31
|
+
|
32
|
+
# @return [String] The content of the message in array of text and/or images.
|
33
|
+
attr_reader :content
|
34
|
+
|
35
|
+
# @return [String | nil] If applicable, the ID of the assistant that authored this message.
|
36
|
+
attr_reader :assistant_id
|
37
|
+
|
38
|
+
# @return [String | nil] The ID of the run associated with the creation of this message. Value is null when messages are created manually using the create message or create thread endpoints.
|
39
|
+
attr_reader :run_id
|
40
|
+
|
41
|
+
# @return [String] A list of files attached to the message, and the tools they were added to.
|
42
|
+
attr_reader :attachments
|
43
|
+
|
44
|
+
# @return [Hash[String, String]] Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maximum of 512 characters long.
|
45
|
+
attr_reader :metadata
|
46
|
+
|
47
|
+
def initialize(attributes)
|
48
|
+
attributes.each do |key, value|
|
49
|
+
instance_variable_set("@#{key}", value)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
|
2
|
+
module OpenAI::Model
|
3
|
+
# Represents an execution run on a thread.
|
4
|
+
class Run
|
5
|
+
|
6
|
+
# @return [String] The identifier, which can be referenced in API endpoints.
|
7
|
+
attr_reader :id
|
8
|
+
|
9
|
+
# @return [String] The object type, which is always thread.run
|
10
|
+
attr_reader :object
|
11
|
+
|
12
|
+
# @return [Integer] The Unix timestamp (in seconds) for when the run was created.
|
13
|
+
attr_reader :created_at
|
14
|
+
|
15
|
+
# @return [String] The ID of the thread that was executed on as a part of this run.
|
16
|
+
attr_reader :thread_id
|
17
|
+
|
18
|
+
# @return [String] The ID of the assistant used for execution of this run.
|
19
|
+
attr_reader :assistant_id
|
20
|
+
|
21
|
+
# @return [String] The status of the run, which can be either queued, in_progress, requires_action, cancelling, cancelled, failed, completed, or expired
|
22
|
+
attr_reader :status
|
23
|
+
|
24
|
+
# @return [String | nil] Details on the action required to continue the run. Will be null if no action is required.
|
25
|
+
attr_reader :required_action
|
26
|
+
|
27
|
+
# @return [String | nil] The last error associated with this run. Will be null if there are no errors.
|
28
|
+
attr_reader :last_error
|
29
|
+
|
30
|
+
# @return [Integer | nil] The Unix timestamp (in seconds) for when the run will expire.
|
31
|
+
attr_reader :expires_at
|
32
|
+
|
33
|
+
# @return [Integer | nil] The Unix timestamp (in seconds) for when the run was started.
|
34
|
+
attr_reader :started_at
|
35
|
+
|
36
|
+
# @return [Integer | nil] The Unix timestamp (in seconds) for when the run was cancelled.
|
37
|
+
attr_reader :cancelled_at
|
38
|
+
|
39
|
+
# @return [Integer | nil] The Unix timestamp (in seconds) for when the run failed.
|
40
|
+
attr_reader :failed_at
|
41
|
+
|
42
|
+
# @return [Integer | nil] The Unix timestamp (in seconds) for when the run was completed.
|
43
|
+
attr_reader :completed_at
|
44
|
+
|
45
|
+
# @return [String | nil] Details on why the run is incomplete. Will be null if the run is not incomplete.
|
46
|
+
attr_reader :incomplete_details
|
47
|
+
|
48
|
+
# @return [String] The model that the assistant used for this run.
|
49
|
+
attr_reader :model
|
50
|
+
|
51
|
+
# @return [String] The instructions that the assistant used for this run.
|
52
|
+
attr_reader :instructions
|
53
|
+
|
54
|
+
# @return [String] The list of tools that the assistant used for this run.
|
55
|
+
attr_reader :tools
|
56
|
+
|
57
|
+
# @return [Hash[String, String]] Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format. Keys can be a maximum of 64 characters long and values can be a maximum of 512 characters long.
|
58
|
+
attr_reader :metadata
|
59
|
+
|
60
|
+
# @return [String | nil] Usage statistics related to the run. This value will be null if the run is not in a terminal state (i.e. in_progress, queued, etc.).
|
61
|
+
attr_reader :usage
|
62
|
+
|
63
|
+
# @return [Number | nil] The sampling temperature used for this run. If not set, defaults to 1.
|
64
|
+
attr_reader :temperature
|
65
|
+
|
66
|
+
# @return [Number | nil] The nucleus sampling value used for this run. If not set, defaults to 1.
|
67
|
+
attr_reader :top_p
|
68
|
+
|
69
|
+
# @return [Integer | nil] The maximum number of prompt tokens specified to have been used over the course of the run.
|
70
|
+
attr_reader :max_prompt_tokens
|
71
|
+
|
72
|
+
# @return [Integer | nil] The maximum number of completion tokens specified to have been used over the course of the run.
|
73
|
+
attr_reader :max_completion_tokens
|
74
|
+
|
75
|
+
# @return [String] Controls for how a thread will be truncated prior to the run. Use this to control the initial context window of the run.
|
76
|
+
attr_reader :truncation_strategy
|
77
|
+
|
78
|
+
# @return [String] Controls which (if any) tool is called by the model. none means the model will not call any tools and instead generates a message. auto is the default value and means the model can pick between generating a message or calling one or more tools. required means the model must call one or more tools before responding to the user. Specifying a particular tool like {"type": "file_search"} or {"type": "function", "function": {"name": "my_function"}} forces the model to call that tool.
|
79
|
+
attr_reader :tool_choice
|
80
|
+
|
81
|
+
# @return [String] Specifies the format that the model must output.
|
82
|
+
attr_reader :response_format
|
83
|
+
|
84
|
+
def initialize(attributes)
|
85
|
+
attributes.each do |key, value|
|
86
|
+
instance_variable_set("@#{key}", value)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/openai.rb
ADDED
data/openai.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/openai/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "eh-openai"
|
7
|
+
spec.version = OpenAI::VERSION
|
8
|
+
spec.authors = ["Linh Le"]
|
9
|
+
spec.email = ["linh.le@employmenthero.com"]
|
10
|
+
|
11
|
+
spec.summary = "OpenAI Assistant API version 2"
|
12
|
+
spec.description = "A Ruby interface to the OpenAI Assistant API version 2"
|
13
|
+
spec.homepage = "https://github.com/eh-linhle"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
16
|
+
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = "https://github.com/eh-linhle"
|
21
|
+
spec.metadata["changelog_uri"] = "https://github.com/eh-linhle/CHANGELOG.md"
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(__dir__) do
|
26
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
(File.expand_path(f) == __FILE__) ||
|
28
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
spec.bindir = "exe"
|
32
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
|
35
|
+
# Uncomment to register a new dependency of your gem
|
36
|
+
# spec.add_dependency "example-gem", "~> 1.0"
|
37
|
+
|
38
|
+
# For more information and examples about making a new gem, check out our
|
39
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: eh-openai
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Linh Le
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-05-14 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A Ruby interface to the OpenAI Assistant API version 2
|
14
|
+
email:
|
15
|
+
- linh.le@employmenthero.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".rspec"
|
21
|
+
- CODE_OF_CONDUCT.md
|
22
|
+
- LICENSE.txt
|
23
|
+
- README.md
|
24
|
+
- Rakefile
|
25
|
+
- lib/openai.rb
|
26
|
+
- lib/openai/assistant_client.rb
|
27
|
+
- lib/openai/base.rb
|
28
|
+
- lib/openai/exceptions/exception.rb
|
29
|
+
- lib/openai/models/assistant.rb
|
30
|
+
- lib/openai/models/list_assistants.rb
|
31
|
+
- lib/openai/models/list_data.rb
|
32
|
+
- lib/openai/models/list_messages.rb
|
33
|
+
- lib/openai/models/message.rb
|
34
|
+
- lib/openai/models/run.rb
|
35
|
+
- lib/openai/query_params/sort_order.rb
|
36
|
+
- lib/openai/version.rb
|
37
|
+
- openai.gemspec
|
38
|
+
homepage: https://github.com/eh-linhle
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata:
|
42
|
+
allowed_push_host: https://rubygems.org
|
43
|
+
homepage_uri: https://github.com/eh-linhle
|
44
|
+
source_code_uri: https://github.com/eh-linhle
|
45
|
+
changelog_uri: https://github.com/eh-linhle/CHANGELOG.md
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.6.0
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubygems_version: 3.1.6
|
62
|
+
signing_key:
|
63
|
+
specification_version: 4
|
64
|
+
summary: OpenAI Assistant API version 2
|
65
|
+
test_files: []
|