response_schemas = [ ResponseSchema(name="answer", description="answer to the user's question"), ResponseSchema(name="source", description="source used to answer the user's question, should be a website.") ] output_parser = StructuredOutputParser.from_response_schemas(response_schemas)
# -*- coding: utf-8 -*- from langchain.output_parsers import StructuredOutputParser, ResponseSchema from langchain.prompts import PromptTemplate
# 告诉他我们生成的内容需要哪些字段,每个字段类型式啥 response_schemas = [ ResponseSchema(type="string", name="bad_string", description="This a poorly formatted user input string"), ResponseSchema(type="string", name="good_string", description="This is your response, a reformatted response") ]
promptValue = prompt.format(user_input="welcom to califonya!") print(promptValue)
此时,结构化输出的内容如下:
1 2 3 4 5 6 7 8
The output should be a markdown code snippet formatted in the following schema, including the leading and trailing "```json" and "```":
\```json { "bad_string": string // This a poorly formatted user input string "good_string": string // This is your response, a reformatted response } \```
prompt的内容如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
You will be given a poorly formatted string from a user. Reformat it and make sure all the words are spelled correctly
The output should be a markdown code snippet formatted in the following schema, including the leading and trailing "```json" and "```":
\```json { "bad_string": string // This a poorly formatted user input string "good_string": string // This is your response, a reformatted response } \```
% USER INPUT: welcom to califonya!
YOUR RESPONSE:
将上述内容使用LLM进行回复,示例Pyhon代码如下(接上述代码):
1 2 3 4 5 6 7 8 9 10 11 12 13
from langchain.llms import OpenAI
# set api key import os os.environ["OPENAI_API_KEY"] = 'sk-xxx'
```json { "bad_string": "welcom to califonya!", "good_string": "Welcome to California!" } \``` {'bad_string': 'welcom to califonya!', 'good_string': 'Welcome to California!'}