-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23c50e7
commit bf852fe
Showing
3 changed files
with
55 additions
and
5 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
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,28 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from langchain_core.output_parsers import StrOutputParser | ||
from langchain_core.prompts import ChatPromptTemplate | ||
from langchain_core.runnables import Runnable | ||
|
||
if TYPE_CHECKING: | ||
from langchain_core.language_models import BaseLanguageModel | ||
|
||
|
||
TRANSLATION_PROMPT = """You are a translation assistant. Translate user input directly into the primary language of the {locale} region without explanation.""" | ||
|
||
|
||
translation_prompt_template = ChatPromptTemplate.from_messages( | ||
[ | ||
("system", TRANSLATION_PROMPT), | ||
("human", "{input}"), | ||
] | ||
) | ||
|
||
output_parser = StrOutputParser() | ||
|
||
|
||
def get_translation_chain(llm: BaseLanguageModel) -> Runnable: | ||
"""return the guard chain runnable.""" | ||
return translation_prompt_template | llm | output_parser |