openaiext 0.0.1 → 0.0.2

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: 4622de30e5df0ef4fd41d49f329dd9ec64ca84f87bf8be59dbf3301e75b99429
4
- data.tar.gz: fbd7a1741c752c1852f7d7962aaa44bb2dcbf641029de864963783d3b3d2f6a4
3
+ metadata.gz: 276d45b2a3e4b7e984a1fe2dbc7a05275500c8e15f0e331fe2a2f980db72dea0
4
+ data.tar.gz: 3366f551da7e14cfb6b0f273e352d79e9eb2c9eb159eb579b4e426f522d3e800
5
5
  SHA512:
6
- metadata.gz: bd2d2f0ccda1be4e864414de652fbb628f16b172e786d6f8ba45266009829ceda9dacd9996a9af12bf2be63f2eb322363374942b5d6ddbac3edbca5bc61edbdb
7
- data.tar.gz: 0ad5bb389487ccd355ae6cb0ac23080eb713b465434b189fe7c86ecedab1301ad7dbd7106ca24c2e5f26c8e2a1223b44a827774df8b14d6d007020fad428b1c4
6
+ metadata.gz: 38cd47294905c538f82f2a594148e4e8e64fb63caf9858be1f3efdd44613890654f941baab616e4f524f47cacaa5266809c23df9a0a87c360e4ebe70b4783d20
7
+ data.tar.gz: 6705205f99790956d259acc4793444d3c5740e656cf0e05427aa9f01bd1df0b8941363850793c146cf8bfe898f1cd267d08e7e052bb8d82e7fef20f5b9da5749
@@ -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')
@@ -33,7 +28,7 @@ module OpenAIExt
33
28
  end
34
29
 
35
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)
36
- model = select_model(model)
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)
@@ -69,19 +64,4 @@ module OpenAIExt
69
64
  end
70
65
 
71
66
  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
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openaiext
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gedean Dias
@@ -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: