mirror of
https://github.com/hwchase17/langchain
synced 2024-11-10 01:10:59 +00:00
37 lines
890 B
Plaintext
37 lines
890 B
Plaintext
```python
|
|
from langchain.output_parsers import CommaSeparatedListOutputParser
|
|
from langchain.prompts import PromptTemplate, ChatPromptTemplate, HumanMessagePromptTemplate
|
|
from langchain.llms import OpenAI
|
|
from langchain.chat_models import ChatOpenAI
|
|
|
|
output_parser = CommaSeparatedListOutputParser()
|
|
|
|
format_instructions = output_parser.get_format_instructions()
|
|
prompt = PromptTemplate(
|
|
template="List five {subject}.\n{format_instructions}",
|
|
input_variables=["subject"],
|
|
partial_variables={"format_instructions": format_instructions}
|
|
)
|
|
|
|
model = OpenAI(temperature=0)
|
|
|
|
_input = prompt.format(subject="ice cream flavors")
|
|
output = model(_input)
|
|
|
|
output_parser.parse(output)
|
|
```
|
|
|
|
The resulting output will be:
|
|
|
|
<CodeOutputBlock lang="python">
|
|
|
|
```
|
|
['Vanilla',
|
|
'Chocolate',
|
|
'Strawberry',
|
|
'Mint Chocolate Chip',
|
|
'Cookies and Cream']
|
|
```
|
|
|
|
</CodeOutputBlock>
|