geminiext 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +1 -0
- data/lib/geminiext.rb +23 -0
- data/lib/openaiext/messages.rb.disabled +34 -0
- data/lib/openaiext/model.rb.disabled +27 -0
- data/lib/openaiext/response_extender.rb.disabled +44 -0
- metadata +75 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0217cac9967438f0bbd4fe0dc38b6c0aba1d21475b937c6b4d1b4d41d51a12b6
|
4
|
+
data.tar.gz: df412fa82b43d42dcaca12b993cfa76f6c9e49dea76e55dfa9cbcddc79a9bee6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 884cdc51610f1d2beefd9884a4b779560adfff38c14deafc3bad84b3dc2ce84079cabf29eae88d96e6688d73dc25824d23eaea7fc2b379fac327de87974e29ea
|
7
|
+
data.tar.gz: e9f69ffe68c4434738612884e54f89d5e471016ee1425846d374f9efa80b13e3fb4210f3f21a3b088e292861717fe0fa3f45473414d28307ec5b63781fe84b3b
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# geminiext
|
data/lib/geminiext.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'gemini-ai'
|
2
|
+
|
3
|
+
# require 'geminiext/model'
|
4
|
+
# require 'geminiext/messages'
|
5
|
+
# require 'geminiext/response_extender'
|
6
|
+
|
7
|
+
module GeminiExt
|
8
|
+
MAX_TOKENS = ENV.fetch('GEMINI_MAX_TOKENS', 8_192).to_i
|
9
|
+
|
10
|
+
def self.new(model: 'gemini-1.5-flash-001')
|
11
|
+
Gemini.new(load_config(model: model))
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.load_config(model: 'gemini-1.5-flash-001')
|
15
|
+
{
|
16
|
+
credentials: {
|
17
|
+
service: 'generative-language-api',
|
18
|
+
api_key: ENV.fetch('GEMINI_API_KEY')
|
19
|
+
},
|
20
|
+
options: { model:}
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module geminiext
|
2
|
+
class Messages < Array
|
3
|
+
def initialize messages = nil
|
4
|
+
super parse_messages(messages)
|
5
|
+
end
|
6
|
+
|
7
|
+
def add(message) = concat(parse_messages(message))
|
8
|
+
|
9
|
+
private
|
10
|
+
def parse_messages(messages)
|
11
|
+
return [] if messages.nil?
|
12
|
+
|
13
|
+
messages = [messages] unless messages.is_a?(Array)
|
14
|
+
|
15
|
+
# if first element is ok, then do not parse the rest
|
16
|
+
return messages if messages.first in { role: String | Symbol, content: String | Array | Hash}
|
17
|
+
|
18
|
+
messages.flat_map do |msg|
|
19
|
+
if msg.is_a?(Hash)
|
20
|
+
if msg.keys.size == 1
|
21
|
+
role, content = msg.first
|
22
|
+
{ role: role.to_s, content: content }
|
23
|
+
elsif msg.key?(:role) && msg.key?(:content)
|
24
|
+
{ role: msg[:role].to_s, content: msg[:content] }
|
25
|
+
else
|
26
|
+
msg.map { |role, content| { role: role.to_s, content: content } }
|
27
|
+
end
|
28
|
+
else
|
29
|
+
raise ArgumentError, "Invalid message format: #{msg}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module geminiext
|
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')
|
5
|
+
GPT_ADVANCED_MODEL_LATEST = ENV.fetch('OPENAI_GPT_ADVANCED_MODEL_LATEST', 'chatgpt-4o-latest')
|
6
|
+
|
7
|
+
O1_BASIC_MODEL = ENV.fetch('OPENAI_O1_BASIC_MODEL', 'o1-mini')
|
8
|
+
O1_ADVANCED_MODEL = ENV.fetch('OPENAI_O1_ADVANCED_MODEL', 'o1-preview')
|
9
|
+
|
10
|
+
def self.select(model)
|
11
|
+
case model
|
12
|
+
when :gpt_basic
|
13
|
+
GPT_BASIC_MODEL
|
14
|
+
when :gpt_advanced
|
15
|
+
GPT_ADVANCED_MODEL
|
16
|
+
when :gpt_advanced_latest
|
17
|
+
GPT_ADVANCED_MODEL_LATEST
|
18
|
+
when :o1_basic
|
19
|
+
O1_BASIC_MODEL
|
20
|
+
when :o1_advanced
|
21
|
+
O1_ADVANCED_MODEL
|
22
|
+
else
|
23
|
+
model
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module ResponseExtender
|
2
|
+
def chat_params = self[:chat_params]
|
3
|
+
|
4
|
+
def message = dig('choices', 0, 'message')
|
5
|
+
|
6
|
+
def content = dig('choices', 0, 'message', 'content')
|
7
|
+
def content? = !content.nil?
|
8
|
+
|
9
|
+
def tool_calls = dig('choices', 0, 'message', 'tool_calls')
|
10
|
+
def tool_calls? = !tool_calls.nil?
|
11
|
+
|
12
|
+
def functions
|
13
|
+
return if tool_calls.nil?
|
14
|
+
|
15
|
+
functions = tool_calls.filter { |tool| tool['type'].eql? 'function' }
|
16
|
+
return if functions.empty?
|
17
|
+
|
18
|
+
functions_list = []
|
19
|
+
functions.map.with_index do |function, function_index|
|
20
|
+
function_info = tool_calls.dig(function_index, 'function')
|
21
|
+
function_def = { id: function['id'], name: function_info['name'], arguments: Oj.load(function_info['arguments'], symbol_keys: true) }
|
22
|
+
|
23
|
+
def function_def.run(context:)
|
24
|
+
{
|
25
|
+
tool_call_id: self[:id],
|
26
|
+
role: :tool,
|
27
|
+
name: self[:name],
|
28
|
+
content: context.send(self[:name], **self[:arguments])
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
functions_list << function_def
|
33
|
+
end
|
34
|
+
|
35
|
+
functions_list
|
36
|
+
end
|
37
|
+
|
38
|
+
def functions_run_all(context:)
|
39
|
+
raise 'No functions to run' if functions.nil?
|
40
|
+
functions.map { |function| function.run(context:) }
|
41
|
+
end
|
42
|
+
|
43
|
+
def functions? = !functions.nil?
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geminiext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gedean Dias
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-11-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: gemini-ai
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: oj
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3'
|
41
|
+
description: Based on gemini-ai, adds some extra features
|
42
|
+
email: gedean.dias@gmail.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- README.md
|
48
|
+
- lib/geminiext.rb
|
49
|
+
- lib/openaiext/messages.rb.disabled
|
50
|
+
- lib/openaiext/model.rb.disabled
|
51
|
+
- lib/openaiext/response_extender.rb.disabled
|
52
|
+
homepage: https://github.com/gedean/geminiext
|
53
|
+
licenses:
|
54
|
+
- MIT
|
55
|
+
metadata: {}
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '3'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubygems_version: 3.5.23
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: Ruby Gemini Extended
|
75
|
+
test_files: []
|