openaiext 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/openaiext/agent.rb +1 -1
- data/lib/openaiext/model.rb +24 -0
- data/lib/openaiext.rb +12 -27
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 321e5e7aaba2691bcc8f5fbf258bd33551920d474cee4bcdfcdde4dae744b937
|
4
|
+
data.tar.gz: 9bc3fe053ae856d540925b6dc2815cf345383572cf2243c886589119649424ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a244914cf823cb4fc0c6d1ec678858ad8a0467c015c6535cfcde6fa1756d1f4a67b0ecd1b4a23c8aff35d0dc3e84f01e0af0aa1fd6571c60b1a5033a02d2c448
|
7
|
+
data.tar.gz: 207768e9d24034baea6278ff4c4f3fc03a664bc29d82904f65f143ca3e3a6cf2f7563bc77765ec0c5298685c0301f8abbacf03711c5c529f79ad6b4e8258937f
|
data/lib/openaiext/agent.rb
CHANGED
@@ -36,7 +36,7 @@ module OpenAIExt
|
|
36
36
|
|
37
37
|
params[:additional_messages] = [{ role: :user, content: additional_message }] unless additional_message.nil?
|
38
38
|
|
39
|
-
params[:model] = model || @assistant['model']
|
39
|
+
params[:model] = OpenAIExt::Model.select(model) || @assistant['model']
|
40
40
|
|
41
41
|
run_id = @openai_client.runs.create(thread_id: @thread['id'], parameters: params)['id']
|
42
42
|
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module OpenAIExt
|
2
|
+
module Model
|
3
|
+
GPT_BASIC_MODEL = ENV.fetch('OPENAI_GPT_BASIC_MODEL', 'gpt-4o-mini')
|
4
|
+
GPT_ADVANCED_MODEL = ENV.fetch('OPENAI_GPT_ADVANCED_MODEL', 'gpt-4o-2024-08-06')
|
5
|
+
|
6
|
+
O1_BASIC_MODEL = ENV.fetch('OPENAI_O1_BASIC_MODEL', 'o1-mini')
|
7
|
+
O1_ADVANCED_MODEL = ENV.fetch('OPENAI_O1_ADVANCED_MODEL', 'o1-preview')
|
8
|
+
|
9
|
+
def self.select(model)
|
10
|
+
case model
|
11
|
+
when :gpt_basic
|
12
|
+
GPT_BASIC_MODEL
|
13
|
+
when :gpt_advanced
|
14
|
+
GPT_ADVANCED_MODEL
|
15
|
+
when :o1_basic
|
16
|
+
O1_BASIC_MODEL
|
17
|
+
when :o1_advanced
|
18
|
+
O1_ADVANCED_MODEL
|
19
|
+
else
|
20
|
+
model
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/openaiext.rb
CHANGED
@@ -1,16 +1,11 @@
|
|
1
1
|
require 'openai'
|
2
2
|
|
3
|
+
require 'openaiext/model'
|
3
4
|
require 'openaiext/messages'
|
4
5
|
require 'openaiext/response_extender'
|
5
6
|
require 'openaiext/agent'
|
6
7
|
|
7
8
|
module OpenAIExt
|
8
|
-
GPT_BASIC_MODEL = ENV.fetch('OPENAI_GPT_BASIC_MODEL', 'gpt-4o-mini')
|
9
|
-
GPT_ADVANCED_MODEL = ENV.fetch('OPENAI_GPT_ADVANCED_MODEL', 'gpt-4o-2024-08-06')
|
10
|
-
|
11
|
-
O1_BASIC_MODEL = ENV.fetch('OPENAI_O1_BASIC_MODEL', 'o1-mini')
|
12
|
-
O1_ADVANCED_MODEL = ENV.fetch('OPENAI_O1_ADVANCED_MODEL', 'o1-preview')
|
13
|
-
|
14
9
|
MAX_TOKENS = ENV.fetch('OPENAI_MAX_TOKENS', 16_383).to_i
|
15
10
|
|
16
11
|
def self.embeddings(input, model: 'text-embedding-3-large')
|
@@ -24,16 +19,16 @@ module OpenAIExt
|
|
24
19
|
chat(messages: [{ role: :user, content: message_content }], model:, response_format:, max_tokens:, store:, tools:, auto_run_functions:, function_context:)
|
25
20
|
end
|
26
21
|
|
27
|
-
def self.single_prompt(prompt:, model: :gpt_basic, response_format: nil, max_tokens: MAX_TOKENS, store: true, metadata: nil, tools: nil, auto_run_functions: false, function_context: nil)
|
28
|
-
chat(messages: [{ user: prompt }], model:, response_format:, max_tokens:, store:, tools:, auto_run_functions:, function_context:)
|
22
|
+
def self.single_prompt(prompt:, model: :gpt_basic, response_format: nil, max_tokens: MAX_TOKENS, store: true, metadata: nil, tools: nil, auto_run_functions: false, function_context: nil, temperature: nil, top_p: nil, frequency_penalty: nil, presence_penalty: nil)
|
23
|
+
chat(messages: [{ user: prompt }], model:, response_format:, max_tokens:, store:, tools:, auto_run_functions:, function_context:, temperature:, top_p:, frequency_penalty:, presence_penalty:)
|
29
24
|
end
|
30
25
|
|
31
|
-
def self.single_chat(system:, user:, model: :gpt_basic, response_format: nil, max_tokens: MAX_TOKENS, store: true, metadata: nil, tools: nil, auto_run_functions: false, function_context: nil)
|
32
|
-
chat(messages: [{ system: }, { user: }], model:, response_format:, max_tokens:, store:, tools:, auto_run_functions:, function_context:)
|
26
|
+
def self.single_chat(system:, user:, model: :gpt_basic, response_format: nil, max_tokens: MAX_TOKENS, store: true, metadata: nil, tools: nil, auto_run_functions: false, function_context: nil, temperature: nil, top_p: nil, frequency_penalty: nil, presence_penalty: nil)
|
27
|
+
chat(messages: [{ system: }, { user: }], model:, response_format:, max_tokens:, store:, tools:, auto_run_functions:, function_context:, temperature:, top_p:, frequency_penalty:, presence_penalty:)
|
33
28
|
end
|
34
29
|
|
35
|
-
def self.chat(messages:, model: :gpt_basic, response_format: nil, max_tokens: MAX_TOKENS, store: true, metadata: nil, tools: nil, auto_run_functions: false, function_context: nil)
|
36
|
-
model =
|
30
|
+
def self.chat(messages:, model: :gpt_basic, response_format: nil, max_tokens: MAX_TOKENS, store: true, metadata: nil, tools: nil, auto_run_functions: false, function_context: nil, temperature: nil, top_p: nil, frequency_penalty: nil, presence_penalty: nil)
|
31
|
+
model = OpenAIExt::Model.select(model)
|
37
32
|
is_o1_model = model.start_with?('o1')
|
38
33
|
|
39
34
|
messages = OpenAIExt::Messages.new(messages) unless messages.is_a?(OpenAIExt::Messages)
|
@@ -48,6 +43,11 @@ module OpenAIExt
|
|
48
43
|
parameters[:response_format] = { type: 'json_object' } if response_format.eql?(:json)
|
49
44
|
parameters[:tools] = tools if tools
|
50
45
|
|
46
|
+
parameters[:temperature] = temperature if temperature
|
47
|
+
parameters[:top_p] = top_p if top_p
|
48
|
+
parameters[:frequency_penalty] = frequency_penalty if frequency_penalty
|
49
|
+
parameters[:presence_penalty] = presence_penalty if presence_penalty
|
50
|
+
|
51
51
|
begin
|
52
52
|
response = OpenAI::Client.new.chat(parameters:)
|
53
53
|
rescue => e
|
@@ -69,19 +69,4 @@ module OpenAIExt
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def self.models = OpenAI::Client.new.models.list
|
72
|
-
|
73
|
-
def self.select_model(model)
|
74
|
-
case model
|
75
|
-
when :gpt_basic
|
76
|
-
GPT_BASIC_MODEL
|
77
|
-
when :gpt_advanced
|
78
|
-
GPT_ADVANCED_MODEL
|
79
|
-
when :o1_basic
|
80
|
-
O1_BASIC_MODEL
|
81
|
-
when :o1_advanced
|
82
|
-
O1_ADVANCED_MODEL
|
83
|
-
else
|
84
|
-
model
|
85
|
-
end
|
86
|
-
end
|
87
72
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openaiext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gedean Dias
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-openai
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- lib/openaiext.rb
|
63
63
|
- lib/openaiext/agent.rb
|
64
64
|
- lib/openaiext/messages.rb
|
65
|
+
- lib/openaiext/model.rb
|
65
66
|
- lib/openaiext/response_extender.rb
|
66
67
|
homepage: https://github.com/gedean/openaiext
|
67
68
|
licenses:
|