appchat 0.0.2 → 0.0.4

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: 673aa6b6d3460c98d8731fd03b68201bfdda69a190f3b3890b1c05160fd707f1
4
- data.tar.gz: 15fa530e300361c280054729fb325b2bf12bf169565f9b9602ceec763be3b6d8
3
+ metadata.gz: f741156bd18664bfb66a4700b633dad255bc2c5e41cacc6b297acbc6d67492b8
4
+ data.tar.gz: d4612a8a1ee88a6caf7bc4e039cf74fa44b369fe79b5d595b0e9544329749819
5
5
  SHA512:
6
- metadata.gz: 2afea783c7fdf8e72f42194d8be4b498250e726dde74fb99b5d177129f6140ee930cfc17fca8b6e9c6b971e6c458c82d2cf590acce9c67a8e712402a12b59eb0
7
- data.tar.gz: 8717c5896f4fe1e46499464dd6389f366147c43381a7eb03bea5e1871a42fd4a766c81d5da3ad21546e782c82b1704fa70997f33b04f288538091b40cf00d30a
6
+ metadata.gz: '0959e29a0ed53649f7f51523e5b4c6f4089b05449f8649165ed7bf7505bdb111774e0c24661e5344f0752df1fa08a38b250a3fe911543530adb7f8a3020f2bd6'
7
+ data.tar.gz: '08f3d14d68ea6c2cf9c50da6842051b78bafa250bf58fc77475e09c32090344d06fe4d98205294aa08e9331bf1817e8d5b23213da001b136dd1fb2101c98aca8'
@@ -24,7 +24,7 @@ class AppchatGenerator < Rails::Generators::Base
24
24
  end
25
25
 
26
26
  def generate_scaffolds
27
- generate "model", "Chat"
27
+ generate "model", "Chat context:text"
28
28
  route "resources :chats"
29
29
  generate "scaffold", "Message chat:references content:text role:integer"
30
30
  end
@@ -37,6 +37,8 @@ class AppchatGenerator < Rails::Generators::Base
37
37
  copy_file "messages/index.html.erb", "app/views/messages/index.html.erb", force: true
38
38
  copy_file "messages/new.html.erb", "app/views/messages/new.html.erb", force: true
39
39
  copy_file "messages/message.html.erb", "app/views/messages/_message.html.erb", force: true
40
+ copy_file "messages/_typing_bubbles.html.erb", "app/views/messages/_typing_bubbles.html.erb", force: true
41
+ copy_file "assets/appchat.tailwind.css", "app/assets/stylesheets/appchat.tailwind.css", force: true
40
42
  copy_file "javascript/chat_message_controller.js", "app/javascript/controllers/chat_message_controller.js"
41
43
  end
42
44
 
@@ -45,6 +47,10 @@ class AppchatGenerator < Rails::Generators::Base
45
47
  copy_file "models/chat.rb", "app/models/chat.rb", force: true
46
48
  end
47
49
 
50
+ def serialize_context
51
+ inject_into_class 'app/models/chat.rb', 'Chat', "serialize :context, coder:JSON, type: Array\n"
52
+ end
53
+
48
54
  def set_associations
49
55
  inject_into_class 'app/models/chat.rb', 'Chat', " has_many :messages, dependent: :destroy\n"
50
56
  end
@@ -76,6 +82,10 @@ class AppchatGenerator < Rails::Generators::Base
76
82
  ART
77
83
  end
78
84
 
85
+ def get_started
86
+ puts "Congratulations on setting up appchat! \n run bin/dev to spin up your app, and visit localhost:3000/chats to start chatting"
87
+ end
88
+
79
89
  private
80
90
 
81
91
  def gem_exists?(gem_name)
@@ -0,0 +1,62 @@
1
+ @tailwind base;
2
+ @tailwind components;
3
+ @tailwind utilities;
4
+
5
+
6
+
7
+ @layer components {
8
+
9
+ .typing {
10
+ background-color: #e0e0e0;
11
+ display: block;
12
+ width: 60px;
13
+ height: 40px;
14
+ border-radius: 20px;
15
+ margin: 0 1rem;
16
+ display: flex;
17
+ justify-content: center;
18
+ align-items: center;
19
+ }
20
+
21
+ .circle {
22
+ display: block;
23
+ height: 10px;
24
+ width: 10px;
25
+ border-radius: 50%;
26
+ background-color: #8d8d8d;
27
+ margin: 3px;
28
+ }
29
+
30
+ .circle.scaling {
31
+ animation: typing 1000ms ease-in-out infinite;
32
+ animation-delay: 3600ms;
33
+ }
34
+
35
+ .circle:nth-child(1) {
36
+ animation-delay: 0ms;
37
+ }
38
+
39
+ .circle:nth-child(2) {
40
+ animation-delay: 333ms;
41
+ }
42
+
43
+ .circle:nth-child(3) {
44
+ animation-delay: 666ms;
45
+ }
46
+
47
+ @keyframes typing {
48
+ 0% {
49
+ transform: scale(1);
50
+ }
51
+ 33% {
52
+ transform: scale(1);
53
+ }
54
+ 50% {
55
+ transform: scale(1.4);
56
+ }
57
+ 100% {
58
+ transform: scale(1);
59
+ }
60
+ }
61
+
62
+ }
@@ -1,5 +1,5 @@
1
1
  <%= link_to chat, data: { turbo_frame: :chat } do %>
