Skip to content

Commit 23e146b

Browse files
fix errors (#216)
* fix errors * test * upgrade rails * adjust css
1 parent cbda5d5 commit 23e146b

File tree

7 files changed

+102
-84
lines changed

7 files changed

+102
-84
lines changed

Gemfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
66
ruby '3.2.2'
77

88
# Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
9-
gem 'rails', '~> 7.1.0'
9+
gem 'rails', '~> 7.2.0'
1010

1111
# The original asset pipeline for Rails [https://github.com/rails/sprockets-rails]
1212
gem 'sprockets-rails'
@@ -135,4 +135,4 @@ gem 'omniauth-google-oauth2'
135135
gem 'google-api-client'
136136
gem 'googleauth'
137137

138-
gem 'uri', '>= 1.0.3'
138+
gem 'uri', '>= 1.0.3'

Gemfile.lock

Lines changed: 63 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,77 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
actioncable (7.1.5.2)
5-
actionpack (= 7.1.5.2)
6-
activesupport (= 7.1.5.2)
4+
actioncable (7.2.2.2)
5+
actionpack (= 7.2.2.2)
6+
activesupport (= 7.2.2.2)
77
nio4r (~> 2.0)
88
websocket-driver (>= 0.6.1)
99
zeitwerk (~> 2.6)
10-
actionmailbox (7.1.5.2)
11-
actionpack (= 7.1.5.2)
12-
activejob (= 7.1.5.2)
13-
activerecord (= 7.1.5.2)
14-
activestorage (= 7.1.5.2)
15-
activesupport (= 7.1.5.2)
16-
mail (>= 2.7.1)
17-
net-imap
18-
net-pop
19-
net-smtp
20-
actionmailer (7.1.5.2)
21-
actionpack (= 7.1.5.2)
22-
actionview (= 7.1.5.2)
23-
activejob (= 7.1.5.2)
24-
activesupport (= 7.1.5.2)
25-
mail (~> 2.5, >= 2.5.4)
26-
net-imap
27-
net-pop
28-
net-smtp
10+
actionmailbox (7.2.2.2)
11+
actionpack (= 7.2.2.2)
12+
activejob (= 7.2.2.2)
13+
activerecord (= 7.2.2.2)
14+
activestorage (= 7.2.2.2)
15+
activesupport (= 7.2.2.2)
16+
mail (>= 2.8.0)
17+
actionmailer (7.2.2.2)
18+
actionpack (= 7.2.2.2)
19+
actionview (= 7.2.2.2)
20+
activejob (= 7.2.2.2)
21+
activesupport (= 7.2.2.2)
22+
mail (>= 2.8.0)
2923
rails-dom-testing (~> 2.2)
30-
actionpack (7.1.5.2)
31-
actionview (= 7.1.5.2)
32-
activesupport (= 7.1.5.2)
24+
actionpack (7.2.2.2)
25+
actionview (= 7.2.2.2)
26+
activesupport (= 7.2.2.2)
3327
nokogiri (>= 1.8.5)
3428
racc
35-
rack (>= 2.2.4)
29+
rack (>= 2.2.4, < 3.2)
3630
rack-session (>= 1.0.1)
3731
rack-test (>= 0.6.3)
3832
rails-dom-testing (~> 2.2)
3933
rails-html-sanitizer (~> 1.6)
40-
actiontext (7.1.5.2)
41-
actionpack (= 7.1.5.2)
42-
activerecord (= 7.1.5.2)
43-
activestorage (= 7.1.5.2)
44-
activesupport (= 7.1.5.2)
34+
useragent (~> 0.16)
35+
actiontext (7.2.2.2)
36+
actionpack (= 7.2.2.2)
37+
activerecord (= 7.2.2.2)
38+
activestorage (= 7.2.2.2)
39+
activesupport (= 7.2.2.2)
4540
globalid (>= 0.6.0)
4641
nokogiri (>= 1.8.5)
47-
actionview (7.1.5.2)
48-
activesupport (= 7.1.5.2)
42+
actionview (7.2.2.2)
43+
activesupport (= 7.2.2.2)
4944
builder (~> 3.1)
5045
erubi (~> 1.11)
5146
rails-dom-testing (~> 2.2)
5247
rails-html-sanitizer (~> 1.6)
53-
activejob (7.1.5.2)
54-
activesupport (= 7.1.5.2)
48+
activejob (7.2.2.2)
49+
activesupport (= 7.2.2.2)
5550
globalid (>= 0.3.6)
56-
activemodel (7.1.5.2)
57-
activesupport (= 7.1.5.2)
58-
activerecord (7.1.5.2)
59-
activemodel (= 7.1.5.2)
60-
activesupport (= 7.1.5.2)
51+
activemodel (7.2.2.2)
52+
activesupport (= 7.2.2.2)
53+
activerecord (7.2.2.2)
54+
activemodel (= 7.2.2.2)
55+
activesupport (= 7.2.2.2)
6156
timeout (>= 0.4.0)
62-
activestorage (7.1.5.2)
63-
actionpack (= 7.1.5.2)
64-
activejob (= 7.1.5.2)
65-
activerecord (= 7.1.5.2)
66-
activesupport (= 7.1.5.2)
57+
activestorage (7.2.2.2)
58+
actionpack (= 7.2.2.2)
59+
activejob (= 7.2.2.2)
60+
activerecord (= 7.2.2.2)
61+
activesupport (= 7.2.2.2)
6762
marcel (~> 1.0)
68-
activesupport (7.1.5.2)
63+
activesupport (7.2.2.2)
6964
base64
7065
benchmark (>= 0.3)
7166
bigdecimal
72-
concurrent-ruby (~> 1.0, >= 1.0.2)
67+
concurrent-ruby (~> 1.0, >= 1.3.1)
7368
connection_pool (>= 2.2.5)
7469
drb
7570
i18n (>= 1.6, < 2)
7671
logger (>= 1.4.2)
7772
minitest (>= 5.1)
78-
mutex_m
7973
securerandom (>= 0.3)
80-
tzinfo (~> 2.0)
74+
tzinfo (~> 2.0, >= 2.0.5)
8175
acts_as_votable (0.14.0)
8276
addressable (2.8.7)
8377
public_suffix (>= 2.0.2, < 7.0)
@@ -328,7 +322,7 @@ GEM
328322
pundit (2.5.0)
329323
activesupport (>= 3.0.0)
330324
racc (1.8.1)
331-
rack (3.2.0)
325+
rack (3.1.16)
332326
rack-protection (4.1.1)
333327
base64 (>= 0.1.0)
334328
logger (>= 1.6.0)
@@ -340,20 +334,20 @@ GEM
340334
rack (>= 1.3)
341335
rackup (2.2.1)
342336
rack (>= 3)
343-
rails (7.1.5.2)
344-
actioncable (= 7.1.5.2)
345-
actionmailbox (= 7.1.5.2)
346-
actionmailer (= 7.1.5.2)
347-
actionpack (= 7.1.5.2)
348-
actiontext (= 7.1.5.2)
349-
actionview (= 7.1.5.2)
350-
activejob (= 7.1.5.2)
351-
activemodel (= 7.1.5.2)
352-
activerecord (= 7.1.5.2)
353-
activestorage (= 7.1.5.2)
354-
activesupport (= 7.1.5.2)
337+
rails (7.2.2.2)
338+
actioncable (= 7.2.2.2)
339+
actionmailbox (= 7.2.2.2)
340+
actionmailer (= 7.2.2.2)
341+
actionpack (= 7.2.2.2)
342+
actiontext (= 7.2.2.2)
343+
actionview (= 7.2.2.2)
344+
activejob (= 7.2.2.2)
345+
activemodel (= 7.2.2.2)
346+
activerecord (= 7.2.2.2)
347+
activestorage (= 7.2.2.2)
348+
activesupport (= 7.2.2.2)
355349
bundler (>= 1.15.0)
356-
railties (= 7.1.5.2)
350+
railties (= 7.2.2.2)
357351
rails-controller-testing (1.0.5)
358352
actionpack (>= 5.0.1.rc1)
359353
actionview (>= 5.0.1.rc1)
@@ -365,10 +359,10 @@ GEM
365359
rails-html-sanitizer (1.6.2)
366360
loofah (~> 2.21)
367361
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
368-
railties (7.1.5.2)
369-
actionpack (= 7.1.5.2)
370-
activesupport (= 7.1.5.2)
371-
irb
362+
railties (7.2.2.2)
363+
actionpack (= 7.2.2.2)
364+
activesupport (= 7.2.2.2)
365+
irb (~> 1.13)
372366
rackup (>= 1.0.0)
373367
rake (>= 12.2)
374368
thor (~> 1.0, >= 1.2.2)
@@ -504,6 +498,7 @@ GEM
504498
unicode-emoji (~> 4.0, >= 4.0.4)
505499
unicode-emoji (4.0.4)
506500
uri (1.0.3)
501+
useragent (0.16.11)
507502
version_gem (1.1.8)
508503
wasabi (5.1.0)
509504
addressable
@@ -567,7 +562,7 @@ DEPENDENCIES
567562
pgvector
568563
puma (~> 6.4)
569564
pundit (~> 2.3)
570-
rails (~> 7.1.0)
565+
rails (~> 7.2.0)
571566
rails-controller-testing
572567
redcarpet
573568
redis (~> 4.0)

app/controllers/concerns/gpt_concern.rb

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,14 +139,32 @@ def call_salesforce_connect_gpt_generation(prompt)
139139
'Content-Type' => 'application/json'
140140
})
141141

