Skip to content

Commit 6175868

Browse files
committed
[Release] Docs Agent version 0.3.1
What's changed: - Bug fixes in the Docs Agent web app UI. - Added more templates for the Docs Agent web app: widget and experimental - A new custom splitter added: FIDL (.fidl) file specific splitter.
1 parent 4582535 commit 6175868

File tree

22 files changed

+1983
-90
lines changed

22 files changed

+1983
-90
lines changed

examples/gemini/python/docs-agent/apps_script/exportmd.gs

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/gemini/python/docs-agent/apps_script/exportmd.gs

Lines changed: 1308 additions & 0 deletions
Large diffs are not rendered by default.

examples/gemini/python/docs-agent/docs_agent/interfaces/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,21 @@ credentials (via `gcloud`) stored on your host machine.
116116
(`application_default_credentials.json`) in the `$HOME/.config/gcloud/`
117117
directory of your host machine.
118118

119-
## 4. Clone the Docs Agent project
119+
## 4. Clone the Docs Agent project repository
120120

121121
**Note**: This guide assumes that you're creating a new project directory
122122
from your `$HOME` directory.
123123

124-
1. Clone the following repo:
124+
1. Clone the following internal repo:
125125

126126
```posix-terminal
127-
git clone https://github.com/google/generative-ai-docs.git
127+
git clone sso://doc-llm-internal/docs-agent
128128
```
129129

130-
2. Go to the Docs Agent project directory:
130+
2. Go to the project directory:
131131

132132
```posix-terminal
133-
cd generative-ai-docs/examples/gemini/python/docs-agent
133+
cd docs-agent
134134
```
135135