2
2
  <div class="w-full text-gray-100 hover:text-green-500">
3
- <%= chat&.messages&.first&.content%>
3
+ <%= chat&.messages&.first&.content || "New AI chat conversation" %>
4
4
  </div>
5
5
  <% end %>
@@ -5,7 +5,7 @@
5
5
  </style>
6
6
  <div class="flex w-full">
7
7
  <%= turbo_stream_from :chats %>
8
- <div class="max-w-sm w-full flex flex-col gap-4 p-2 w-full flex-shrink-0 bg-[#2e2e2e] rounded-lg" id="chats">
8
+ <div class="max-w-sm w-full h-full flex flex-col gap-4 p-2 w-full flex-shrink-0 bg-[#2e2e2e] rounded-lg" id="chats">
9
9
  <%= link_to chats_path, data: { turbo_method: :post, turbo_frame: :chat }, class: "flex gap-2 justify-center items-center bg-gray-500 text-gray-100 rounded-lg p-2 text-center mr-auto" do %>
10
10
  <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">
11
11
  <path stroke-linecap="round" stroke-linejoin="round" d="M12 4.5v15m7.5-7.5h-15" />
@@ -22,6 +22,7 @@ class GetAiResponseJob < ApplicationJob
22
22
  {
23
23
  model: 'llama3.1',
24
24
  prompt: user_prompt,
25
+ context: chat.context,
25
26
  stream: true,
26
27
  }
27
28
  ) do |event, raw|
@@ -32,5 +33,6 @@ class GetAiResponseJob < ApplicationJob
32
33
  message.update(content: new_content)
33
34
  end
34
35
  end
36
+ chat.update(context: response.last["context"])
35
37
  end
36
38
  end
@@ -0,0 +1,5 @@
1
+ <div class="typing">
2
+ <span class="circle scaling"></span>
3
+ <span class="circle scaling"></span>
4
+ <span class="circle scaling"></span>
5
+ </div>
@@ -1,3 +1,7 @@
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
- <%= message.content %>
2
+ <% if message.content? %>
3
+ <%= message.content %>
4
+ <% else %>
5
+ <%= render 'messages/typing_bubbles' %>
6
+ <% end %>
3
7
  </div>
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.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - hackliteracy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-06 00:00:00.000000000 Z
11
+ date: 2024-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -73,12 +73,14 @@ extensions: []
73
73
  extra_rdoc_files: []
74
74
  files:
75
75
  - lib/generators/appchat/appchat_generator.rb
76
+ - lib/generators/appchat/templates/assets/appchat.tailwind.css
76
77
  - lib/generators/appchat/templates/chats/chat.html.erb
77
78
  - lib/generators/appchat/templates/chats/index.html.erb
78
79
  - lib/generators/appchat/templates/chats/show.html.erb
79
80
  - lib/generators/appchat/templates/chats_controller.rb
80
81
  - lib/generators/appchat/templates/get_ai_response_job.rb
81
82
  - lib/generators/appchat/templates/javascript/chat_message_controller.js
83
+ - lib/generators/appchat/templates/messages/_typing_bubbles.html.erb
82
84
  - lib/generators/appchat/templates/messages/index.html.erb
83
85
  - lib/generators/appchat/templates/messages/message.html.erb
84
86
  - lib/generators/appchat/templates/messages/new.html.erb
@@ -88,7 +90,8 @@ files:
88
90
  homepage: https://rubygems.org/gems/appchat
89
91
  licenses:
90
92
  - MIT
91
- metadata: {}
93
+ metadata:
94
+ source_code_uri: https://github.com/ktamulonis/appchat
92
95
  post_install_message:
93
96
  rdoc_options: []
94
97
  require_paths:
@@ -104,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
107
  - !ruby/object:Gem::Version
105
108
  version: '0'
106
109
  requirements: []
107
- rubygems_version: 3.5.11
110
+ rubygems_version: 3.5.17
108
111
  signing_key:
109
112
  specification_version: 4
110
113
  summary: Appchat makes it easy to add a chat to your app