omniai-openai 1.5.0 → 1.6.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 +4 -4
- data/README.md +8 -19
- data/lib/omniai/openai/chat.rb +9 -1
- data/lib/omniai/openai/client.rb +5 -2
- data/lib/omniai/openai/version.rb +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: 3ff87839fda74772081155dca341df25a7112ac9fb40940d3a9ce027702f78fa
|
4
|
+
data.tar.gz: c4f892dc84bf3c9c6f914dbf19912c34add5f30d486ddaef5d4a72122ecc42bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecea745e019e298450b06485dc8283d66e2a3bb0e0562a54ee6c55c358b1e687afb1c7f9f34e9b45a495189ca282651183fdd47983492f554ce68a6125277529
|
7
|
+
data.tar.gz: e1834ffed43d4db32b430bdf7150af21250d7757adf87c5dbc5912162598038f661ba24b24aaa6ac4cf078c9db7d32e7ec1d0a1c79c79e52dac94d2f27f74991
|
data/README.md
CHANGED
@@ -70,21 +70,10 @@ completion.choice.message.content # 'Why did the chicken cross the road? To get
|
|
70
70
|
```
|
71
71
|
|
72
72
|
```ruby
|
73
|
-
completion = client.chat
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
completion.choice.message.content # 'No.'
|
78
|
-
```
|
79
|
-
|
80
|
-
```ruby
|
81
|
-
completion = client.chat([
|
82
|
-
{
|
83
|
-
role: OmniAI::Chat::Role::SYSTEM,
|
84
|
-
content: 'You are a helpful assistant.'
|
85
|
-
},
|
86
|
-
'What is the capital of Canada?',
|
87
|
-
])
|
73
|
+
completion = client.chat do |prompt|
|
74
|
+
prompt.system('Your are an expert in geography.')
|
75
|
+
prompt.user('What is the capital of Canada?')
|
76
|
+
end
|
88
77
|
completion.choice.message.content # 'The capital of Canada is Ottawa.'
|
89
78
|
```
|
90
79
|
|
@@ -128,10 +117,10 @@ client.chat('Be poetic.', stream:)
|
|
128
117
|
`format` takes an optional symbol (`:json`) and that setes the `response_format` to `json_object`:
|
129
118
|
|
130
119
|
```ruby
|
131
|
-
completion = client.chat(
|
132
|
-
|
133
|
-
|
134
|
-
|
120
|
+
completion = client.chat(format: :json) do |prompt|
|
121
|
+
prompt.system(OmniAI::Chat::JSON_PROMPT)
|
122
|
+
prompt.user('What is the name of the drummer for the Beatles?')
|
123
|
+
end
|
135
124
|
JSON.parse(completion.choice.message.content) # { "name": "Ringo" }
|
136
125
|
```
|
137
126
|
|
data/lib/omniai/openai/chat.rb
CHANGED
@@ -3,6 +3,14 @@
|
|
3
3
|
module OmniAI
|
4
4
|
module OpenAI
|
5
5
|
# An OpenAI chat implementation.
|
6
|
+
#
|
7
|
+
# Usage:
|
8
|
+
#
|
9
|
+
# completion = OmniAI::OpenAI::Chat.process!(client: client) do |prompt|
|
10
|
+
# prompt.system('You are an expert in the field of AI.')
|
11
|
+
# prompt.user('What are the biggest risks of AI?')
|
12
|
+
# end
|
13
|
+
# completion.choice.message.content # '...'
|
6
14
|
class Chat < OmniAI::Chat
|
7
15
|
JSON_RESPONSE_FORMAT = { type: 'json_object' }.freeze
|
8
16
|
|
@@ -20,7 +28,7 @@ module OmniAI
|
|
20
28
|
# @return [Hash]
|
21
29
|
def payload
|
22
30
|
OmniAI::OpenAI.config.chat_options.merge({
|
23
|
-
messages
|
31
|
+
messages: @prompt.serialize,
|
24
32
|
model: @model,
|
25
33
|
stream: @stream.nil? ? nil : !@stream.nil?,
|
26
34
|
temperature: @temperature,
|
data/lib/omniai/openai/client.rb
CHANGED
@@ -69,9 +69,12 @@ module OmniAI
|
|
69
69
|
# @param stream [Proc, nil] optional
|
70
70
|
# @param tools [Array<OmniAI::Tool>, nil] optional
|
71
71
|
#
|
72
|
+
# @yield [prompt]
|
73
|
+
# @yieldparam prompt [OmniAI::Chat::Prompt]
|
74
|
+
#
|
72
75
|
# @return [OmniAI::Chat::Completion]
|
73
|
-
def chat(messages, model: Chat::DEFAULT_MODEL, temperature: nil, format: nil, stream: nil, tools: nil)
|
74
|
-
Chat.process!(messages, model:, temperature:, format:, stream:, tools:, client: self)
|
76
|
+
def chat(messages, model: Chat::DEFAULT_MODEL, temperature: nil, format: nil, stream: nil, tools: nil, &)
|
77
|
+
Chat.process!(messages, model:, temperature:, format:, stream:, tools:, client: self, &)
|
75
78
|
end
|
76
79
|
|
77
80
|
# @raise [OmniAI::Error]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniai-openai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Sylvestre
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-07-
|
11
|
+
date: 2024-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: event_stream_parser
|