-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Papayne/program-routine-runner (#316)
Adds a program routine runner to the skill library.
- Loading branch information
Showing
35 changed files
with
1,229 additions
and
587 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from openai.types.chat import ChatCompletionMessageParam, ChatCompletionUserMessageParam | ||
from openai_client.chat_driver import MessageHistoryProviderProtocol | ||
from semantic_workbench_api_model.workbench_model import ( | ||
ConversationMessageList, | ||
MessageType, | ||
NewConversationMessage, | ||
) | ||
from semantic_workbench_assistant.assistant_app import ( | ||
ConversationContext, | ||
) | ||
|
||
|
||
class WorkbenchMessageProvider(MessageHistoryProviderProtocol): | ||
""" | ||
This class is used to use the workbench for messages. | ||
""" | ||
|
||
def __init__(self, session_id: str, conversation_context: ConversationContext) -> None: | ||
self.session_id = session_id | ||
self.conversation_context = conversation_context | ||
|
||
async def get(self) -> list[ChatCompletionMessageParam]: | ||
message_list: ConversationMessageList = await self.conversation_context.get_messages() | ||
return [ | ||
ChatCompletionUserMessageParam( | ||
role="user", | ||
content=message.content, | ||
) | ||
for message in message_list.messages | ||
if message.message_type == MessageType.chat | ||
] | ||
|
||
async def append(self, message: ChatCompletionMessageParam) -> None: | ||
if "content" in message: | ||
await self.conversation_context.send_messages( | ||
NewConversationMessage( | ||
content=str(message["content"]), | ||
message_type=MessageType.chat, | ||
) | ||
) | ||
|
||
async def get_history(self) -> ConversationMessageList: | ||
return await self.conversation_context.get_messages() | ||
|
||
async def get_history_json(self) -> str: | ||
message_list: ConversationMessageList = await self.conversation_context.get_messages() | ||
return message_list.model_dump_json() |
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.
Oops, something went wrong.