-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
To ease reading/understanding/debugging of code
- Loading branch information
1 parent
c48cafd
commit e4537e4
Showing
13 changed files
with
329 additions
and
323 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
assistants/prospector-assistant/assistant/agents/form_fill_agent/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 0 additions & 40 deletions
40
assistants/prospector-assistant/assistant/agents/form_fill_agent/step.py
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
assistants/prospector-assistant/assistant/agents/form_fill_agent/steps/_attachments.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
""" | ||
Utility functions for handling attachments in chat messages. | ||
""" | ||
|
||
from typing import Awaitable, Callable, Sequence | ||
|
||
from openai.types.chat import ChatCompletionMessageParam | ||
from semantic_workbench_assistant.assistant_app.context import ConversationContext | ||
|
||
from .. import state | ||
|
||
|
||
async def message_with_recent_attachments( | ||
context: ConversationContext, | ||
latest_user_message: str | None, | ||
get_attachment_messages: Callable[[Sequence[str]], Awaitable[Sequence[ChatCompletionMessageParam]]], | ||
) -> str: | ||
files = await context.get_files() | ||
|
||
new_filenames = set() | ||
|
||
async with state.agent_state(context) as agent_state: | ||
max_timestamp = agent_state.most_recent_attachment_timestamp | ||
for file in files.files: | ||
if file.updated_datetime.timestamp() <= agent_state.most_recent_attachment_timestamp: | ||
continue | ||
|
||
max_timestamp = max(file.updated_datetime.timestamp(), max_timestamp) | ||
new_filenames.add(file.filename) | ||
|
||
agent_state.most_recent_attachment_timestamp = max_timestamp | ||
|
||
attachment_messages = await get_attachment_messages(list(new_filenames)) | ||
|
||
return "\n\n".join( | ||
( | ||
latest_user_message or "", | ||
*( | ||
str(attachment.get("content")) | ||
for attachment in attachment_messages | ||
if "<ATTACHMENT>" in str(attachment.get("content", "")) | ||
), | ||
), | ||
) | ||
|
||
|
||
async def attachment_for_filename( | ||
filename: str, get_attachment_messages: Callable[[Sequence[str]], Awaitable[Sequence[ChatCompletionMessageParam]]] | ||
) -> str: | ||
attachment_messages = await get_attachment_messages([filename]) | ||
return "\n\n".join( | ||
( | ||
str(attachment.get("content")) | ||
for attachment in attachment_messages | ||
if "<ATTACHMENT>" in str(attachment.get("content", "")) | ||
) | ||
) |
Oops, something went wrong.