Skip to content

Commit 7da549c

Browse files
authored
Merge pull request Azure-Samples#43 from Azure-Samples/improvements
Various UI and backend improvements
2 parents 6df6e20 + e6a0fda commit 7da549c

File tree

12 files changed

+238
-216
lines changed

12 files changed

+238
-216
lines changed

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ A related option is VS Code Dev Containers, which will open the project in your
4848
1. Start Docker Desktop (install it if not already installed)
4949
2. Open the project:
5050

51-
[![Open in Dev Containers](https://img.shields.io/static/v1?style=for-the-badge&label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](placeholder)
51+
[![Open in Dev Containers](https://img.shields.io/static/v1?style=for-the-badge&label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/azure-samples/rag-postgres-openai-python)
5252

5353
3. In the VS Code window that opens, once the project files show up (this may take several minutes), open a terminal window.
5454
4. Continue with the [deployment steps](#deployment)
@@ -135,15 +135,25 @@ Since the local app uses OpenAI models, you should first deploy it for the optim
135135
136136
If you opened the project in Codespaces or a Dev Container, these commands will already have been run for you.
137137
138-
2. Run the FastAPI backend:
138+
2. Build the frontend:
139+
140+
```bash
141+
cd src/frontend
142+
npm install
143+
npm run build
144+
```
145+
146+
There must be an initial build of static assets before running the backend, since the backend serves static files from the `src/static` directory.
147+
148+
3. Run the FastAPI backend (with hot reloading):
139149
140150
```shell
141151
python3 -m uvicorn fastapi_app:create_app --factory --reload
142152
```
143153
144154
Or you can run "Backend" in the VS Code Run & Debug menu.
145155
146-
3. Run the frontend:
156+
4. Run the frontend (with hot reloading):
147157
148158
```bash
149159
cd src/frontend
@@ -152,7 +162,7 @@ Since the local app uses OpenAI models, you should first deploy it for the optim
152162
153163
Or you can run "Frontend" or "Frontend & Backend" in the VS Code Run & Debug menu.
154164
155-
4. Open the browser at `http://localhost:5173/` and you will see the frontend.
165+
5. Open the browser at `http://localhost:5173/` and you will see the frontend.
156166
157167
## Costs
158168
@@ -161,6 +171,7 @@ You may try the [Azure pricing calculator](https://azure.microsoft.com/pricing/c
161171
162172
* Azure Container Apps: Pay-as-you-go tier. Costs based on vCPU and memory used. [Pricing](https://azure.microsoft.com/pricing/details/container-apps/)
163173
* Azure OpenAI: Standard tier, GPT and Ada models. Pricing per 1K tokens used, and at least 1K tokens are used per question. [Pricing](https://azure.microsoft.com/pricing/details/cognitive-services/openai-service/)
174+
* Azure PostgreSQL Flexible Server: Burstable Tier with 1 CPU core, 32GB storage. Pricing is hourly. [Pricing](https://azure.microsoft.com/pricing/details/postgresql/flexible-server/)
164175
* Azure Monitor: Pay-as-you-go tier. Costs based on data ingested. [Pricing](https://azure.microsoft.com/pricing/details/monitor/)
165176
166177
## Security Guidelines

src/fastapi_app/rag_advanced.py

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -99,42 +99,44 @@ async def run(
9999
n=1,
100100
stream=False,
101101
)
102-
chat_resp = chat_completion_response.model_dump()
103-
chat_resp["choices"][0]["context"] = {
104-
"data_points": {"text": sources_content},
105-
"thoughts": [
106-
ThoughtStep(
107-
title="Prompt to generate search arguments",
108-
description=[str(message) for message in query_messages],
109-
props=(
110-
{"model": self.chat_model, "deployment": self.chat_deployment}
111-
if self.chat_deployment
112-
else {"model": self.chat_model}
102+
first_choice = chat_completion_response.model_dump()["choices"][0]
103+
return {
104+
"message": first_choice["message"],
105+
"context": {
106+
"data_points": {item.id: item.to_dict() for item in results},
107+
"thoughts": [
108+
ThoughtStep(
109+
title="Prompt to generate search arguments",
110+
description=[str(message) for message in query_messages],
111+
props=(
112+
{"model": self.chat_model, "deployment": self.chat_deployment}
113+
if self.chat_deployment
114+
else {"model": self.chat_model}
115+
),
113116
),
114-
),
115-
ThoughtStep(
116-
title="Search using generated search arguments",
117-
description=query_text,
118-
props={
119-
"top": top,
120-
"vector_search": vector_search,
121-
"text_search": text_search,
122-
"filters": filters,
123-
},
124-
),
125-
ThoughtStep(
126-
title="Search results",
127-
description=[result.to_dict() for result in results],
128-
),
129-
ThoughtStep(
130-
title="Prompt to generate answer",
131-
description=[str(message) for message in messages],
132-
props=(
133-
{"model": self.chat_model, "deployment": self.chat_deployment}
134-
if self.chat_deployment
135-
else {"model": self.chat_model}
117+
ThoughtStep(
118+
title="Search using generated search arguments",
119+
description=query_text,
120+
props={
121+
"top": top,
122+
"vector_search": vector_search,
123+
"text_search": text_search,
124+
"filters": filters,
125+
},
136126
),
137-
),
138-
],
127+
ThoughtStep(
128+
title="Search results",
129+
description=[result.to_dict() for result in results],
130+
),
131+
ThoughtStep(
132+
title="Prompt to generate answer",
133+
description=[str(message) for message in messages],
134+
props=(
135+
{"model": self.chat_model, "deployment": self.chat_deployment}
136+
if self.chat_deployment
137+
else {"model": self.chat_model}
138+
),
139+
),
140+
],
141+
},
139142
}
140-
return chat_resp

src/fastapi_app/rag_simple.py

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -66,32 +66,34 @@ async def run(
6666
n=1,
6767
stream=False,
6868
)
69-
chat_resp = chat_completion_response.model_dump()
70-
chat_resp["choices"][0]["context"] = {
71-
"data_points": {"text": sources_content},
72-
"thoughts": [
73-
ThoughtStep(
74-
title="Search query for database",
75-
description=original_user_query if text_search else None,
76-
props={
77-
"top": top,
78-
"vector_search": vector_search,
79-
"text_search": text_search,
80-
},
81-
),
82-
ThoughtStep(
83-
title="Search results",
84-
description=[result.to_dict() for result in results],
85-
),
86-
ThoughtStep(
87-
title="Prompt to generate answer",
88-
description=[str(message) for message in messages],
89-
props=(
90-
{"model": self.chat_model, "deployment": self.chat_deployment}
91-
if self.chat_deployment
92-
else {"model": self.chat_model}
69+
first_choice = chat_completion_response.model_dump()["choices"][0]
70+
return {
71+
"message": first_choice["message"],
72+
"context": {
73+
"data_points": {item.id: item.to_dict() for item in results},
74+
"thoughts": [
75+
ThoughtStep(
76+
title="Search query for database",
77+
description=original_user_query if text_search else None,
78+
props={
79+
"top": top,
80+
"vector_search": vector_search,
81+
"text_search": text_search,
82+
},
9383
),
94-
),
95-
],
84+
ThoughtStep(
85+
title="Search results",
86+
description=[result.to_dict() for result in results],
87+
),
88+
ThoughtStep(
89+
title="Prompt to generate answer",
90+
description=[str(message) for message in messages],
91+
props=(
92+
{"model": self.chat_model, "deployment": self.chat_deployment}
93+
if self.chat_deployment
94+
else {"model": self.chat_model}
95+
),
96+
),
97+
],
98+
},
9699
}
97-
return chat_resp

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy