omniai 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +41 -3
- data/lib/omniai/chat/content.rb +18 -0
- data/lib/omniai/config.rb +6 -0
- data/lib/omniai/version.rb +1 -1
- data/lib/omniai.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d90d000047c670a17478146fa35fca9c993127067b01b11113cc46e739d15e2
|
4
|
+
data.tar.gz: d025855eb6ea4ae79bc7c126a2853fff7a6a0e21d597fa86b2efb6b8d1c3ddf1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 77247cd74f88fdaa527b377940f32cfaad187c26f8ae4c6f373c708c866ce5c956c0436194786acb474ae07f423ea83511df6bbd5029c91247aff4b5d8ee2891
|
7
|
+
data.tar.gz: c7d3a40a6c21fe1827b162e94eae0dd0d2f66014797e4d878fa6c7aacf17c443412fcefa2f4bc0ad008f7b64b41ab4e2d583109990d6418d77451f1ba67b4fbd
|
data/README.md
CHANGED
@@ -60,19 +60,57 @@ client = OmniAI::OpenAI::Client.new
|
|
60
60
|
|
61
61
|
### Chat
|
62
62
|
|
63
|
-
Clients that support chat (e.g. Anthropic w/ "Claude", Google w/ "Gemini", Mistral w/ "LeChat", OpenAI w/ "ChatGPT", etc)
|
63
|
+
Clients that support chat (e.g. Anthropic w/ "Claude", Google w/ "Gemini", Mistral w/ "LeChat", OpenAI w/ "ChatGPT", etc) generate completions using the following calls:
|
64
64
|
|
65
|
-
####
|
65
|
+
#### w/ a Simple Prompt
|
66
66
|
|
67
67
|
```ruby
|
68
68
|
completion = client.chat.completion('Tell me a joke.')
|
69
69
|
puts(completion.choice.message.content) # '...'
|
70
70
|
```
|
71
71
|
|
72
|
+
#### w/ a Collection of Messages
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
messages = [
|
76
|
+
{
|
77
|
+
role: 'system',
|
78
|
+
content: 'You are a helpful assistant with an expertise in geography.',
|
79
|
+
},
|
80
|
+
{
|
81
|
+
role: 'user',
|
82
|
+
content: 'What is the capital of Canada?',
|
83
|
+
},
|
84
|
+
]
|
85
|
+
completion = client.chat.completion(messages, model: '...', temperature: 0.7, format: :json)
|
86
|
+
puts(completion.choice.message.content) # '...'
|
87
|
+
```
|
88
|
+
|
89
|
+
#### w/ a Collection of Files
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
|
93
|
+
image_a_url = "https://images.unsplash.com/photo-1517849845537-4d257902454a?w=800&h=800&format=jpeg&fit=crop"
|
94
|
+
image_b_url = "https://images.unsplash.com/photo-1537151625747-768eb6cf92b2?q=80&w=1024&h=1024&format=jpeg"
|
95
|
+
|
96
|
+
message = {
|
97
|
+
role: 'user',
|
98
|
+
content: [
|
99
|
+
OmniAI::Chat::Content.new('What are in these images and are they different?'),
|
100
|
+
OmniAI::Chat::Content.new(image_a_url, type: :image),
|
101
|
+
OmniAI::Chat::Content.new(image_b_url, type: :image),
|
102
|
+
]
|
103
|
+
}
|
104
|
+
|
105
|
+
completion = client.chat.completion(message)
|
106
|
+
puts(completion.choice.message.content) # '...'
|
107
|
+
```
|
108
|
+
|
72
109
|
#### Streaming
|
73
110
|
|
74
111
|
```ruby
|
75
|
-
|
112
|
+
stream = proc do |chunk|
|
76
113
|
print(chunk.choice.delta.content) # '...'
|
77
114
|
end
|
115
|
+
client.chat.completion('Tell me a joke.', stream:)
|
78
116
|
```
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OmniAI
|
4
|
+
class Chat
|
5
|
+
# A file used for analysis.
|
6
|
+
class Content
|
7
|
+
attr_accessor :type, :value
|
8
|
+
|
9
|
+
# @param url [String]
|
10
|
+
# @param text [String]
|
11
|
+
# @param type [Symbol] :image / :video / :audio / :text
|
12
|
+
def initialize(value, type: :text)
|
13
|
+
@value = value
|
14
|
+
@type = type
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/omniai/version.rb
CHANGED
data/lib/omniai.rb
CHANGED
@@ -16,7 +16,7 @@ module OmniAI
|
|
16
16
|
|
17
17
|
# @param response [HTTP::Response]
|
18
18
|
def initialize(response)
|
19
|
-
super("status=#{response.status.inspect} headers=#{response.headers.inspect} body=#{response.body
|
19
|
+
super("status=#{response.status.inspect} headers=#{response.headers.inspect} body=#{response.body}")
|
20
20
|
@response = response
|
21
21
|
end
|
22
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
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-06-
|
11
|
+
date: 2024-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: event_stream_parser
|
@@ -69,11 +69,13 @@ files:
|
|
69
69
|
- lib/omniai/chat/choice.rb
|
70
70
|
- lib/omniai/chat/chunk.rb
|
71
71
|
- lib/omniai/chat/completion.rb
|
72
|
+
- lib/omniai/chat/content.rb
|
72
73
|
- lib/omniai/chat/delta.rb
|
73
74
|
- lib/omniai/chat/message.rb
|
74
75
|
- lib/omniai/chat/request.rb
|
75
76
|
- lib/omniai/chat/usage.rb
|
76
77
|
- lib/omniai/client.rb
|
78
|
+
- lib/omniai/config.rb
|
77
79
|
- lib/omniai/version.rb
|
78
80
|
homepage: https://github.com/ksylvest/omniai
|
79
81
|
licenses: []
|