omniai-openai 1.5.0 → 1.6.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: 9541bdbe54c24be244b7bacd347eb4457d2f8686151cec1d4474889bf23bf6d0
4
- data.tar.gz: 5fabc408441ca53da67d05f221d14cb74f6c178e30696ec1a76598adb18ec4c8
3
+ metadata.gz: ccfa9de2275327a63e5e187d40050fe86c5c22098a1caf03418fd34e3bd87462
4
+ data.tar.gz: 163cbd9b4dab840e0d16dbb7677c4caab56552717a6dbba27afb3326832b70c6
5
5
  SHA512:
6
- metadata.gz: 48b237f8d606fff3d8db2aecac46633d6bebbae3c403ce2f68d9d87ecac0fe7beb101ada9be12d15e2d1bf734ef86dab92ff7cbf56298311634e44584b9b7cce
7
- data.tar.gz: 4627a44685b895c4b2616de3a88ba8b4bb63b038efc7f0536aacc7b9108e373f78d690acdc5adc99635dc9c8e10c6b1e59161643fdf7c3db283a012f1166a9bb
6
+ metadata.gz: 7ce15471f2609194788cfef73679e8c95bae0d9b011aecdc1087fe3f546239be4ca9053de3e4100808b403a34bb8d997a76a67d66b299afae426a812bd35f430
7
+ data.tar.gz: d0d1e276d090972077b51de2fab52f710fff7f2cd78b22a95cb3b7dbea23eac64d3d3f48d5f584abf3b108a24b8566946e23f81ccb78d92752b04fcd6067dd1e
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
- role: OmniAI::Chat::Role::USER,
75
- content: 'Is it wise to jump off a bridge?'
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
- { role: OmniAI::Chat::Role::SYSTEM, content: OmniAI::Chat::JSON_PROMPT },
133
- { role: OmniAI::Chat::Role::USER, content: 'What is the name of the drummer for the Beatles?' }
134
- ], format: :json)
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
 
@@ -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,
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAI
4
4
  module OpenAI
5
- VERSION = '1.5.0'
5
+ VERSION = '1.6.0'
6
6
  end
7
7
  end
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.5.0
4
+ version: 1.6.0
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 00:00:00.000000000 Z
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