我正在使用chatGPT查询一段文本。但我需要chatGPT以单一直接的回答回应,而不是长篇大论或无关的文本。有没有办法实现这一点?
我的代码如下:
from langchain.document_loaders import TextLoaderfrom langchain.vectorstores import DocArrayInMemorySearchfrom langchain.indexes import VectorstoreIndexCreatorloader = TextLoader("path/to/extracted_text.txt")loaded_text = loader.load()# 将文档文本保存为向量。index = VectorstoreIndexCreator( vectorstore_cls=DocArrayInMemorySearch ).from_loaders([loader])# 查询文本response = index.query("At what time did john come home yesterday?")print("Loaded text is:", loaded_text)print("ChatGPT response is:", response)
>>> Loaded text is: “< 一段很长的文本 > + John came home lastnight at 11:30pm + < 一段很长的文本 >”
>>> ChatGPT response is: “John came back yesterday at 11:30pm.”
问题是我想要一个简洁的回答 11:30pm
,而不是完整的句子 John came home last night at 11:30pm
。有没有办法在不向查询中添加“我需要一个简短直接的回答”的情况下实现这一点?我可以通过设置其他参数来获得更有保证的简洁回答吗?
回答:
实现你想要的结果的最佳方法是适当的提示工程。没有其他办法。这是更多的一种思维训练,而不是学习一项新技能。阅读这篇微软学习文档关于提示工程的内容,以获取推进任务所需的知识。祝你好运!