I am using GTP API to query HTML pages. I am trying to find a way to format the text output by the response from the GPT API. I am using Pinecone, Flask and LangChain.
For example, when the output is instructions about something, instead of making a numbered HTML list, it actually just sent it as a whole paragraph. Is it possible to format how the output message is displayed on the page?
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)
The response
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.