Skip to content

Commit

Permalink
Send a notification to users when proactive notification apps exceed … (
Browse files Browse the repository at this point in the history
#1307)

…the prompts limit
  • Loading branch information
beastoin authored Nov 13, 2024
2 parents a89fe5e + 7c4a789 commit 17286ba
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
17 changes: 9 additions & 8 deletions backend/utils/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,39 @@ def get_github_docs_content(repo="BasedHardware/omi", path="docs/docs"):
"""
Recursively retrieves content from GitHub docs folder and subfolders using GitHub API.
Returns a dict mapping file paths to their raw content.
If cached, returns cached content. (24 hours)
So any changes to the docs will take 24 hours to be reflected.
"""
if cached := get_generic_cache(f'get_github_docs_content_{repo}_{path}'):
return cached
docs_content = {}
headers = {"Authorization": f"token {os.getenv('GITHUB_TOKEN')}"}

def get_contents(path):
url = f"https://api.github.com/repos/{repo}/contents/{path}"
response = requests.get(url, headers=headers)

if response.status_code != 200:
print(f"Failed to fetch contents for {path}: {response.status_code}")
return

contents = response.json()

if not isinstance(contents, list):
return

for item in contents:
if item["type"] == "file" and (item["name"].endswith(".md") or item["name"].endswith(".mdx")):
# Get raw content for documentation files
raw_response = requests.get(item["download_url"], headers=headers)
if raw_response.status_code == 200:
docs_content[item["path"]] = raw_response.text

elif item["type"] == "dir":
# Recursively process subfolders
get_contents(item["path"])

get_contents(path)
set_generic_cache(f'get_github_docs_content_{repo}_{path}', docs_content, 60 * 24*7)
return docs_content
Expand Down Expand Up @@ -270,6 +270,7 @@ def _single(plugin: Plugin):
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")

except Exception as e:
Expand Down
9 changes: 7 additions & 2 deletions plugins/example/basic/mentor.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ def normalize(text):

session_id = data.session_id
segments = get_upsert_segment_to_transcript_plugin('mentor-01', session_id, data.segments)
scan_segment = scan_segment_session[session_id] if session_id in scan_segment_session and len(segments) > len(data.segments) else 0
if len(segments) <= len(data.segments) or session_id not in scan_segment_session:
scan_segment_session[session_id] = 0
scan_segment = scan_segment_session[session_id]

# 1. Detect codewords. You could either use a simple regexp or call LLMs to trigger the step 2.
codewords = ['hey Omi what do you think']
scan_segments = segments[scan_segment:]
print(session_id, "scan_segment", len(scan_segments), scan_segment)
if len(scan_segments) == 0:
return {}
text_lower = normalize(" ".join([segment.text for segment in scan_segments]))
Expand All @@ -50,7 +53,7 @@ def normalize(text):
The following is a {user_name}'s conversation, with the transcripts, that {user_name} had during the meeting.
{user_name} wants to get the call-to-action advice to move faster during the meetting based on the conversation.
First, identify the topics or problems that {user_name} is discussing or trying to resolve during the meeting, and then provide advice specific to those topics or problems. If you cannot find the topic or problem of the meeting, respond with an empty message.
First, identify the topics or problems that {user_name} is discussing or trying to resolve during the meeting, and then provide advice specific to those topics or problems.
The advice must focus on the specific object mentioned in the conversation. The object could be a product, a person, or an event.
Expand All @@ -62,6 +65,8 @@ def normalize(text):
Respond in at most 100 words.
Output your response in plain text, without markdown.
If you cannot find the topic or problem of the meeting, respond 'Nah 🤷 ~'.
```
${transcript}
```
Expand Down

0 comments on commit 17286ba

Please sign in to comment.