136136
3. Install dependencies using `poetry`:
@@ -139,6 +139,8 @@ from your `$HOME` directory.
139139
poetry install
140140
```
141141

142+
This may take some time to complete.
143+
142144
## 5. Set up an alias to the gemini command
143145

144146
**Note**: If your Docs Agent project is not cloned in the `$HOME` directory,

examples/gemini/python/docs-agent/docs_agent/interfaces/chatbot/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from docs_agent.utilities import config
2020

2121

22-
def create_app(product: config.ProductConfig):
22+
def create_app(product: config.ProductConfig, app_mode: str = "web"):
2323
app = Flask(__name__)
24-
app.register_blueprint(chatui.construct_blueprint(product_config=product))
24+
app.register_blueprint(chatui.construct_blueprint(product_config=product, app_mode=app_mode))
2525
return app

examples/gemini/python/docs-agent/docs_agent/interfaces/chatbot/chatui.py

Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,32 @@
4545

4646

4747
# This is used to define the app blueprint using a productConfig
48-
def construct_blueprint(product_config: config.ProductConfig):
48+
def construct_blueprint(product_config: config.ProductConfig, app_mode: str = None):
4949
bp = Blueprint("chatui", __name__)
5050
if product_config.db_type == "google_semantic_retriever":
5151
docs_agent = DocsAgent(config=product_config, init_chroma=False)
5252
else:
5353
docs_agent = DocsAgent(config=product_config)
54-
logging.info(f"Launching the flask app for product: {product_config.product_name}")
54+
logging.info(f"Launching the Flask app for product: {product_config.product_name} with app_mode: {app_mode}")
55+
# Assign templates and redirects
56+
if app_mode == "web":
57+
app_template = "chatui/index.html"
58+
redirect_index = "chatui.index"
59+
elif app_mode == "experimental":
60+
app_template = "chatui-experimental/index.html"
61+
redirect_index = "chatui-experimental.index"
62+
elif app_mode == "widget":
63+
app_template = "chat-widget/index.html"
64+
redirect_index = "chat-widget.index"
65+
else:
66+
app_template = "chatui/index.html"
67+
redirect_index = "chatui.index"
5568

5669
@bp.route("/", methods=["GET", "POST"])
5770
def index():
5871
server_url = request.url_root.replace("http", "https")
5972
return render_template(
60-
"chatui/index.html",
73+
app_template,
6174
product=product_config.product_name,
6275
server_url=server_url,
6376
)
@@ -73,7 +86,7 @@ def api():
7386
context,
7487
sources_ref,
7588
plain_token,
76-
) = ask_model_2_with_sources(input["question"], agent=docs_agent)
89+
) = ask_model_with_sources(input["question"], agent=docs_agent)
7790
source_array = []
7891
for source in sources_ref:
7992
source_array.append(source.returnDictionary())
@@ -100,7 +113,7 @@ def like():
100113
log_like(is_like, str(uuid_found).strip())
101114
return "OK"
102115
else:
103-
return redirect(url_for("chatui.index"))
116+
return redirect(url_for(redirect_index))
104117

105118
@bp.route("/rewrite", methods=["GET", "POST"])
106119
def rewrite():
@@ -149,54 +162,35 @@ def rewrite():
149162
file.close()
150163
return "OK"
151164
else:
152-
if product_config.docs_agent_config == "experimental":
153-
return redirect(url_for("chatui.index_experimental"))
154-
elif product_config.docs_agent_config == "normal":
155-
return redirect(url_for("chatui.index"))
165+
return redirect(url_for(redirect_index))
156166

157167
# Render a response page when the user asks a question
158168
# using input text box.
159169
@bp.route("/result", methods=["GET", "POST"])
160170
def result():
161171
if request.method == "POST":
162172
question = request.form["question"]
163-
if product_config.docs_agent_config == "experimental":
164-
return ask_model2(question, agent=docs_agent, template="chatui/index_experimental.html")
165-
elif product_config.docs_agent_config == "normal":
166-
return ask_model2(
167-
question, agent=docs_agent, template="chatui/index.html"
168-
)
173+
return ask_model(question, agent=docs_agent, template=app_template)
169174
else:
170-
if product_config.docs_agent_config == "experimental":
171-
return redirect(url_for("chatui.index_experimental"))
172-
elif product_config.docs_agent_config == "normal":
173-
return redirect(url_for("chatui.index"))
175+
return redirect(url_for(redirect_index))
174176

175177
# Render a response page when the user clicks a question
176178
# from the related questions list.
177179
@bp.route("/question/<ask>", methods=["GET", "POST"])
178180
def question(ask):
179181
if request.method == "GET":
180182
question = urllib.parse.unquote_plus(ask)
181-
if product_config.docs_agent_config == "experimental":
182-
return ask_model2(question, agent=docs_agent, template="chatui/index_experimental.html")
183-
elif product_config.docs_agent_config == "normal":
184-
return ask_model2(
185-
question, agent=docs_agent, template="chatui/index.html"
186-
)
183+
return ask_model(question, agent=docs_agent, template=app_template)
187184
else:
188-
if product_config.docs_agent_config == "experimental":
189-
return redirect(url_for("chatui.index_expiremental"))
190-
elif product_config.docs_agent_config == "normal":
191-
return redirect(url_for("chatui.index"))
185+
return redirect(url_for(redirect_index))
192186

193187
return bp
194188

195189

196190
# Construct a set of prompts using the user question, send the prompts to
197191
# the lanaguage model, receive responses, and present them into a page.
198192
# Use template to specify a custom template for the classic web UI
199-
def ask_model2(question, agent, template: str = "chatui/index.html"):
193+
def ask_model(question, agent, template: str = "chatui/index.html"):
200194
# Returns a built context, a total token count of the context and an array
201195
# of sourceOBJ
202196
full_prompt = ""
@@ -307,7 +301,7 @@ def ask_model2(question, agent, template: str = "chatui/index.html"):
307301
# Not fully implemented
308302
# This method is used for the API endpoint, so it returns values that can be
309303
# packaged as JSON
310-
def ask_model_2_with_sources(question, agent):
304+
def ask_model_with_sources(question, agent):
311305
docs_agent = agent
312306
full_prompt = ""
313307
context, plain_token, sources_ref = docs_agent.query_vector_store_to_build(

examples/gemini/python/docs-agent/docs_agent/interfaces/chatbot/static/css/style-chatui.css

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,18 +93,20 @@ body {
9393
font-size: 0.9em;
9494
font-family: system-ui;
9595
line-height: 150%;
96+
word-break: break-word;
9697
padding: 4px;
9798
}
9899

99100
#response-box {
100101
font-size: 1.0em;
101102
font-family: sans-serif;
102-
line-height: 100%;
103+
line-height: 140%;
103104
margin-top: 10px;
104105
}
105106

106107
#suggested-questions {
107108
font-family: sans-serif;
109+
word-break: break-word;
108110
}
109111

110112
#context-content{
@@ -176,6 +178,13 @@ body {
176178
margin-top: 12px;
177179
}
178180

181+
#answerable-span {
182+
font-size: small;
183+
font-family: system-ui;
184+
float: right;
185+
padding: 10px;
186+
}
187+
179188
/* ======= Style by class ======= */
180189

181190
.hidden {
@@ -240,6 +249,7 @@ body {
240249
.related-questions {
241250
margin-bottom: 20px;
242251
font-size: 0.9em;
252+
line-height: 140%;
243253
}
244254

245255
/* ======= Style buttons by ID ======= */
@@ -291,7 +301,7 @@ body {
291301
#edit-text-area {
292302
font: 13px/1.5em Overpass, "Open Sans", Helvetica, sans-serif;
293303
max-height: 500px;
294-
max-width: 650px;
304+
max-width: -webkit-fill-available;
295305
height: 300px;
296306
width: 650px;
297307
padding: 8px;
@@ -340,7 +350,7 @@ body {
340350

341351
.search input[type="text"] {
342352
border: 0;
343-
width: 91%;
353+
width: calc(100% - 65px);
344354
padding: 10px;
345355
}
346356

@@ -505,3 +515,17 @@ body {
505515
margin-bottom: 0;
506516
}
507517

518+
/* Loader animation */
519+
/* Source: https://css-loaders.com/classic/ */
520+
.loader {
521+
width: fit-content;
522+
font-family: monospace;
523+
font-size: 14px;
524+
margin-left: 13px;
525+
clip-path: inset(0 3ch 0 0);
526+
animation: animation 1s steps(4) infinite;
527+
}
528+
.loader:before {
529+
content:"Generating a response..."
530+
}
531+
@keyframes animation {to{clip-path: inset(0 -1ch 0 0)}}

0 commit comments

Comments
 (0)