rasti-ai 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/lib/rasti/ai/open_ai/assistant.rb +15 -4
- data/lib/rasti/ai/open_ai/client.rb +4 -2
- data/lib/rasti/ai/version.rb +1 -1
- data/spec/open_ai/assistant_spec.rb +22 -5
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bd63fcf9d5f5af5cd58627893322ee4f09c3a5d45c489865ff3cebe9c11aaf3
|
4
|
+
data.tar.gz: ed2992eabeb5a0c0fe429d8c9dbaa96036658cf3c27540b4069e80e5ee6b83df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aea33a82665fb2e565ba9efcbd7de3ed7872e7e28ce95a407013dae8aa966cf916f4963e9e324f631e7cbd1d9ebe915b0832a8627466409c7a1c1e9ffcfd09e4
|
7
|
+
data.tar.gz: cf551997163a891f116e55cbb19225f1bda0006ab32b360cdd78409f4b200ebf5658f414adecc9066ddbcca768f8d2d92a0a425d69898aa9815f6485871fbda5
|
@@ -5,8 +5,9 @@ module Rasti
|
|
5
5
|
|
6
6
|
attr_reader :state
|
7
7
|
|
8
|
-
def initialize(client:nil, state:nil, model:nil, tools:[], logger:nil)
|
8
|
+
def initialize(client:nil, json_schema:nil, state:nil, model:nil, tools:[], logger:nil)
|
9
9
|
@client = client || Client.new
|
10
|
+
@json_schema = json_schema
|
10
11
|
@state = state || AssistantState.new
|
11
12
|
@model = model
|
12
13
|
@tools = {}
|
@@ -29,7 +30,8 @@ module Rasti
|
|
29
30
|
loop do
|
30
31
|
response = client.chat_completions messages: messages,
|
31
32
|
model: model,
|
32
|
-
tools: serialized_tools
|
33
|
+
tools: serialized_tools,
|
34
|
+
response_format: response_format
|
33
35
|
|
34
36
|
choice = response['choices'][0]['message']
|
35
37
|
|
@@ -64,7 +66,7 @@ module Rasti
|
|
64
66
|
|
65
67
|
private
|
66
68
|
|
67
|
-
attr_reader :client, :model, :tools, :serialized_tools, :logger
|
69
|
+
attr_reader :client, :json_schema, :model, :tools, :serialized_tools, :logger
|
68
70
|
|
69
71
|
def messages
|
70
72
|
state.messages
|
@@ -90,7 +92,16 @@ module Rasti
|
|
90
92
|
"Error: #{ex.message}"
|
91
93
|
end
|
92
94
|
|
95
|
+
def response_format
|
96
|
+
return nil if json_schema.nil?
|
97
|
+
|
98
|
+
{
|
99
|
+
type: 'json_schema',
|
100
|
+
json_schema: json_schema
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
93
104
|
end
|
94
105
|
end
|
95
106
|
end
|
96
|
-
end
|
107
|
+
end
|
@@ -10,7 +10,7 @@ module Rasti
|
|
10
10
|
@logger = logger || Rasti::AI.logger
|
11
11
|
end
|
12
12
|
|
13
|
-
def chat_completions(messages:, model:nil, tools:[])
|
13
|
+
def chat_completions(messages:, model:nil, tools:[], response_format: nil)
|
14
14
|
body = {
|
15
15
|
model: model || Rasti::AI.openai_default_model,
|
16
16
|
messages: messages,
|
@@ -18,6 +18,8 @@ module Rasti
|
|
18
18
|
tool_choice: tools.empty? ? 'none' : 'auto'
|
19
19
|
}
|
20
20
|
|
21
|
+
body[:response_format] = response_format unless response_format.nil?
|
22
|
+
|
21
23
|
post '/chat/completions', body
|
22
24
|
end
|
23
25
|
|
@@ -54,4 +56,4 @@ module Rasti
|
|
54
56
|
end
|
55
57
|
|
56
58
|
end
|
57
|
-
end
|
59
|
+
end
|
data/lib/rasti/ai/version.rb
CHANGED
@@ -8,14 +8,17 @@ describe Rasti::AI::OpenAI::Assistant do
|
|
8
8
|
|
9
9
|
let(:answer) { 'Lionel Messi scored 672 goals in 778 official matches for FC Barcelona.' }
|
10
10
|
|
11
|
-
def stub_open_ai_chat_completions(model:nil,
|
11
|
+
def stub_open_ai_chat_completions(question:, answer:, model:nil, json_schema:nil)
|
12
12
|
model ||= Rasti::AI.openai_default_model
|
13
13
|
|
14
|
+
body = read_json_resource('open_ai/basic_request.json', model: model, prompt: question)
|
15
|
+
body['response_format'] = {type: 'json_schema', json_schema: json_schema} if json_schema
|
16
|
+
|
14
17
|
stub_request(:post, api_url)
|
15
|
-
.with(body:
|
18
|
+
.with(body: JSON.dump(body))
|
16
19
|
.to_return(body: read_resource('open_ai/basic_response.json', content: answer))
|
17
20
|
end
|
18
|
-
|
21
|
+
|
19
22
|
|
20
23
|
it 'Default' do
|
21
24
|
stub_open_ai_chat_completions question: question, answer: answer
|
@@ -39,7 +42,8 @@ describe Rasti::AI::OpenAI::Assistant do
|
|
39
42
|
role: Rasti::AI::OpenAI::Roles::USER,
|
40
43
|
content: question
|
41
44
|
}
|
42
|
-
]
|
45
|
+
],
|
46
|
+
response_format: nil
|
43
47
|
}
|
44
48
|
]
|
45
49
|
|
@@ -107,6 +111,19 @@ describe Rasti::AI::OpenAI::Assistant do
|
|
107
111
|
assert_equal answer, response
|
108
112
|
end
|
109
113
|
|
114
|
+
it 'JSON Schema' do
|
115
|
+
json_schema = {answer: 'Response answer'}
|
116
|
+
json_answer = "{\\\"answer\\\": \\\"#{answer}\\\"}"
|
117
|
+
|
118
|
+
stub_open_ai_chat_completions question: question, answer: json_answer, json_schema: json_schema
|
119
|
+
|
120
|
+
assistant = Rasti::AI::OpenAI::Assistant.new json_schema: json_schema
|
121
|
+
|
122
|
+
response = assistant.call question
|
123
|
+
|
124
|
+
assert_equal answer, JSON.parse(response)['answer']
|
125
|
+
end
|
126
|
+
|
110
127
|
end
|
111
128
|
|
112
129
|
describe 'Tools' do
|
@@ -278,4 +295,4 @@ describe Rasti::AI::OpenAI::Assistant do
|
|
278
295
|
|
279
296
|
end
|
280
297
|
|
281
|
-
end
|
298
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rasti-ai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Naiman
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-
|
11
|
+
date: 2025-06-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_require
|
@@ -210,7 +210,7 @@ homepage: https://github.com/gabynaiman/rasti-ai
|
|
210
210
|
licenses:
|
211
211
|
- MIT
|
212
212
|
metadata: {}
|
213
|
-
post_install_message:
|
213
|
+
post_install_message:
|
214
214
|
rdoc_options: []
|
215
215
|
require_paths:
|
216
216
|
- lib
|
@@ -225,8 +225,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
225
225
|
- !ruby/object:Gem::Version
|
226
226
|
version: '0'
|
227
227
|
requirements: []
|
228
|
-
rubygems_version: 3.
|
229
|
-
signing_key:
|
228
|
+
rubygems_version: 3.0.9
|
229
|
+
signing_key:
|
230
230
|
specification_version: 4
|
231
231
|
summary: AI for apps
|
232
232
|
test_files:
|