Skip to content

Commit

Permalink
feat: [4] as_langchain
Browse files Browse the repository at this point in the history
  • Loading branch information
tvaroska committed Dec 10, 2024
1 parent 754156c commit b1af702
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions promptgit/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,18 @@ def parse_children(children):

def as_langchain(self):
try:
from langchain_core.prompts import PromptTemplate
from langchain_core.prompts import PromptTemplate, ChatPromptTemplate
except ModuleNotFoundError:
raise ModuleNotFoundError('Install promptgit[langchain] to use with langchain prompts')

return PromptTemplate.from_template(self.prompt)
if isinstance(self.prompt, str):
return PromptTemplate(template=self.prompt, template_format='f-string', input_variables=self.variables)
else:
return ChatPromptTemplate(
template = [(item.role, item.content) for item in self.prompt],
template_format='f-string',
input_variables=self.variables
)

def __str__(self):
if isinstance(self.prompt, str):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ GitPython = ">=3.0.0,<4.0.0"
urllib3 = ">=2.2.2,<3.0.0"
langchain-core = { version = ">=0.3.0,<0.4.0", optional = true }
pyyaml = ">=6.0.0"
mistletoe = "^1.4.0"
mistletoe = ">=1.4.0,<2.0.0"

[tool.poetry.extras]
langchain = [ "langchain-core" ]
Expand Down

0 comments on commit b1af702

Please sign in to comment.