openai-assistant 1.0.0 → 1.1.0
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 +4 -4
- data/README.md +3 -3
- data/lib/openai_assistant/base.rb +2 -2
- data/lib/openai_assistant/client.rb +5 -5
- data/lib/openai_assistant/clients/assistant/create.rb +4 -4
- data/lib/openai_assistant/clients/assistant/delete.rb +2 -2
- data/lib/openai_assistant/clients/assistant/list.rb +4 -4
- data/lib/openai_assistant/clients/assistant/retrieve.rb +4 -4
- data/lib/openai_assistant/clients/http/http.rb +1 -1
- data/lib/openai_assistant/error_response.rb +2 -2
- data/lib/openai_assistant/mappers/assistant.rb +2 -2
- data/lib/openai_assistant/version.rb +2 -2
- data/openai-assistant.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1d903e8d269b7951b68f30be711b1891f4175ae828f0ef57aa52896971604920
|
4
|
+
data.tar.gz: 2b310fe5f7423d00f57760d9a0a48c715b6617bd592d98ad5c04f07fdb76e4e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab128129583233462bde63adb5ca0dce2799313b362e0c8632d86046803a39c8d57dde423736b34e931b1cf797a0ff539dd19e4deee88f048b6628a8723b3b4b
|
7
|
+
data.tar.gz: cdd30bd9901b70e7c1bc7bb4a749b9e6c37d6450be09e4494f606f3a7f33da8412016f01ba36da43de5c1ce32a8d24beda60e245cd28f93cc1cce2a4532992a8
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
#
|
1
|
+
# OpenaiAssistant::Assistant
|
2
2
|
This project/gem is for Ruby interact with OpenAI Assistant throught rest api.
|
3
3
|
|
4
|
-
The client to call is: `
|
4
|
+
The client to call is: `OpenaiAssistant::Assistant`
|
5
5
|
|
6
6
|
## Installation
|
7
7
|
Install throught RubyGems server by below step:
|
@@ -14,7 +14,7 @@ Install throught RubyGems server by below step:
|
|
14
14
|
You can direct interact with gem by:
|
15
15
|
|
16
16
|
- use the gem `require "openai/assistant"`
|
17
|
-
- setup the api key `instance =
|
17
|
+
- setup the api key `instance = OpenaiAssistant::Assistant::new(${API_KEY})`
|
18
18
|
- interact with assistant:
|
19
19
|
+ `instance.create_assistant(model, instruction)`
|
20
20
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module OpenaiAssistant
|
4
4
|
# Base class of openai
|
5
5
|
class Base
|
6
6
|
def initialize(api_key = "")
|
@@ -8,7 +8,7 @@ module OpenaiAsissistant
|
|
8
8
|
# hard the host because if the official docs change the host, maybe it will change another
|
9
9
|
# we need to update this gem for any change
|
10
10
|
@openai_url = "https://api.openai.com/v1/assistants"
|
11
|
-
@http_client =
|
11
|
+
@http_client = OpenaiAssistant::HTTPClient.new
|
12
12
|
end
|
13
13
|
|
14
14
|
def default_headers
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module OpenaiAssistant
|
4
4
|
module Assistant
|
5
5
|
# An openai assistant client
|
6
6
|
class Client
|
@@ -11,19 +11,19 @@ module OpenaiAsissistant
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def create_assistant(model, instructions)
|
14
|
-
|
14
|
+
OpenaiAssistant::Assistant::Create.new(@api_key).create_assistant(model, instructions)
|
15
15
|
end
|
16
16
|
|
17
17
|
def retrieve_assistant(assistant_id)
|
18
|
-
|
18
|
+
OpenaiAssistant::Assistant::Retrieve.new(@api_key).retrieve_assistant(assistant_id)
|
19
19
|
end
|
20
20
|
|
21
21
|
def list_assistant
|
22
|
-
|
22
|
+
OpenaiAssistant::Assistant::List.new(@api_key).list_assistant
|
23
23
|
end
|
24
24
|
|
25
25
|
def delete_assistant(assistant_id)
|
26
|
-
|
26
|
+
OpenaiAssistant::Assistant::Delete.new(@api_key).delete_assistant(assistant_id)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module OpenaiAssistant
|
4
4
|
module Assistant
|
5
5
|
# An openai assistant
|
6
6
|
class Create < Base
|
7
7
|
# @param model [String] Select model of the assistant. refer on: https://platform.openai.com/docs/api-reference/models/list.
|
8
8
|
# @param instructions [String] The system instructions that the assistant uses.
|
9
|
-
# @return [
|
9
|
+
# @return [OpenaiAssistant::Mapper::Assistant] A new response object of assistant.
|
10
10
|
def create_assistant(model, instructions)
|
11
11
|
url = URI.parse(@openai_url)
|
12
12
|
req_body = {
|
@@ -16,9 +16,9 @@ module OpenaiAsissistant
|
|
16
16
|
"model": model
|
17
17
|
}.to_json
|
18
18
|
response = @http_client.call_post(url, req_body, default_headers)
|
19
|
-
return
|
19
|
+
return OpenaiAssistant::ErrorResponse.from_json(response.body) unless response.code == "200"
|
20
20
|
|
21
|
-
|
21
|
+
OpenaiAssistant::Mapper::Assistant.from_json(JSON.parse(response.body))
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module OpenaiAssistant
|
4
4
|
module Assistant
|
5
5
|
# An openai assistant
|
6
6
|
class Delete < Base
|
@@ -10,7 +10,7 @@ module OpenaiAsissistant
|
|
10
10
|
url = "#{@openai_url}/#{assistant_id}"
|
11
11
|
uri = URI(url)
|
12
12
|
response = @http_client.call_delete(uri, default_headers)
|
13
|
-
return
|
13
|
+
return OpenaiAssistant::ErrorResponse.from_json(response.body) unless response.code == "200"
|
14
14
|
|
15
15
|
true
|
16
16
|
end
|
@@ -1,20 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module OpenaiAssistant
|
4
4
|
module Assistant
|
5
5
|
# An openai assistant
|
6
6
|
class List < Base
|
7
|
-
# @return [Array<
|
7
|
+
# @return [Array<OpenaiAssistant::Mapper::Assistant>] List all assistant
|
8
8
|
def list_assistant
|
9
9
|
url = @openai_url
|
10
10
|
uri = URI(url)
|
11
11
|
response = @http_client.call_get(uri, default_headers)
|
12
|
-
return
|
12
|
+
return OpenaiAssistant::ErrorResponse.from_json(response.body) unless response.code == "200"
|
13
13
|
|
14
14
|
parsed = JSON.parse(response.body)
|
15
15
|
assistants = []
|
16
16
|
parsed["data"].each do |ast|
|
17
|
-
assistants <<
|
17
|
+
assistants << OpenaiAssistant::Mapper::Assistant.from_json(ast)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module OpenaiAssistant
|
4
4
|
module Assistant
|
5
5
|
# An openai assistant
|
6
6
|
class Retrieve < Base
|
7
7
|
# @param assistant_id [String] The id of assistant after create
|
8
|
-
# @return [
|
8
|
+
# @return [OpenaiAssistant::Mapper::OpenaiAssistant] A new response object of assistant.
|
9
9
|
def retrieve_assistant(assistant_id)
|
10
10
|
url = "#{@openai_url}/#{assistant_id}"
|
11
11
|
uri = URI(url)
|
12
12
|
response = @http_client.call_get(uri, default_headers)
|
13
|
-
return
|
13
|
+
return OpenaiAssistant::ErrorResponse.from_json(response.body) unless response.code == "200"
|
14
14
|
|
15
|
-
|
15
|
+
OpenaiAssistant::Mapper::Assistant.from_json(JSON.parse(response.body))
|
16
16
|
end
|
17
17
|
end
|
18
18
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module OpenaiAssistant
|
4
4
|
# A error response of openai
|
5
5
|
class ErrorResponse
|
6
6
|
# @return [String] error message
|
@@ -20,7 +20,7 @@ module OpenaiAsissistant
|
|
20
20
|
|
21
21
|
def self.from_json(response_body)
|
22
22
|
data = JSON.parse(response_body)["error"]
|
23
|
-
|
23
|
+
OpenaiAssistant::ErrorResponse.new(
|
24
24
|
message: data["message"],
|
25
25
|
type: data["type"],
|
26
26
|
param: data["param"],
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module
|
3
|
+
module OpenaiAssistant
|
4
4
|
# A mapper of assistant
|
5
5
|
module Mapper
|
6
6
|
# A object model struct of assistant
|
@@ -33,7 +33,7 @@ module OpenaiAsissistant
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def self.from_json(data)
|
36
|
-
|
36
|
+
OpenaiAssistant::Mapper::Assistant.new(
|
37
37
|
id: data["id"],
|
38
38
|
object: data["object"],
|
39
39
|
created_at: data["created_at"],
|
data/openai-assistant.gemspec
CHANGED
@@ -5,7 +5,7 @@ require_relative "lib/openai_assistant/version"
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "openai-assistant"
|
8
|
-
spec.version =
|
8
|
+
spec.version = OpenaiAssistant::VERSION
|
9
9
|
spec.authors = ["duonghds"]
|
10
10
|
spec.email = ["duong.hoang@employmenthero.com"]
|
11
11
|
|
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: 1.
|
4
|
+
version: 1.1.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-12-
|
11
|
+
date: 2023-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|