142-
response_data = JSON.parse(response.body)
142+
# Check if the HTTP request was successful
143+
unless response.success?
144+
Rails.logger.error("Salesforce API HTTP error: #{response.code} - #{response.message}")
145+
return response.body || ''
146+
end
147+
148+
begin
149+
response_data = JSON.parse(response.body)
150+
rescue JSON::ParserError => e
151+
Rails.logger.error("Failed to parse Salesforce API response as JSON: #{e.message}. Response body: #{response.body}")
152+
return response.body || ''
153+
end
154+
155+
# Debug logging to understand the response structure
156+
Rails.logger.debug("Salesforce API response: #{response_data.inspect}")
157+
158+
# Check if the response has the expected structure
159+
unless response_data.is_a?(Hash) && response_data['generations'].is_a?(Array) && response_data['generations'].any?
160+
puts("Unexpected Salesforce API response structure: #{response_data.inspect}")
161+
return response_data.to_s
162+
end
143163

144164
# Decode the HTML entities
145165
decoded_text = CGI.unescapeHTML(response_data['generations'][0]['text'])
146166

147167
return decoded_text
148-
rescue StandardError => e
149-
Rails.logger.error("Error calling Salesforce Connect GPT: #{e.message}")
150168
end
151169

152170
''
@@ -168,7 +186,7 @@ def get_salesforce_connect_oauth_token
168186
client_id: encoded_client_id,
169187
client_secret: encoded_client_secret
170188
}
171-
else
189+
else
172190
{
173191
grant_type: 'password',
174192
client_id: encoded_client_id,

app/jobs/generate_message_response_job.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,13 @@ def perform(_message_id)
226226

227227
llm_message.save
228228
llm_message.ready!
229-
rescue StandardError => e
229+
rescue Exception => e
230230
error_message = "I'm sorry, I encountered an error while processing your request. Please try again later. Error: #{e.message}"
231231
llm_message.content = error_message
232232
llm_message.save
233233
llm_message.ready!
234234
Rails.logger.error("Error calling GPT to generate answer. Error: #{e.message}\nBacktrace: #{e.backtrace.join("\n")}")
235235
end
236-
237236
end
238237
end
239238
end

app/views/documents/_document.html.erb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
<div class="flex justify-between items-center py-2 pl-4 bg-stone-200 rounded-t-lg">
1616
<div class="w-full">
1717
<p class="text-xs ">
18-
<%= render partial: 'shared/meta_info', locals: { email: document.user.email, created_at: document.created_at, updated_at: document.updated_at } %>
19-
<%= "| Synced #{time_ago_in_words(document.synced_at)} ago" if document.synced_at.present? %>
18+
<%= render partial: 'shared/meta_info', locals: { email: document.user.email, created_at: document.created_at, updated_at: document.updated_at, synced_at: document.synced_at } %>
2019
</p>
2120
<% if document.url %>
2221
<div class="flex items-center space-x-1 text-xs mt-2">
@@ -29,8 +28,7 @@
2928
<span class="">Source:</span>
3029
<%= link_to document.source_url, document.source_url, class:" hover:underline", target:"_source" %>
3130
<% if document.source_type == 'quip' %>
32-
<%= image_tag 'quip_logo.png', alt: 'Quip Logo', class: 'h-6' %>
33-
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-5 <%= "text-green-600" if document.last_sync_result == "SUCCESS" %> <%= "text-red-600" if document.last_sync_result == "FAILED" %>">
31+
<svg xmlns="http://www.w3.org/2000/svg" title="Quip Sync"fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-4 <%= "text-green-600" if document.last_sync_result == "SUCCESS" %> <%= "text-red-600" if document.last_sync_result == "FAILED" %>">
3432
<path stroke-linecap="round" stroke-linejoin="round" d="M16.023 9.348h4.992v-.001M2.985 19.644v-4.992m0 0h4.992m-4.993 0 3.181 3.183a8.25 8.25 0 0 0 13.803-3.7M4.031 9.865a8.25 8.25 0 0 1 13.803-3.7l3.181 3.182m0-4.991v4.99" />
3533
</svg>
3634
<% end %>
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<div class="py-1 text-xs ">
22
Owner <span class="font-bold "><%= email %> </span> |
33
Created <span class="font-bold "><%= time_ago_in_words(created_at) %> ago</span> |
4-
Updated <span class="font-bold "><%= time_ago_in_words(updated_at) %> ago</span>
4+
Updated <span class="font-bold "><%= time_ago_in_words(updated_at) %> ago</span><%=
5+
if defined?(synced_at) && synced_at.present?
6+
content_tag(:span, " | Synced #{time_ago_in_words(synced_at)} ago")
7+
end
8+
%>
59
</div>

spec/controllers/concerns/gpt_concern_spec.rb

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@
184184

185185
let(:success_response) do
186186
double('response',
187-
body: '{"generations": [{"text": "&lt;generated&gt; text"}]}')
187+
success?: true,
188+
body: '{"generations": [{"text": "&lt;generated&gt; text"}]}',
189+
code: 200,
190+
message: 'OK')
188191
end
189192

190193
before do
@@ -199,8 +202,9 @@
199202
expect(result).to eq('<generated> text')
200203
end
201204

202-
it 'returns empty string when an error occurs' do
203-
allow(HTTParty).to receive(:post).and_raise(StandardError.new('API Error'))
205+
it 'returns empty string when HTTP request fails' do
206+
failed_response = double('response', success?: false, body: nil, code: 500, message: 'Internal Server Error')
207+
allow(HTTParty).to receive(:post).and_return(failed_response)
204208
result = instance.call_salesforce_connect_gpt_generation('test prompt')
205209
expect(result).to eq('')
206210
end

0 commit comments

Comments
 (0)