diff --git a/demos/palm/python/docs-agent/README.md b/demos/palm/python/docs-agent/README.md index 3ec9cfd38..526708391 100644 --- a/demos/palm/python/docs-agent/README.md +++ b/demos/palm/python/docs-agent/README.md @@ -125,6 +125,10 @@ The following list summarizes the tasks and features of the Docs Agent sample ap the responses. (See the [Enabling users to submit a rewrite of a generated response][submit-a-rewrite] and [Enabling users to like generated responses][like-generate-responses] sections.) +- **Convert Google Docs, PDF, and Gmail into Markdown files**: This feature uses + Apps Script to convert Google Docs, PDF, and Gmail into Markdown files, which then + can be used as input datasets for Docs Agent. For more information, see the + [`README`][apps-script-readme] file in the `apps_script` directory. ## Flow of events @@ -205,10 +209,10 @@ by the PaLM model: - Additional condition (for fact-checking): ``` - Can you compare the following text to the context provided in this prompt and write - a short message that warns the readers about which part of the text they should - consider fact-checking? (Please keep your response concise and focus on only - one important item.) + Can you compare the text below to the context provided + in this prompt above and write a short message that warns the readers about + which part of the text they should consider fact-checking? (Please keep your + response concise and focus on only one important item.)" ``` - Previously generated response @@ -597,20 +601,18 @@ To launch the Docs Agent chat app, do the following: ``` $ poetry run ./chatbot/launch.sh - This script starts your flask app in a virtual environment - Installing all dependencies through pip... - Using the local vector database created at /home/alice/generative-ai-docs/demos/palm/python/docs-agent/vector_database - Using embedded DuckDB with persistence: data will be stored in: /home/alice/generative-ai-docs/demos/palm/python/docs-agent/vector_database + Reading the config file: /home/alice/docs-agent/config.yaml + Reading the config file: /home/alice/docs-agent/config.yaml * Serving Flask app 'chatbot' * Debug mode: on - WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. + INFO:werkzeug:WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on http://example.com:5000 - Press CTRL+C to quit - * Restarting with stat - Using the local vector database created at /home/alice/generative-ai-docs/demos/palm/python/docs-agent/vector_database - Using embedded DuckDB with persistence: data will be stored in: /home/alice/generative-ai-docs/demos/palm/python/docs-agent/vector_database - * Debugger is active! - * Debugger PIN: 129-640-957 + INFO:werkzeug:Press CTRL+C to quit + INFO:werkzeug: * Restarting with stat + Reading the config file: /home/alice/docs-agent/config.yaml + Reading the config file: /home/alice/docs-agent/config.yaml + WARNING:werkzeug: * Debugger is active! + INFO:werkzeug: * Debugger PIN: 825-594-989 ``` Notice the line that shows the URL of this server (`http://example.com:5000` in diff --git a/demos/palm/python/docs-agent/chatbot/chatui.py b/demos/palm/python/docs-agent/chatbot/chatui.py index 4b6c64bcf..d6982cb7f 100644 --- a/demos/palm/python/docs-agent/chatbot/chatui.py +++ b/demos/palm/python/docs-agent/chatbot/chatui.py @@ -143,13 +143,13 @@ def ask_model(question): # 3. Add the custom condition text to the context. # 4. Send the prompt (condition + context + question) to the language model. query_result = docs_agent.query_vector_store(question) - context = markdown.markdown(query_result.fetch_formatted(Format.CONTEXT)) - context_with_prefix = docs_agent.add_instruction_to_context(context) - response = docs_agent.ask_text_model_with_context(context_with_prefix, question) + context = query_result.fetch_formatted(Format.CONTEXT) + context_with_instruction = docs_agent.add_instruction_to_context(context) + response = docs_agent.ask_text_model_with_context(context_with_instruction, question) ### PROMPT 2: FACT-CHECK THE PREVIOUS RESPONSE. fact_checked_response = docs_agent.ask_text_model_to_fact_check( - context_with_prefix, response + context_with_instruction, response ) ### PROMPT 3: GET 5 RELATED QUESTIONS. @@ -176,10 +176,12 @@ def ask_model(question): ### PREPARE OTHER ELEMENTS NEEDED BY UI. # - Create a uuid for this request. + # - Convert the context returned from the database into HTML for rendering. # - Convert the first response from the model into HTML for rendering. # - Convert the fact-check response from the model into HTML for rendering. # - A workaround to get the server's URL to work with the rewrite and like features. new_uuid = uuid.uuid1() + context_in_html = markdown.markdown(context) response_in_html = markdown.markdown(response) fact_checked_response_in_html = markdown.markdown(fact_checked_response) server_url = request.url_root.replace("http", "https") @@ -190,7 +192,7 @@ def ask_model(question): return render_template( "chatui/index.html", question=question, - context=context, + context_in_html=context_in_html, response=response, response_in_html=response_in_html, clickable_urls=clickable_urls, diff --git a/demos/palm/python/docs-agent/chatbot/templates/chatui/result.html b/demos/palm/python/docs-agent/chatbot/templates/chatui/result.html index d02d95425..60d1a30c3 100644 --- a/demos/palm/python/docs-agent/chatbot/templates/chatui/result.html +++ b/demos/palm/python/docs-agent/chatbot/templates/chatui/result.html @@ -22,7 +22,7 @@