Skip to content

Commit

Permalink
Change notification response format to {notification:{prompt, params}} (
Browse files Browse the repository at this point in the history
  • Loading branch information
beastoin authored Nov 14, 2024
2 parents 02f91d5 + 471dee5 commit a7dca7d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions backend/utils/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,26 +253,26 @@ def _single(plugin: Plugin):

# message
message = response_data.get('message', '')
mentor = response_data.get('mentor', None)
print('Plugin', plugin.id, 'response:', message, mentor)
print('Plugin', plugin.id, 'response message:', message)
if message and len(message) > 5:
send_plugin_notification(token, plugin.name, plugin.id, message)
results[plugin.id] = message

# proactive_notification
if plugin.has_capability("proactive_notification"):
mentor = response_data.get('mentor', None)
if mentor:
prompt = mentor.get('prompt', '')
if len(prompt) > 0 and len(prompt) <= 5000:
params = mentor.get('params', [])
noti = response_data.get('notification', None)
print('Plugin', plugin.id, 'response notification:', noti)
if noti:
prompt = noti.get('prompt', '')
if len(prompt) > 0 and len(prompt) <= 8000:
params = noti.get('params', [])
message = get_metoring_message(uid, prompt, plugin.fitler_proactive_notification_scopes(params))
if message and len(message) > 5:
send_plugin_notification(token, plugin.name, plugin.id, message)
results[plugin.id] = message
elif len(prompt) > 5000:
send_plugin_notification(token, plugin.name, plugin.id, f"Prompt too long: {len(prompt)}/5000 characters. Please shorten.")
print(f"Plugin {plugin.id} prompt too long, length: {len(prompt)}/5000")
elif len(prompt) > 8000:
send_plugin_notification(token, plugin.name, plugin.id, f"Prompt too long: {len(prompt)}/8000 characters. Please shorten.")
print(f"Plugin {plugin.id} prompt too long, length: {len(prompt)}/8000")

except Exception as e:
print(f"Plugin integration error: {e}")
Expand Down
2 changes: 1 addition & 1 deletion plugins/example/basic/mentor.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def normalize(text):

# 3. Respond with the format {mentor: {prompt, params}}
return {'session_id': data.session_id,
'mentor': {'prompt': prompt,
'notification': {'prompt': prompt,
'params': ['user_name', 'user_facts']}}

@ router.get('/setup/mentor', tags=['mentor'])
Expand Down

0 comments on commit a7dca7d

Please sign in to comment.