Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
payneio committed Feb 10, 2025
1 parent bc1455e commit d24c1bc
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from openai import AsyncAzureOpenAI, AsyncOpenAI
from openai_client.chat_driver import ChatDriver, ChatDriverConfig, InMemoryMessageHistoryProvider
from openai_client.chat_driver import (
ChatDriver,
ChatDriverConfig,
InMemoryMessageHistoryProvider,
)
from openai_client.messages import format_with_liquid

from ..document_skill import Outline, Paper
Expand All @@ -18,7 +22,7 @@ async def draft_content(
history = InMemoryMessageHistoryProvider(formatter=format_with_liquid)

if decision == "[ITERATE]":
history.append_system_message(
await history.append_system_message(
(
"Following the structure of the outline, iterate on the currently drafted page of the"
" document. It's more important to maintain an appropriately useful level of detail. "
Expand All @@ -28,7 +32,7 @@ async def draft_content(
)

else:
history.append_system_message(
await history.append_system_message(
(
"Following the structure of the outline, create the content for the next (or first) page of the"
" document - don't try to create the entire document in one pass nor wrap it up too quickly, it will be a"
Expand All @@ -39,32 +43,36 @@ async def draft_content(
)
)

history.append_system_message("<CHAT_HISTORY>{{chat_history}}</CHAT_HISTORY>", {"chat_history": chat_history})
await history.append_system_message("<CHAT_HISTORY>{{chat_history}}</CHAT_HISTORY>", {"chat_history": chat_history})

for item in attachments:
history.append_system_message(
await history.append_system_message(
"<ATTACHMENT><FILENAME>{{item.filename}}</FILENAME><CONTENT>{{item.content}}</CONTENT></ATTACHMENT>",
{"item": item},
)

if outline_versions:
last_outline = outline_versions[-1]
history.append_system_message(
await history.append_system_message(
"<APPROVED_OUTLINE>{{last_outline}}</APPROVED_OUTLINE>", {"last_outline": last_outline}
)

if paper_versions:
if decision == "[ITERATE]" and user_feedback:
content = paper_versions[-1].contents[-1].content
history.append_system_message("<EXISTING_CONTENT>{{content}}</EXISTING_CONTENT>", {"content": content})
history.append_system_message(
await history.append_system_message(
"<EXISTING_CONTENT>{{content}}</EXISTING_CONTENT>", {"content": content}
)
await history.append_system_message(
"<USER_FEEDBACK>{{user_feedback}}</USER_FEEDBACK>", {"user_feedback": user_feedback}
)
else:
full_content = ""
for content in paper_versions[-1].contents:
full_content += content.content
history.append_system_message("<EXISTING_CONTENT>{{content}}</EXISTING_CONTENT>", {"content": full_content})
await history.append_system_message(
"<EXISTING_CONTENT>{{content}}</EXISTING_CONTENT>", {"content": full_content}
)

config = ChatDriverConfig(
openai_client=open_ai_client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async def draft_outline(
):
history = InMemoryMessageHistoryProvider(formatter=format_with_liquid)

history.append_system_message(
await history.append_system_message(
(
"Generate an outline for the document, including title. The outline should include the key points that will"
" be covered in the document. Consider the attachments, the rationale for why they were uploaded, and the"
Expand All @@ -25,22 +25,22 @@ async def draft_outline(
)
)

history.append_system_message("<CHAT_HISTORY>{{chat_history}}</CHAT_HISTORY>", {"chat_history": chat_history})
await history.append_system_message("<CHAT_HISTORY>{{chat_history}}</CHAT_HISTORY>", {"chat_history": chat_history})

for item in attachments:
history.append_system_message(
await history.append_system_message(
"<ATTACHMENT><FILENAME>{{item.filename}}</FILENAME><CONTENT>{{item.content}}</CONTENT></ATTACHMENT>",
{"item": item},
)

if len(outline_versions):
last_outline = outline_versions[-1]
history.append_system_message(
await history.append_system_message(
"<EXISTING_OUTLINE>{{last_outline}}</EXISTING_OUTLINE>", {"last_outline": last_outline}
)

if user_feedback is not None:
history.append_system_message(
await history.append_system_message(
"<USER_FEEDBACK>{{user_feedback}}</USER_FEEDBACK>", {"user_feedback": user_feedback}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async def get_user_feedback_for_outline_decision(
history = InMemoryMessageHistoryProvider(formatter=format_with_liquid)

if outline:
history.append_system_message(
await history.append_system_message(
(
"Use the user's most recent feedback to determine if the user wants to iterate further on the"
" provided outline [ITERATE], or if the user is ready to move on to drafting a paper from the"
Expand All @@ -26,7 +26,7 @@ async def get_user_feedback_for_outline_decision(
)
)
else:
history.append_system_message(
await history.append_system_message(
(
"You are an AI assistant that helps draft outlines for a future flushed-out document."
" You use the user's most recent feedback to determine if the user wants to iterate further on the"
Expand All @@ -36,16 +36,16 @@ async def get_user_feedback_for_outline_decision(
)
)

history.append_system_message("<CHAT_HISTORY>{{chat_history}}</CHAT_HISTORY>", {"chat_history": chat_history})
await history.append_system_message("<CHAT_HISTORY>{{chat_history}}</CHAT_HISTORY>", {"chat_history": chat_history})

if len(outline_versions):
last_outline_content = outline_versions[-1].content
if outline:
history.append_system_message(
await history.append_system_message(
"<EXISTING_OUTLINE>{{outline}}</EXISTING_OUTLINE>", {"outline": last_outline_content}
)
else:
history.append_system_message(
await history.append_system_message(
"<APPROVED_OUTLINE>{{outline}}</APPROVED_OUTLINE>", {"outline": last_outline_content}
)

Expand All @@ -54,12 +54,12 @@ async def get_user_feedback_for_outline_decision(
full_paper_content = ""
for content in paper_versions[-1].contents:
full_paper_content += content.content
history.append_system_message(
await history.append_system_message(
"<EXISTING_CONTENT>{{content}}</EXISTING_CONTENT>", {"content": full_paper_content}
)

if user_feedback is not None:
history.append_system_message(
await history.append_system_message(
"<USER_FEEDBACK>{{user_feedback}}</USER_FEEDBACK>", {"user_feedback": user_feedback}
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async def get_user_feedback_for_page_decision(
history = InMemoryMessageHistoryProvider(formatter=format_with_liquid)

if outline:
history.append_system_message(
await history.append_system_message(
(
"Use the user's most recent feedback to determine if the user wants to iterate further on the"
" provided outline [ITERATE], or if the user is ready to move on to drafting a paper from the"
Expand All @@ -26,7 +26,7 @@ async def get_user_feedback_for_page_decision(
)
)
else:
history.append_system_message(
await history.append_system_message(
(
"You are an AI assistant that helps draft outlines for a future flushed-out document."
" You use the user's most recent feedback to determine if the user wants to iterate further on the"
Expand All @@ -36,16 +36,16 @@ async def get_user_feedback_for_page_decision(
)
)

history.append_system_message("<CHAT_HISTORY>{{chat_history}}</CHAT_HISTORY>", {"chat_history": chat_history})
await history.append_system_message("<CHAT_HISTORY>{{chat_history}}</CHAT_HISTORY>", {"chat_history": chat_history})

if len(outline_versions):
last_outline_content = outline_versions[-1].content
if outline:
history.append_system_message(
await history.append_system_message(
"<EXISTING_OUTLINE>{{outline}}</EXISTING_OUTLINE>", {"outline": last_outline_content}
)
else:
history.append_system_message(
await history.append_system_message(
"<APPROVED_OUTLINE>{{outline}}</APPROVED_OUTLINE>", {"outline": last_outline_content}
)

Expand All @@ -54,12 +54,12 @@ async def get_user_feedback_for_page_decision(
full_paper_content = ""
for content in paper_versions[-1].contents:
full_paper_content += content.content
history.append_system_message(
await history.append_system_message(
"<EXISTING_CONTENT>{{content}}</EXISTING_CONTENT>", {"content": full_paper_content}
)

if user_feedback is not None:
history.append_system_message(
await history.append_system_message(
"<USER_FEEDBACK>{{user_feedback}}</USER_FEEDBACK>", {"user_feedback": user_feedback}
)

Expand Down

0 comments on commit d24c1bc

Please sign in to comment.