Skip to content

Commit e0d216f

Browse files
authored
[Release] Docs Agent version 0.1.4 (google#167)
What's changed: - Bug fix: Update `docs_agent.py` to remove a no-longer-in-use error message variable. - Clean up the prompt format in Docs Agent - Context is added to prompts as Markdown - Remove extra new lines in context - Add extra new lines after the instruction and before the question in prompts. - Remove the warning message in the Chroma module, which as displayed when launching the chatbot. - Update the embeddings diagrams in the main `README` file. - Minor updates in the main `README` file.
1 parent 998c2f5 commit e0d216f

File tree

10 files changed

+39
-35
lines changed

10 files changed

+39
-35
lines changed

demos/palm/python/docs-agent/README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ The following list summarizes the tasks and features of the Docs Agent sample ap
125125
the responses. (See the
126126
[Enabling users to submit a rewrite of a generated response][submit-a-rewrite] and
127127
[Enabling users to like generated responses][like-generate-responses] sections.)
128+
- **Convert Google Docs, PDF, and Gmail into Markdown files**: This feature uses
129+
Apps Script to convert Google Docs, PDF, and Gmail into Markdown files, which then
130+
can be used as input datasets for Docs Agent. For more information, see the
131+
[`README`][apps-script-readme] file in the `apps_script` directory.
128132

129133
## Flow of events
130134

@@ -205,10 +209,10 @@ by the PaLM model:
205209
- Additional condition (for fact-checking):
206210

207211
```
208-
Can you compare the following text to the context provided in this prompt and write
209-
a short message that warns the readers about which part of the text they should
210-
consider fact-checking? (Please keep your response concise and focus on only
211-
one important item.)
212+
Can you compare the text below to the context provided
213+
in this prompt above and write a short message that warns the readers about
214+
which part of the text they should consider fact-checking? (Please keep your
215+
response concise and focus on only one important item.)"
212216
```
213217

214218
- Previously generated response
@@ -597,20 +601,18 @@ To launch the Docs Agent chat app, do the following:
597601

598602
```
599603
$ poetry run ./chatbot/launch.sh
600-
This script starts your flask app in a virtual environment
601-
Installing all dependencies through pip...
602-
Using the local vector database created at /home/alice/generative-ai-docs/demos/palm/python/docs-agent/vector_database
603-
Using embedded DuckDB with persistence: data will be stored in: /home/alice/generative-ai-docs/demos/palm/python/docs-agent/vector_database
604+
Reading the config file: /home/alice/docs-agent/config.yaml
605+
Reading the config file: /home/alice/docs-agent/config.yaml
604606
* Serving Flask app 'chatbot'
605607
* Debug mode: on
606-
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
608+
INFO:werkzeug:WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
607609
* Running on http://example.com:5000
608-
Press CTRL+C to quit
609-
* Restarting with stat
610-
Using the local vector database created at /home/alice/generative-ai-docs/demos/palm/python/docs-agent/vector_database
611-
Using embedded DuckDB with persistence: data will be stored in: /home/alice/generative-ai-docs/demos/palm/python/docs-agent/vector_database
612-
* Debugger is active!
613-
* Debugger PIN: 129-640-957
610+
INFO:werkzeug:Press CTRL+C to quit
611+
INFO:werkzeug: * Restarting with stat
612+
Reading the config file: /home/alice/docs-agent/config.yaml
613+
Reading the config file: /home/alice/docs-agent/config.yaml
614+
WARNING:werkzeug: * Debugger is active!
615+
INFO:werkzeug: * Debugger PIN: 825-594-989
614616
```
615617

616618
Notice the line that shows the URL of this server (`http://example.com:5000` in

demos/palm/python/docs-agent/chatbot/chatui.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,13 @@ def ask_model(question):
143143
# 3. Add the custom condition text to the context.
144144
# 4. Send the prompt (condition + context + question) to the language model.
145145
query_result = docs_agent.query_vector_store(question)
146-
context = markdown.markdown(query_result.fetch_formatted(Format.CONTEXT))
147-
context_with_prefix = docs_agent.add_instruction_to_context(context)
148-
response = docs_agent.ask_text_model_with_context(context_with_prefix, question)
146+
context = query_result.fetch_formatted(Format.CONTEXT)
147+
context_with_instruction = docs_agent.add_instruction_to_context(context)
148+
response = docs_agent.ask_text_model_with_context(context_with_instruction, question)
149149

150150
### PROMPT 2: FACT-CHECK THE PREVIOUS RESPONSE.
151151
fact_checked_response = docs_agent.ask_text_model_to_fact_check(
152-
context_with_prefix, response
152+
context_with_instruction, response
153153
)
154154

155155
### PROMPT 3: GET 5 RELATED QUESTIONS.
@@ -176,10 +176,12 @@ def ask_model(question):
176176

177177
### PREPARE OTHER ELEMENTS NEEDED BY UI.
178178
# - Create a uuid for this request.
179+
# - Convert the context returned from the database into HTML for rendering.
179180
# - Convert the first response from the model into HTML for rendering.
180181
# - Convert the fact-check response from the model into HTML for rendering.
181182
# - A workaround to get the server's URL to work with the rewrite and like features.
182183
new_uuid = uuid.uuid1()
184+
context_in_html = markdown.markdown(context)
183185
response_in_html = markdown.markdown(response)
184186
fact_checked_response_in_html = markdown.markdown(fact_checked_response)
185187
server_url = request.url_root.replace("http", "https")
@@ -190,7 +192,7 @@ def ask_model(question):
190192
return render_template(
191193
"chatui/index.html",
192194
question=question,
193-
context=context,
195+
context_in_html=context_in_html,
194196
response=response,
195197
response_in_html=response_in_html,
196198
clickable_urls=clickable_urls,

demos/palm/python/docs-agent/chatbot/templates/chatui/result.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ <h2 class="handle">
2222
<label for="handle1">Context</label>
2323
</h2>
2424
<div class="content">
25-
{{ context | safe }}
25+
{{ context_in_html | safe }}
2626
<span class="reference-content">
2727
<h4>Reference:</h4>
2828
{{ clickable_urls | safe }}

demos/palm/python/docs-agent/chroma.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ def get_collection(self, name, embedding_function=None):
6969
)
7070
elif embedding_model is None or embedding_model == "palm/embedding-gecko-001":
7171
if embedding_model is None:
72-
logging.warning(
73-
"Embedding model is not stored in the metadata of "
74-
"the collection %s. Using PaLM as default.",
72+
logging.info(
73+
"Embedding model is not specified in the metadata of "
74+
"the collection %s. Using the default PaLM embedding model.",
7575
name,
7676
)
7777
palm = PaLM(embed_model="models/embedding-gecko-001", find_models=False)
@@ -138,7 +138,7 @@ def __init__(self, result: QueryResult, index: int) -> None:
138138

139139
def format(self, format_type: Format, ref_index: int = None):
140140
d = {
141-
"document": self.document,
141+
"document": self.document.strip(),
142142
"ref_index": ref_index,
143143
"url": self.metadata.get("url", None),
144144
"distance": self.distance,

demos/palm/python/docs-agent/config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ input:
7373
condition_text: "You are a helpful chatbot answering questions from users. Read
7474
the following context first and answer the question at the end:"
7575

76-
fact_check_question: "Can you compare the following text to the context provided
77-
in this prompt and write a short message that warns the readers about which part
78-
of the text they should consider fact-checking? (Please keep your response
79-
concise and focus on only one important item.)"
76+
fact_check_question: "Can you compare the text below to the context provided
77+
in this prompt above and write a short message that warns the readers about
78+
which part of the text they should consider fact-checking? (Please keep your
79+
response concise and focus on only one important item.)"
8080

8181
model_error_message: "PaLM is not able to answer this question at the
8282
moment. Rephrase the question and try asking again."
-37.6 KB
Loading
74.7 KB
Loading

demos/palm/python/docs-agent/docs_agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def __init__(self):
7373

7474
# Use this method for talking to PaLM (Text)
7575
def ask_text_model_with_context(self, context, question):
76-
new_prompt = f"{context}\nQuestion: {question}"
76+
new_prompt = f"{context}\n\nQuestion: {question}"
7777
try:
7878
response = palm.generate_text(
7979
prompt=new_prompt,
@@ -101,7 +101,7 @@ def ask_chat_model_with_context(self, context, question):
101101
return self.model_error_message
102102

103103
if response.last is None:
104-
return self.palm_none_response
104+
return self.model_error_message
105105
return response.last
106106

107107
# Use this method for asking PaLM (Text) for fact-checking
@@ -117,5 +117,5 @@ def query_vector_store(self, question):
117117
# Add specific instruction as a prefix to the context
118118
def add_instruction_to_context(self, context):
119119
new_context = ""
120-
new_context += self.prompt_condition + "\n" + context
120+
new_context += self.prompt_condition + "\n\n" + context
121121
return new_context

demos/palm/python/docs-agent/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "docs-agent"
3-
version = "0.1.3"
3+
version = "0.1.4"
44
description = ""
55
authors = ["Docs Agent contributors"]
66
readme = "README.md"

demos/palm/python/docs-agent/scripts/read_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ def __init__(self):
4343
with open(INPUT_YAML, "r", encoding="utf-8") as inp_yaml:
4444
self.config_values = yaml.safe_load(inp_yaml)
4545
self.IS_CONFIG_FILE = True
46-
print("Configuration defined in: " + INPUT_YAML)
46+
print("Reading the config file: " + INPUT_YAML)
4747
# Check that the required keys exist
4848
self.validateKeys()
4949
except FileNotFoundError:
50-
print("The file " + INPUT_YAML + " does not exist.")
50+
print("The config file " + INPUT_YAML + " does not exist.")
5151
# Exits the scripts if there is no valid config file
5252
return sys.exit(1)
5353

0 commit comments

Comments
 (0)