Skip to content

Various UI and backend improvements #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ A related option is VS Code Dev Containers, which will open the project in your
1. Start Docker Desktop (install it if not already installed)
2. Open the project:

[![Open in Dev Containers](https://img.shields.io/static/v1?style=for-the-badge&label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](placeholder)
[![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)

3. In the VS Code window that opens, once the project files show up (this may take several minutes), open a terminal window.
4. Continue with the [deployment steps](#deployment)
Expand Down Expand Up @@ -135,15 +135,25 @@ Since the local app uses OpenAI models, you should first deploy it for the optim

If you opened the project in Codespaces or a Dev Container, these commands will already have been run for you.

2. Run the FastAPI backend:
2. Build the frontend:

```bash
cd src/frontend
npm install
npm run build
```

There must be an initial build of static assets before running the backend, since the backend serves static files from the `src/static` directory.

3. Run the FastAPI backend (with hot reloading):

```shell
python3 -m uvicorn fastapi_app:create_app --factory --reload
```

Or you can run "Backend" in the VS Code Run & Debug menu.

3. Run the frontend:
4. Run the frontend (with hot reloading):

```bash
cd src/frontend
Expand All @@ -152,7 +162,7 @@ Since the local app uses OpenAI models, you should first deploy it for the optim

Or you can run "Frontend" or "Frontend & Backend" in the VS Code Run & Debug menu.

4. Open the browser at `http://localhost:5173/` and you will see the frontend.
5. Open the browser at `http://localhost:5173/` and you will see the frontend.

## Costs

Expand All @@ -161,6 +171,7 @@ You may try the [Azure pricing calculator](https://azure.microsoft.com/pricing/c

* Azure Container Apps: Pay-as-you-go tier. Costs based on vCPU and memory used. [Pricing](https://azure.microsoft.com/pricing/details/container-apps/)
* 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/)
* 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/)
* Azure Monitor: Pay-as-you-go tier. Costs based on data ingested. [Pricing](https://azure.microsoft.com/pricing/details/monitor/)

## Security Guidelines
Expand Down
74 changes: 38 additions & 36 deletions src/fastapi_app/rag_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,42 +99,44 @@ async def run(
n=1,
stream=False,
)
chat_resp = chat_completion_response.model_dump()
chat_resp["choices"][0]["context"] = {
"data_points": {"text": sources_content},
"thoughts": [
ThoughtStep(
title="Prompt to generate search arguments",
description=[str(message) for message in query_messages],
props=(
{"model": self.chat_model, "deployment": self.chat_deployment}
if self.chat_deployment
else {"model": self.chat_model}
first_choice = chat_completion_response.model_dump()["choices"][0]
return {
"message": first_choice["message"],
"context": {
"data_points": {item.id: item.to_dict() for item in results},
"thoughts": [
ThoughtStep(
title="Prompt to generate search arguments",
description=[str(message) for message in query_messages],
props=(
{"model": self.chat_model, "deployment": self.chat_deployment}
if self.chat_deployment
else {"model": self.chat_model}
),
),
),
ThoughtStep(
title="Search using generated search arguments",
description=query_text,
props={
"top": top,
"vector_search": vector_search,
"text_search": text_search,
"filters": filters,
},
),
ThoughtStep(
title="Search results",
description=[result.to_dict() for result in results],
),
ThoughtStep(
title="Prompt to generate answer",
description=[str(message) for message in messages],
props=(
{"model": self.chat_model, "deployment": self.chat_deployment}
if self.chat_deployment
else {"model": self.chat_model}
ThoughtStep(
title="Search using generated search arguments",
description=query_text,
props={
"top": top,
"vector_search": vector_search,
"text_search": text_search,
"filters": filters,
},
),
),
],
ThoughtStep(
title="Search results",
description=[result.to_dict() for result in results],
),
ThoughtStep(
title="Prompt to generate answer",
description=[str(message) for message in messages],
props=(
{"model": self.chat_model, "deployment": self.chat_deployment}
if self.chat_deployment
else {"model": self.chat_model}
),
),
],
},
}
return chat_resp
56 changes: 29 additions & 27 deletions src/fastapi_app/rag_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,32 +66,34 @@ async def run(
n=1,
stream=False,
)
chat_resp = chat_completion_response.model_dump()
chat_resp["choices"][0]["context"] = {
"data_points": {"text": sources_content},
"thoughts": [
ThoughtStep(
title="Search query for database",
description=original_user_query if text_search else None,
props={
"top": top,
"vector_search": vector_search,
"text_search": text_search,
},
),
ThoughtStep(
title="Search results",
description=[result.to_dict() for result in results],
),
ThoughtStep(
title="Prompt to generate answer",
description=[str(message) for message in messages],
props=(
{"model": self.chat_model, "deployment": self.chat_deployment}
if self.chat_deployment
else {"model": self.chat_model}
first_choice = chat_completion_response.model_dump()["choices"][0]
return {
"message": first_choice["message"],
"context": {
"data_points": {item.id: item.to_dict() for item in results},
"thoughts": [
ThoughtStep(
title="Search query for database",
description=original_user_query if text_search else None,
props={
"top": top,
"vector_search": vector_search,
"text_search": text_search,
},
),
),
],
ThoughtStep(
title="Search results",
description=[result.to_dict() for result in results],
),
ThoughtStep(
title="Prompt to generate answer",
description=[str(message) for message in messages],
props=(
{"model": self.chat_model, "deployment": self.chat_deployment}
if self.chat_deployment
else {"model": self.chat_model}
),
),
],
},
}
return chat_resp
Loading