Skip to content

Commit

Permalink
conversation context
Browse files Browse the repository at this point in the history
  • Loading branch information
srtaalej committed Aug 5, 2024
1 parent 3f8b047 commit 02ca237
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 3 additions & 2 deletions ai/ai_utils/handle_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ def _get_provider(api_name: str):
return AnthropicAPI()


def get_ai_response(user_id: str, prompt: str, context="", system_content=DEFAULT_SYSTEM_CONTENT):
def get_ai_response(user_id: str, prompt: str, context: list = [], system_content=DEFAULT_SYSTEM_CONTENT):
try:
full_prompt = f"{prompt} {context}"
formatted_context = "\n".join([f"{msg['user']}: {msg['text']}" for msg in context])
full_prompt = f"Prompt: {prompt}\nContext: {formatted_context}"
api_name, model_name = get_user_state(user_id)
provider = _get_provider(api_name)
provider.set_model(model_name)
Expand Down
9 changes: 4 additions & 5 deletions listeners/listener_utils/parse_conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
# and formats it as a string with user IDs and their messages.
# Used in `app_mentioned_callback`, `dm_sent_callback`,
# and `handle_summary_function_callback`.
def parse_conversation(conversation: str, bot_id: str = ""):
parsed = ""
def parse_conversation(conversation: str):
parsed = []
try:
for message in conversation:
user = message.get("user")
text = message.get("text", "")
if user != bot_id:
parsed += f"{user}: {text}, "
return str(parsed)
parsed.append({"user": user, "text": text})
return parsed
except Exception as e:
Logger.error(e)
return None

0 comments on commit 02ca237

Please sign in to comment.