我非常喜欢chatpdf.com网站。您可以上传一个PDF文件,然后与文件“本身”讨论文件的文本内容。它使用ChatGPT。
我想编写类似的程序。但是我想知道如何在ChatGPT提示符中使用长PDF文件的内容,因为ChatGPT每次会话只接受4096个令牌。
如何减少所需令牌的数量?
发布于 2023-03-24 12:14:34
我没有发现你提到的网站有用-也许它没有使用最新的GPT模式?或者ChatGPT还没有很好的能力来理解我提供的pdf文件。
无聊的答案#1要求GPT总结每一页或每一节,然后将摘要提供给它。
无聊的答案#2在这类任务上微调你自己的语言模型。由于好的那些仍然是巨大的,它是不可能得到非常好的结果,因为你可以负担的价格。
无聊的答案#3,等一些大公司发布一个更好的模型,具有更长的上下文或内存能力。
更有趣的,但仍然是实验性的答案,基于研究观察发现,非常大的LLM能够进行思维链推理,您可以尝试教ChatGPT使用工具。该方法在反应纸中进行了描述。相关关键词是“语言链”或“语言链”。一个实现可以找到这里。有一个叫做LangChain的python框架和一个OpenAI 检索插件。
因此,在您的示例中,工具可以读取ChatGPT请求的特定页面。一旦它请求读取特定的页面,您(或您的程序)就会输入该页面等等,直到它到达最终的答案为止。另一个工具是让模型访问文本搜索(Ctrl+F)。
示例(来自这里):
You are working with a pandas dataframe in Python. The name of the dataframe is `df`.
You should use the tools below to answer the question posed of you.
python_repl_ast: A Python shell. Use this to execute python commands. Input should be a valid python command. When using this tool, sometimes output is abbreviated - make sure it does not look abbreviated before using it in your answer.
Use the following format:
Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [python_repl_ast]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question
```
发布于 2023-04-27 12:03:13
一个典型的解决方案是将长文本块成较小的片段,根据搜索查询检索相关片段,然后通过API调用发送它们。
下面是是一个可以处理PDF、txt和doc文件以及网页的项目。如果您有兴趣的话,我相信这个实现是很简单的。
https://datascience.stackexchange.com/questions/120321
复制相似问题