- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在连接到我的第一个聊天机器人。基于此处概述的流程: https://beebom.com/how-train-ai-chatbot-custom-knowledge-base-chatgpt-api/
我创建了他建议的代码来让 ChatGPT 分析我的 PDF。不过代码有点过时了,我必须做一些调整。这就是我现在拥有的:
from llama_index import *
from langchain.chat_models import ChatOpenAI
import gradio as gr
import sys
import os
import openai
os.environ["OPENAI_API_KEY"] = 'XXXX'
openai.api_key = "XXXX"
documents = ""
service_context = ""
def construct_index(directory_path):
max_input_size = 4096
num_outputs = 512
max_chunk_overlap = 20
chunk_size_limit = 600
prompt_helper = PromptHelper(max_input_size, num_outputs, chunk_overlap_ratio=0.1, chunk_size_limit=chunk_size_limit)
llm_predictor = LLMPredictor(llm=ChatOpenAI(temperature=0.7, model_name="gpt-3.5-turbo", max_tokens=num_outputs))
documents = SimpleDirectoryReader(directory_path).load_data()
service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor, prompt_helper=prompt_helper)
index = GPTVectorStoreIndex.from_documents(documents, service_context=service_context)
# apparently this saves it to disk?
index.storage_context.persist(persist_dir='docs')
storage_context = StorageContext.from_defaults(persist_dir='docs')
index = load_index_from_storage(storage_context)
return index
def chatbot(input_text):
index = GPTVectorStoreIndex.from_documents(documents, service_context=service_context)
index.storage_context.persist(persist_dir='docs')
storage_context = StorageContext.from_defaults(persist_dir='docs')
index = load_index_from_storage(storage_context)
# tried this method as well with no success instead of above
#index = GPTVectorStoreIndex.from_documents(documents, service_context=service_context)
query_engine = index.as_query_engine()
response = query_engine.query(input_text)
# am I returning the correct object here? I believe its supposed to be JSON?
return response
iface = gr.Interface(fn=chatbot,
inputs=gr.components.Textbox(lines=7, label="Enter your text"),
outputs="text",
title="Custom-trained AI Chatbot")
index = construct_index("docs")
iface.launch(share=True)
当我运行该程序时,没有错误,它说它在我的 Ip 上运行。当我到达聊天机器人时,一切看起来都很好,直到我提出问题。然后它一直说“无”
控制台中没有错误或警告,程序继续运行。每当我查询它时,它总是说“无”。我哪里出错了?顺便说一句,我并不是 100% 理解代码,这是对原始示例的大量修改,以使所有库都能正常工作。如果有人可以简单地解释发生了什么,我们将不胜感激。谢谢G
最佳答案
Chatbot 函数返回 response=None
,它只是在输出文本框组件中收集。我建议在 iface.launch() 中使用 debug=True
。更多信息可以在这里找到 - https://www.gradio.app/docs/blocks#blocks-launch-arguments
关于python - ChatGPT API 定制训练的 AI 聊天机器人对 Python 查询应答 "None",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76989885/
我正在研究直径协议(protocol)。我在直径堆栈重新启动时遇到有关处理请求/应答/ session 的问题,因此我想知道哪些参数存储在数据库中以供直径堆栈重新启动时进一步使用? Session_I
我正在学习 SOAP,并创建了一个非常小的 CGI 脚本,该脚本在 Apache 上运行,将提供一小组功能。 #!/usr/bin/perl use SOAP::Transport::HTTP; SO
我是 C# 新手,我需要发送 HTTP GET 请求并阅读答案。我熟悉 Java 并且很容易做到 URLConnection 类,但我不知道在 c# 中。有人可以帮忙吗? 最佳答案 最简单的方法是使用
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 1 年前。
我想创建一个从服务器返回 token 的函数,但是 http.post() 在我的函数返回 token 后得到响应。 我如何在返回 token 之前等待 http.post()。 我的代码: impo
此处引用 developer site & call recording android 10尝试录制音频文件并将其保存到其本地目录路径,我使用 AccessibilityService 来实现它在
我是一名优秀的程序员,十分优秀!