You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
langchain/langchain/prompts
Jonas Nelle 97e7dc1502
Make BaseStringMessagePromptTemplate.from_template return type generic (#4523)
# Make BaseStringMessagePromptTemplate.from_template return type generic

I use mypy to check type on my code that uses langchain. Currently after
I load a prompt and convert it to a system prompt I have to explicitly
cast it which is quite ugly (and not necessary):
```
prompt_template = load_prompt("prompt.yaml")
system_prompt_template = cast(
    SystemMessagePromptTemplate,
    SystemMessagePromptTemplate.from_template(prompt_template.template),
)
```

With this PR, the code would simply be: 
```
prompt_template = load_prompt("prompt.yaml")
system_prompt_template = SystemMessagePromptTemplate.from_template(prompt_template.template)
```

Given how much langchain uses inheritance, I think this type hinting
could be applied in a bunch more places, e.g. load_prompt also return a
`FewShotPromptTemplate` or a `PromptTemplate` but without typing the
type checkers aren't able to infer that. Let me know if you agree and I
can take a look at implementing that as well.

        @hwchase17 - project lead

        DataLoaders
        - @eyurtsev
1 year ago
..
example_selector Fix small typo in SemanticSimilarityExampleSelector (#2629) 1 year ago
__init__.py chat model example (#2310) 1 year ago
base.py Validate `input_variables` when using `jinja2` templates (#3140) 1 year ago
chat.py Make BaseStringMessagePromptTemplate.from_template return type generic (#4523) 1 year ago
few_shot.py Removed duplicate BaseModel dependencies (#2471) 1 year ago
few_shot_with_templates.py Removed duplicate BaseModel dependencies (#2471) 1 year ago
loading.py consistently use getLogger(__name__), no root logger (#2989) 1 year ago
prompt.py Validate `input_variables` when using `jinja2` templates (#3140) 1 year ago