-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Common
: Improve langchain message converters (#65)
- Loading branch information
Showing
7 changed files
with
43 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
from common.singleton import Singleton | ||
from common.message_converters import ( | ||
convert_iris_message_to_langchain_message, | ||
convert_langchain_message_to_iris_message, | ||
) |
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,29 @@ | ||
from langchain_core.messages import BaseMessage | ||
|
||
from domain import IrisMessage, IrisMessageRole | ||
|
||
|
||
def convert_iris_message_to_langchain_message(iris_message: IrisMessage) -> BaseMessage: | ||
match iris_message.role: | ||
case IrisMessageRole.USER: | ||
role = "human" | ||
case IrisMessageRole.ASSISTANT: | ||
role = "ai" | ||
case IrisMessageRole.SYSTEM: | ||
role = "system" | ||
case _: | ||
raise ValueError(f"Unknown message role: {iris_message.role}") | ||
return BaseMessage(content=iris_message.text, type=role) | ||
|
||
|
||
def convert_langchain_message_to_iris_message(base_message: BaseMessage) -> IrisMessage: | ||
match base_message.type: | ||
case "human": | ||
role = IrisMessageRole.USER | ||
case "ai": | ||
role = IrisMessageRole.ASSISTANT | ||
case "system": | ||
role = IrisMessageRole.SYSTEM | ||
case _: | ||
raise ValueError(f"Unknown message type: {base_message.type}") | ||
return IrisMessage(text=base_message.content, role=role) |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
from llm.request_handler_interface import RequestHandler | ||
from llm.completion_arguments import * | ||
from llm.basic_request_handler import BasicRequestHandler | ||
from llm.external import * | ||
from llm.request_handler import * |
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,2 @@ | ||
from basic_request_handler import BasicRequestHandler | ||
from request_handler_interface import RequestHandler |
File renamed without changes.
File renamed without changes.