appchat 0.0.6 → 0.0.7
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 +4 -4
- data/lib/generators/appchat/appchat_generator.rb +3 -1
- data/lib/generators/appchat/templates/get_ai_response_job.rb +5 -4
- data/lib/generators/appchat/templates/javascript/toggle_controller.js +15 -0
- data/lib/generators/appchat/templates/messages/_function_logs.html.erb +12 -0
- data/lib/generators/appchat/templates/messages/message.html.erb +2 -0
- data/lib/generators/appchat/templates/models/message.rb +2 -0
- data/lib/generators/appchat/templates/services/web_search_service.rb +5 -11
- 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: 0f2e478412edcf3880d15f39ad4aeedbbf73a1a4819c0b270cf1505d3c47b826
|
4
|
+
data.tar.gz: 4cc000f36710cda913c9474e04c3c55fc221170811fde494392cb6d19c3795ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6d2310e575c27c6401a2a74afe7c099c9e7dff546dd1220781dbcce74482e2f61af439c9634c1e06ae5c0589f2873ba919a9552f306507e0b2a03dcdaca2c0e
|
7
|
+
data.tar.gz: 2b5b16b39b719650c33ef334f3ceb415fcc445c4a7fa28284b19969ee2a8fd1d69735208148d961c4ebb5852bda67cb8e65a5d29830e1249d35cab53cc64141b
|
@@ -12,7 +12,6 @@ class AppchatGenerator < Rails::Generators::Base
|
|
12
12
|
gems = %w(
|
13
13
|
ollama-ai
|
14
14
|
tailwindcss-rails
|
15
|
-
watir
|
16
15
|
)
|
17
16
|
|
18
17
|
gems.each do |gem|
|
@@ -40,6 +39,7 @@ class AppchatGenerator < Rails::Generators::Base
|
|
40
39
|
generate "model", "Message chat:references content:text role:integer status:string"
|
41
40
|
generate "model", "AppchatFunction name:string description:text class_name:string"
|
42
41
|
generate "model", "FunctionParameter appchat_function:references name:string example_value:string"
|
42
|
+
generate "model", "FunctionLog message:references name:string prompt:text results:text"
|
43
43
|
end
|
44
44
|
|
45
45
|
def create_controllers
|
@@ -55,6 +55,7 @@ class AppchatGenerator < Rails::Generators::Base
|
|
55
55
|
copy_file "messages/new.html.erb", "app/views/messages/new.html.erb", force: true
|
56
56
|
copy_file "messages/message.html.erb", "app/views/messages/_message.html.erb", force: true
|
57
57
|
copy_file "messages/_typing_bubbles.html.erb", "app/views/messages/_typing_bubbles.html.erb", force: true
|
58
|
+
copy_file "messages/_function_logs.html.erb", "app/views/messages/_function_logs.html.erb", force: true
|
58
59
|
end
|
59
60
|
|
60
61
|
def create_stylesheets
|
@@ -64,6 +65,7 @@ class AppchatGenerator < Rails::Generators::Base
|
|
64
65
|
def create_stimulus_controllers
|
65
66
|
copy_file "javascript/chat_message_controller.js", "app/javascript/controllers/chat_message_controller.js"
|
66
67
|
copy_file "javascript/speech_to_text_controller.js", "app/javascript/controllers/speech_to_text_controller.js"
|
68
|
+
copy_file "javascript/toggle_controller.js", "app/javascript/controllers/toggle_controller.js"
|
67
69
|
end
|
68
70
|
|
69
71
|
def copy_models
|
@@ -45,16 +45,17 @@ class GetAiResponseJob < ApplicationJob
|
|
45
45
|
def appchat_functions
|
46
46
|
appchat_function_service = AppchatFunctionService.new(chat.id, user_prompt).run
|
47
47
|
if appchat_function_service["match"] == "true" && appchat_function_service["appchat_function"].in?(AppchatFunction.pluck(:class_name))
|
48
|
-
puts "Function Match Found! --> #{appchat_function_service}"
|
48
|
+
puts "Function Match Found! --> #{ appchat_function_service }"
|
49
|
+
|
50
|
+
function_log = message.function_logs.create(name: appchat_function_service["appchat_function"], prompt: appchat_function_service["parameters"])
|
49
51
|
function_class = appchat_function_service["appchat_function"].constantize
|
50
52
|
function_response = function_class.new(appchat_function_service["parameters"]).run do |status|
|
51
53
|
message.update(status: status)
|
52
54
|
end
|
53
55
|
|
54
56
|
return if function_response.nil?
|
55
|
-
|
56
|
-
|
57
|
-
:current_time => #{Date.current}"
|
57
|
+
function_log.update(results: function_response)
|
58
|
+
@informed_prompt = "The user prompted: #{ user_prompt }, to help you answer the user, an appchat function called #{ function_class } provided this data #{ function_response }"
|
58
59
|
end
|
59
60
|
end
|
60
61
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
2
|
+
|
3
|
+
export default class extends Controller {
|
4
|
+
static targets = ["content", "icon"]
|
5
|
+
|
6
|
+
toggle() {
|
7
|
+
this.contentTarget.classList.toggle("hidden")
|
8
|
+
if (this.contentTarget.classList.contains("hidden")) {
|
9
|
+
this.iconTarget.textContent = "Expand"
|
10
|
+
} else {
|
11
|
+
this.iconTarget.textContent = "Collapse"
|
12
|
+
}
|
13
|
+
}
|
14
|
+
}
|
15
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<div data-controller="toggle">
|
2
|
+
<%= message.function_logs.count %> Function calls informed this message.
|
3
|
+
<i data-toggle-target="icon" data-action="click->toggle#toggle" class="icon-class">Expand</i>
|
4
|
+
|
5
|
+
<div data-toggle-target="content" class="hidden bg-white">
|
6
|
+
<% message.function_logs.each do |log| %>
|
7
|
+
<p> Name: <%= log.name %> </p>
|
8
|
+
<p> Parameters: <%= log.prompt %> </p>
|
9
|
+
<p> Response: <%= log.results %> </p>
|
10
|
+
<% end %>
|
11
|
+
</div>
|
12
|
+
</div>
|
@@ -1,4 +1,6 @@
|
|
1
1
|
<div data-chat-message-target="message" id="<%= dom_id(message) %>" class="bg-gray-200 text-gray-900 shadow-lg p-4 rounded-lg">
|
2
|
+
<%= render partial: 'messages/function_logs', locals: { message: message } if message.function_logs.present? %>
|
3
|
+
|
2
4
|
<% if message.status? && !message.content? %>
|
3
5
|
<%= message.status %>
|
4
6
|
<% elsif message.content? %>
|
@@ -1,23 +1,17 @@
|
|
1
|
-
require 'watir'
|
2
1
|
require 'cgi'
|
2
|
+
require 'open-uri'
|
3
3
|
|
4
4
|
class WebSearchService
|
5
5
|
attr_reader :query
|
6
|
-
|
7
6
|
def initialize(args)
|
8
7
|
@query = args["query"]
|
9
8
|
end
|
10
9
|
|
11
10
|
def run
|
12
|
-
yield("Searching Google for #{
|
11
|
+
yield("Searching Google for #{query}")
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
response = "browser_text: #{browser.text} browser_links: #{browser.links}"
|
18
|
-
browser.close
|
19
|
-
response
|
20
|
-
rescue Selenium::WebDriver::Error::UnknownError => e
|
21
|
-
"Error: #{e.message}"
|
13
|
+
doc = Nokogiri::HTML(URI.open("https://www.google.com/search?q=#{CGI.escape(query)}").read.force_encoding('UTF-8'))
|
14
|
+
doc.css('script, style, noscript, comment').remove
|
15
|
+
doc.css('h1, h2, h3, h4, h5, h6, p').map(&:text).join("\n").strip
|
22
16
|
end
|
23
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appchat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hackliteracy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,6 +81,8 @@ files:
|
|
81
81
|
- lib/generators/appchat/templates/get_ai_response_job.rb
|
82
82
|
- lib/generators/appchat/templates/javascript/chat_message_controller.js
|
83
83
|
- lib/generators/appchat/templates/javascript/speech_to_text_controller.js
|
84
|
+
- lib/generators/appchat/templates/javascript/toggle_controller.js
|
85
|
+
- lib/generators/appchat/templates/messages/_function_logs.html.erb
|
84
86
|
- lib/generators/appchat/templates/messages/_typing_bubbles.html.erb
|
85
87
|
- lib/generators/appchat/templates/messages/index.html.erb
|
86
88
|
- lib/generators/appchat/templates/messages/message.html.erb
|