openai-assistant 0.1.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64fdebd2ebeba89ddc5a70fd0a3c56eb677935138de23e70dbdeafbd91ce5b84
4
- data.tar.gz: f3b25cfae2e3e0dd3149a0da2d16f3719cf1ed54ddc8d1f22e0d6dcb4ab4a7d4
3
+ metadata.gz: e4ddb6b9bd825412979c3e7a33935200236dff748ce439c8c5ac29fb7dfadc6c
4
+ data.tar.gz: c0c4fa73e072bfc18daa545ce8b06243d581adc3a5d948ffad68e311016de6c6
5
5
  SHA512:
6
- metadata.gz: 0665f422378e79c08cb8e249b10db948216c390159156bbec06f2b253799c1e525fb2a3a54d6c625157509657434b03901e902f7364714d3f253d67050a2fb35
7
- data.tar.gz: 24e349e872037bec3e4ba5f95555cf0835dbee1aa1f496337d9f0cb93a4d21926eae4ca893e5d11fa9a01b5ea16bfcf7d8231f4327a53ad70eed4e28c349002c
6
+ metadata.gz: 67d7e18366125045cfbdb2180955b337a31b361eb8079c118a8fa8ca919b9d78878bf7879d910a2d942fdb3d5d85a23adbbf67d276974caf86d3c0c5223e0e7a
7
+ data.tar.gz: e3dab4d30f625f79d93f424641640f74089915b103dc7e2fa32d1995f29fdd5805cd402b73e639db6eef70f8b8c608dd36f669a3e9b41847997bf686480b3ee8
data/README.md CHANGED
@@ -1,39 +1,25 @@
1
1
  # Openai::Assistant
2
+ This project/gem is for Ruby interact with OpenAI Assistant throught rest api.
2
3
 
3
- TODO: Delete this and the text below, and describe your gem
4
-
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/openai/assistant`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+ The client to call is: `Openai::Assistant`
6
5
 
7
6
  ## Installation
7
+ Install throught RubyGems server by below step:
8
8
 
9
- 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.
10
-
11
- Install the gem and add to the application's Gemfile by executing:
12
-
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
9
+ `$ bundle add openai/assistant`.
14
10
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
16
-
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
11
+ `$ bundle install openai/assistant`
18
12
 
19
13
  ## Usage
14
+ You can direct interact with gem by:
20
15
 
21
- TODO: Write usage instructions here
22
-
23
- ## Development
24
-
25
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26
-
27
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
-
29
- ## Contributing
30
-
31
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/openai-assistant. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/openai-assistant/blob/main/CODE_OF_CONDUCT.md).
32
-
33
- ## License
16
+ - use the gem `require "openai/assistant"`
17
+ - setup the api key `instance =Openai::Assistant::new(${API_KEY})`
18
+ - interact with assistant:
19
+ + `instance.create_assistant(model, instruction)`
34
20
 
35
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
21
+ + `instance.retrieve_assistant(assistant_id)`
36
22
 
37
- ## Code of Conduct
23
+ + `instance.delete_assistant(assistant_id)`
38
24
 
39
- Everyone interacting in the Openai::Assistant 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).
25
+ + `instance.list_assistant()`
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Openai
4
4
  class Assistant
5
- VERSION = "0.1.0"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
@@ -10,12 +10,28 @@ module Openai
10
10
  # An openai assistant
11
11
  class Assistant
12
12
  @openai_api_key = nil
13
- @openai_url = "https://api.openai.com/v1/assistants"
14
- def self.initialize(api_key)
13
+ @openai_url = nil
14
+
15
+ # @param api_key [String] The api key of openai
16
+ def initialize(api_key = "")
17
+ @openai_api_key = api_key
18
+ # hard the host because if the official docs change the host, maybe it will change another
19
+ # we need to update this gem for any change
20
+ @openai_url = "https://api.openai.com/v1/assistants"
21
+ end
22
+
23
+ # @param api_key [String] The api key of openai
24
+ def self.setup(api_key = "")
15
25
  @openai_api_key = api_key
26
+ # hard the host because if the official docs change the host, maybe it will change another
27
+ # we need to update this gem for any change
28
+ @openai_url = "https://api.openai.com/v1/assistants"
16
29
  end
17
30
 
18
- def self.create_assistant(model, instructions)
31
+ # @param model [String] Select model of the assistant. refer on: https://platform.openai.com/docs/api-reference/models/list.
32
+ # @param instructions [String] The system instructions that the assistant uses.
33
+ # @return [Openai::AssistantObj] A new response object of assistant.
34
+ def create_assistant(model, instructions)
19
35
  url = @openai_url
20
36
  headers = {
21
37
  "Authorization": "Bearer #{@openai_api_key}",
@@ -40,7 +56,9 @@ module Openai
40
56
  parse_assistant_object(JSON.parse(resp.body))
41
57
  end
42
58
 
43
- def self.retrieve_assistant(assistant_id)
59
+ # @param assistant_id [String] The id of assistant after create
60
+ # @return [Openai::AssistantObj] A new response object of assistant.
61
+ def retrieve_assistant(assistant_id)
44
62
  url = "#{@openai_url}/#{assistant_id}"
45
63
  headers = {
46
64
  "Authorization": "Bearer #{@openai_api_key}",
@@ -59,7 +77,9 @@ module Openai
59
77
  parse_assistant_object(JSON.parse(resp.body))
60
78
  end
61
79
 
62
- def self.delete_assistant(assistant_id)
80
+ # @param assistant_id [String] The id of assistant after create
81
+ # @return [String] Message delete the assistant ok or not
82
+ def delete_assistant(assistant_id)
63
83
  url = "#{@openai_url}/#{assistant_id}"
64
84
  headers = {
65
85
  "Authorization": "Bearer #{@openai_api_key}",
@@ -77,7 +97,30 @@ module Openai
77
97
  parsed["deleted"]
78
98
  end
79
99
 
80
- def self.parse_assistant_object(data)
100
+ # @return [Array<Openai::AssistantObj>] List all assistant
101
+ def list_assistant
102
+ url = @openai_url
103
+ headers = {
104
+ "Authorization": "Bearer #{@openai_api_key}",
105
+ "OpenAI-Beta": "assistants=v1",
106
+ "Content-Type": "application/json"
107
+ }
108
+ begin
109
+ resp = RestClient.get(url, headers)
110
+ rescue RestClient::ExceptionWithResponse => e
111
+ resp = e.response
112
+ end
113
+ parsed = JSON.parse(resp.body)
114
+ return parsed["error"]["code"] unless resp.code == 200
115
+
116
+ assistants = []
117
+ parsed["data"].each do |ast|
118
+ assistants << parse_assistant_object(ast)
119
+ end
120
+ end
121
+
122
+ # @return private
123
+ def parse_assistant_object(data)
81
124
  Openai::AssistantObj.new(
82
125
  id: data["id"],
83
126
  object: data["object"],
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openai-assistant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - duonghds
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-28 00:00:00.000000000 Z
11
+ date: 2023-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec