scout-ai 1.1.7 → 1.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e939ad5a06a271bd6379845c3c3f119c2191dcbe250482b622d83cc03c5a27a
4
- data.tar.gz: '009d4893f3a473f48149db3bed025ebd8d2603295a525f99a86c07437dd1340d'
3
+ metadata.gz: f6c4a5eda08ca50c1353e6b36d41bc0b5c8ac1c6a58d40b48f23f005c8566c84
4
+ data.tar.gz: e61823c2c1344aaab60ed78504db4edbfa3776442436da2e58399619407159f0
5
5
  SHA512:
6
- metadata.gz: ae56ea4a63d69ae58ceaeb4dcf76196c25c1a75a68590ae36031d088181c213bbbc2ace780229e9923f3260ec0e330fbc6f7b6844201804e5daa460c865c11fb
7
- data.tar.gz: 28803032d0d2666384f0dcbbbb809544e11649a460bd331807fa94df13bb9c7d391d6622cb91599dc9ad155775d0b14b8835203ac87b0fbfbce6d22aabc878d4
6
+ metadata.gz: 75a8092ba29b8d75a141c0abff7d519e91f140e56b0220ba4a59512fcc9172aa13b9b068face217f418ec2afc3ef4f0377dac4e0d124b6399bc033b9d2a0bf6f
7
+ data.tar.gz: 1aac91f51c220a78c5f1a4d3aa77a7ccf07d7a8929f20a869ec702e67deff7d43a18d8c19913005b99dace1666a73715ee0fa9cafbfacccfb78f2ed60493482d
data/.vimproject CHANGED
@@ -8,6 +8,7 @@ scout-ai=$PWD filter="*.rb *.rake Rakefile *.rdoc *.R *.sh *.js *.haml *.sass *.
8
8
  chats=chats filter="*"{
9
9
  agent_doc
10
10
 
11
+ tool_oeu
11
12
 
12
13
  multi_agent.rb
13
14
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.7
1
+ 1.1.8
@@ -1,21 +1,22 @@
1
1
  require 'openai'
2
2
  require 'rest-client'
3
3
  require_relative '../chat'
4
+ require_relative 'openai'
4
5
 
5
6
  module LLM
6
7
  module OpenWebUI
7
8
 
8
9
  def self.rest(method, base_url, key, action, options = {})
9
10
  url = File.join(base_url, action.to_s)
10
- headers = {"Authorization" => "Bearer #{key}", "Content-Type" => "application/json"}
11
+ headers = IndiferentHash.setup({"Authorization" => "Bearer #{key}", "Content-Type" => "application/json"})
11
12
  response = case method.to_sym
12
13
  when :post
13
14
  #RestClient.send(method, url, options, {content_type: "application/json", accept: "application/json", Authorization: "Bearer #{key}"})
14
- iii [url, options, headers]
15
15
  RestClient.post(url, options.to_json, headers)
16
16
  else
17
17
  RestClient.send(method, url, {content_type: "application/json", accept: "application/json", "Authorization" => "Bearer #{key}"})
18
18
  end
19
+
19
20
  JSON.parse(response.body)
20
21
  end
21
22
 
@@ -23,9 +24,9 @@ module LLM
23
24
 
24
25
  url, key, model, log_errors = IndiferentHash.process_options options, :url, :key, :model, :log_errors
25
26
 
26
- url ||= Scout::Config.get(:url, :openai_ask, :ask, :openai, env: 'OPENWEBUI_URL', default: "http://localhost:3000/api")
27
- key ||= LLM.get_url_config(:key, url, :openai_ask, :ask, :openai, env: 'OPENWEBUI_KEY')
28
- model ||= LLM.get_url_config(:model, url, :openai_ask, :ask, :openai, env: 'OPENWEBUI_MODEL')
27
+ url ||= Scout::Config.get(:url, :openwebui_ask, :ask, :openwebui, env: 'OPENWEBUI_URL', default: "http://localhost:3000/api")
28
+ key ||= LLM.get_url_config(:key, url, :openwebui_ask, :ask, :openwebui, env: 'OPENWEBUI_KEY')
29
+ model ||= LLM.get_url_config(:model, url, :openwebui_ask, :ask, :openwebui, env: 'OPENWEBUI_MODEL')
29
30
 
30
31
  role = IndiferentHash.process_options options, :role
31
32
  messages = LLM.messages(question, role)
@@ -56,5 +57,79 @@ module LLM
56
57
 
57
58
  message.dig("content")
58
59
  end
60
+
61
+ def self.ask(question, options = {}, &block)
62
+ original_options = options.dup
63
+
64
+ messages = LLM.chat(question)
65
+ options = options.merge LLM.options messages
66
+
67
+ client, url, key, model, log_errors, return_messages, format, tool_choice_next, previous_response_id, tools, = IndiferentHash.process_options options,
68
+ :client, :url, :key, :model, :log_errors, :return_messages, :format, :tool_choice_next, :previous_response_id, :tools,
69
+ log_errors: true, tool_choice_next: :none
70
+
71
+ if client.nil?
72
+ url ||= Scout::Config.get(:url, :openwebui_ask, :ask, :openwebui, env: 'OPENWEBUI_URL', default: "http://localhost:3000/api")
73
+ key ||= LLM.get_url_config(:key, url, :openwebui_ask, :ask, :openwebui, env: 'OPENWEBUI_KEY')
74
+ end
75
+
76
+ if model.nil?
77
+ url ||= Scout::Config.get(:url, :openai_ask, :ask, :openai, env: 'OPENAI_URL')
78
+ model ||= LLM.get_url_config(:model, url, :openai_ask, :ask, :openai, env: 'OPENAI_MODEL', default: "gpt-4.1")
79
+ end
80
+
81
+ case format
82
+ when Hash
83
+ options[:response_format] = format
84
+ when 'json', 'json_object', :json, :json_object
85
+ options[:response_format] = {type: 'json_object'}
86
+ else
87
+ options[:response_format] = {type: format}
88
+ end if format
89
+
90
+ parameters = options.merge(model: model)
91
+
92
+ # Process tools
93
+
94
+ case tools
95
+ when Array
96
+ tools = tools.inject({}) do |acc,definition|
97
+ IndiferentHash.setup definition
98
+ name = definition.dig('name') || definition.dig('function', 'name')
99
+ acc.merge(name => definition)
100
+ end
101
+ when nil
102
+ tools = {}
103
+ end
104
+
105
+ tools.merge!(LLM.tools messages)
106
+ tools.merge!(LLM.associations messages)
107
+
108
+ if tools.any?
109
+ parameters[:tools] = LLM.tool_definitions_to_openai tools
110
+ end
111
+
112
+ messages = LLM::OpenAI.process_input messages
113
+
114
+ Log.debug "Calling openai #{url}: #{Log.fingerprint(parameters.except(:tools))}}"
115
+ Log.high "Tools: #{Log.fingerprint tools.keys}}" if tools
116
+
117
+ parameters[:messages] = LLM.tools_to_openai messages
118
+
119
+ response = LLM::OpenAI.process_response self.rest(:post, url, key, "chat/completions" , parameters), tools, &block
120
+
121
+ res = if response.last[:role] == 'function_call_output'
122
+ response + self.ask(messages + response, original_options.merge(tool_choice: tool_choice_next, return_messages: true, tools: tools ), &block)
123
+ else
124
+ response
125
+ end
126
+
127
+ if return_messages
128
+ res
129
+ else
130
+ res.last['content']
131
+ end
132
+ end
133
+
59
134
  end
60
135
  end
data/scout-ai.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: scout-ai 1.1.7 ruby lib
5
+ # stub: scout-ai 1.1.8 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "scout-ai".freeze
9
- s.version = "1.1.7".freeze
9
+ s.version = "1.1.8".freeze
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
@@ -13,7 +13,8 @@ user: write a script that sorts files in a directory
13
13
  user: write a script that sorts files in a directory
14
14
  EOF
15
15
 
16
- ppp LLM::OpenWebUI.ask prompt, model: 'mistral:latest', url: "http://gepeto.bsc.es/api"
16
+ #ppp LLM::OpenWebUI.ask prompt, model: 'ALIA-40b-instruct-2512-Q8_0:latest', url: "https://gepeto.bsc.es/api"
17
+ ppp LLM::OpenWebUI.ask prompt, model: 'qwen3-vl:30b', url: "https://gepeto.bsc.es/api"
17
18
  end
18
19
 
19
20
  def _test_tool
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scout-ai
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.7
4
+ version: 1.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez