forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfollowup.py
More file actions
54 lines (46 loc) · 2 KB
/
Copy pathfollowup.py
File metadata and controls
54 lines (46 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from typing import List, Optional, cast
from models.other import Person
from models.transcript_segment import TranscriptSegment
from utils.llm.clients import get_llm
from utils.llm.usage_tracker import track_usage, Features
def _response_text(response: object) -> str:
content = getattr(response, 'content', response)
if isinstance(content, str):
return content
if isinstance(content, list):
parts: list[str] = []
for item in cast(list[object], content):
if isinstance(item, str):
parts.append(item)
elif isinstance(item, dict):
block = cast(dict[str, object], item)
text = block.get('text') or block.get('content') or ''
if text:
parts.append(str(text))
elif item is not None:
parts.append(str(item))
return ''.join(parts)
return str(content)
def followup_question_prompt(
uid: str, segments: List[TranscriptSegment], people: Optional[List[Person]] = None, user_name: Optional[str] = None
) -> str:
transcript_str = TranscriptSegment.segments_as_string(
segments, include_timestamps=False, people=people, user_name=user_name
)
words = transcript_str.split()
w_count = len(words)
if w_count < 10:
return ''
elif w_count > 100:
# trim to last 500 words
transcript_str = ' '.join(words[-100:])
prompt = f"""
You will be given the transcript of an in-progress conversation.
Your task as an engaging, fun, and curious conversationalist, is to suggest the next follow-up question to keep the conversation engaging.
Conversation Transcript:
{transcript_str}
Output your response in plain text, without markdown.
Output only the question, without context, be concise and straight to the point.
""".replace(' ', '').strip()
with track_usage(uid, Features.FOLLOWUP):
return _response_text(get_llm('followup').invoke(prompt))