gpt4 book ai didi

flask - 设置 OpenAI API GPT 输出文本响应的格式

转载 作者:行者123 更新时间:2023-12-02 22:47:08 25 4
gpt4 key购买 nike

我正在使用 GTP API 来查询 HTML 页面。我正在尝试找到一种方法来格式化 GPT API 响应的文本输出。我正在使用 Pinecone、Flask 和 LangChain。

例如,当输出是有关某件事的说明时,它实际上只是将其作为整个段落发送,而不是制作编号的 HTML 列表。是否可以格式化输出消息在页面上的显示方式?

doc_db = Pinecone.from_documents(docs_split, embeddings, index_name="qafrom-gpt")

# Initialize chat models and retrieval QA

llm = ChatOpenAI(
openai_api_key=openai.api_key, model_name="gpt-3.5-turbo", temperature=0.0, verbose=True

)
qa_with_source = RetrievalQA.from_chain_type(
llm=llm, chain_type="stuff", retriever=doc_db.as_retriever()
)



@app.route("/", methods=["POST", "GET"])
def chat():
if request.method == "POST":
user_query = request.form["user_query"]
message = qa_with_source.run(user_query)
print(message)
return render_template(
"chat.html",
message=message)


else:
return render_template("chat.html", message=None)

if __name__ == "__main__":
app.run(debug=True)

回应


To load HTML documents, you can follow these steps: 1. Import the necessary modules: Depending on the library you are using, you may need to import modules that provide HTML loading functionality. For example, if you are using the langchain library, you can import the document_loaders module. 2. Choose a document loader: Depending on your specific requirements, you can choose a document loader that suits your needs. For example, you can use the UnstructuredHTMLLoader or the BSHTMLLoader from the document_loaders module. 3. Create an instance of the chosen document loader: Instantiate the chosen document loader class. Pass the path or URL of the HTML document you want to load as a parameter to the loader. 4. Load the HTML document: Use the `load` method of the document loader instance to load the HTML document. This method will extract the text content from the HTML and store it in a suitable format for further processing. 5. Access the loaded data: Once the HTML document is loaded, you can access the loaded data, such as the page content, metadata, or any other relevant information, depending on the specific document loader you are using. Note: The exact implementation may vary depending on the library or framework you are using. The steps provided here are a general guideline and may need to be adapted to your specific use case.

最佳答案

您可以只要求 ChatGPT 在用户/系统提示符中以 Markdown 格式返回输出,然后使用 Python 的 markdown模块以在 Flask 中显示它。

关于flask - 设置 OpenAI API GPT 输出文本响应的格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76597068/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com