Skip to content

Commit a75288c

Browse files
Address PR feedback
1 parent 9b9c0a5 commit a75288c

File tree

2 files changed

+49
-49
lines changed

2 files changed

+49
-49
lines changed

docassemble/GithubFeedbackForm/data/questions/feedback.yml

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ subquestion: |
8181
The information you type here will be publicly available. That means anyone
8282
will be able to see it. Use this form to tell us about problems that do not
8383
include any personal information.
84-
84+
8585
${ collapse_template(al_how_to_get_legal_help) }
8686
8787
Thank you for telling us about your experience with this website.
88-
88+
8989
fields:
9090
- no label: reason
9191
input type: radio
@@ -158,12 +158,12 @@ decoration: opinion
158158
subquestion: |
159159
This form is designed to be used by testers and community
160160
stakeholders.
161-
161+
162162
The information you type here will be publicly available. That means anyone
163163
will be able to see it.
164-
164+
165165
${ collapse_template(al_how_to_get_legal_help) }
166-
166+
167167
fields:
168168
- "**What would you like to tell us about?**": reason
169169
input type: radio
@@ -236,7 +236,7 @@ subject: |
236236
Do you need more help?
237237
content: |
238238
If you need more help, these are free resources:
239-
239+
240240
- [Find Free Legal help - Legal Services Corporation](https://www.lsc.gov/about-lsc/what-legal-aid/get-legal-help)
241241
242242
- [Hire a lawyer](https://www.americanbar.org/groups/legal_services/flh-home/flh-hire-a-lawyer/)
@@ -248,7 +248,7 @@ question: |
248248
decoration: lifebuoy
249249
subquestion: |
250250
We are sorry that we couldn't do more to help you.
251-
251+
252252
${ al_how_to_get_legal_help }
253253
254254
buttons:
@@ -261,7 +261,7 @@ question: |
261261
decoration: opinion
262262
subquestion: |
263263
We appreciate you letting us know how we are doing.
264-
264+
265265
% if issue_url:
266266
If you would like to track this issue, you can [follow
267267
it](${issue_url}) on GitHub.
@@ -304,40 +304,47 @@ content: |
304304
% endif
305305
---
306306
########################## Send to GitHub code ##########################
307+
only sets:
308+
- note_issue
307309
need:
308310
- should_send_to_github
309311
- question_id
310312
- variable
311313
- package_version
312314
- filename
313315
code: |
314-
if is_likely_spam(issue_template.content):
316+
if task_performed('issue noted'):
317+
pass
318+
elif is_likely_spam(issue_template.content):
315319
log("Not saving feedback because it looks like spam")
316320
mark_task_as_performed('issue noted', persistent=True)
317-
issue_url = None
318-
saved_uuid = None
319-
note_issue = False
321+
issue_url, saved_uuid = None
322+
note_issue = False # End block early
320323
else:
321-
if not task_performed('issue noted', persistent=True):
322-
saved_uuid
323-
if showifdef('would_be_on_panel', False):
324-
add_panel_participant(panel_email)
325-
if should_send_to_github:
326-
issue_url
327-
if issue_url:
328-
if saved_uuid:
329-
set_feedback_github_url(saved_uuid, issue_url)
324+
saved_uuid # Trigger the code to save locally on the server and optionally link the session answers. We do this regardless of whether we send to GitHub
325+
if showifdef('would_be_on_panel'):
326+
add_panel_participant(panel_email)
327+
328+
if should_send_to_github:
329+
issue_url # Trigger the code to save as a GitHub issue
330+
if issue_url and saved_uuid:
331+
# Link the GitHub issue to the saved feedback in database
332+
set_feedback_github_url(saved_uuid, issue_url)
333+
else:
334+
log(f"This form was not able to add an issue on the {github_user}/{github_repo} repo. Check your config.")
335+
if al_error_email:
336+
log(f"Unable to create issue on repo {github_repo}, falling back to emailing {al_error_email}")
337+
send_email(
338+
to=al_error_email,
339+
subject=f"{github_repo} - {issue_template.subject_as_html(trim=True)}",
340+
template=issue_template
341+
)
330342
else:
331-
al_error_email
332-
log(f"This form was not able to add an issue on the {github_user}/{github_repo} repo. Check your config.")
333-
if al_error_email and not is_likely_spam(issue_template.content):
334-
log(f"Unable to create issue on repo {github_repo}, falling back to emailing {al_error_email}")
335-
send_email(to=al_error_email, subject=f"{github_repo} - {issue_template.subject_as_html(trim=True)}", template=issue_template)
336-
else:
337-
log(f"~~~USER FEEDBACK~~~ {github_repo} -{issue_template.subject_as_html(trim=True)} - {issue_template.content_as_html(trim=True)}")
338-
mark_task_as_performed('issue noted', persistent=True)
339-
else:
340-
log("Already sent feedback to github from a feedback interview, not going to send again")
343+
log(f"~~~USER FEEDBACK~~~ {github_repo} - {issue_template.subject_as_html(trim=True)} - {issue_template.content_as_html(trim=True)}")
344+
else:
345+
issue_url = None
346+
mark_task_as_performed('issue noted', persistent=True)
347+
341348
note_issue = True
342349
---
343350
code: |

docassemble/GithubFeedbackForm/github_issue.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
try:
1010
import google.generativeai as genai
11-
except:
11+
except ImportError:
1212
pass
1313

1414
# reference: https://gist.github.com/JeffPaine/3145490
@@ -186,27 +186,22 @@ def is_likely_spam_from_genai(
186186
Args:
187187
body (Optional[str]): the body of the issue
188188
context (Optional[str]): the context of the issue to help rate it as spam or not, defaults to a guided interview in the legal context
189-
gemini_api_key (Optional[str]): the token for the Google Gemini Flash API, can be specified in the global config as `google gemini api key`
189+
gemini_api_key (Optional[str]): the API key for the Google Gemini Flash API, can be specified in the global config as `google gemini api key`
190190
model (Optional[str]): the model to use for the spam detection, defaults to "gemini-2.0-flash-exp", can be specified in the global config
191191
as `github issues: spam model`
192192
"""
193193
if not body:
194194
return False
195+
196+
model = model or get_config("github issues", {}).get("spam model", "gemini-2.0-flash-exp")
197+
gemini_api_key = gemini_api_key or get_config("google gemini api key")
195198

196-
if not context:
197-
context = "a guided interview in the legal context"
198-
199-
if not gemini_api_key:
200-
gemini_api_key = get_config("google gemini api key")
201-
202-
if not gemini_api_key:
203-
log("Not using Google Gemini Flash to check for spam: no token provided")
199+
if not gemini_api_key: # not passed as a parameter OR in the global config
200+
log("Not using Google Gemini Flash to check for spam: no API key provided")
204201
return False
205202

206-
if not model:
207-
model = get_config("github issues", {}).get(
208-
"spam model", "gemini-2.0-flash-exp"
209-
)
203+
if context is None: # empty string is a valid input
204+
context = "a guided interview in the legal context"
210205

211206
try:
212207
genai.configure(api_key=gemini_api_key)
@@ -221,14 +216,12 @@ def is_likely_spam_from_genai(
221216
Answer only with the exact keywords: 'spam' or 'not spam'.
222217
""",
223218
)
224-
except Exception as e:
225-
log(f"Error configuring Google Gemini Flash: {e}")
226-
return False
227219

228-
try:
229220
response = model.generate_content(body)
230221
if response.text.strip() == "spam":
231222
return True
223+
except NameError:
224+
log(f"Error using Google Gemini Flash: the `google.generativeai` module is not available")
232225
except Exception as e:
233226
log(f"Error using Google Gemini Flash: {e}")
234227
return False

0 commit comments

Comments
 (0)