Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
9 changes: 2 additions & 7 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ If necessary, edit this file to ensure it accurately reflects the current state
* app: Contains the main application code, including frontend and backend.
* app/backend: Contains the Python backend code, written with Quart framework.
* app/backend/approaches: Contains the different approaches
* app/backend/approaches/approach.py: Base class for all approaches
* app/backend/approaches/retrievethenread.py: Ask approach, just searches and answers
* app/backend/approaches/chatreadretrieveread.py: Chat approach, includes query rewriting step first
* app/backend/approaches/prompts/ask_answer_question.prompty: Prompt used by the Ask approach to answer the question based off sources
* app/backend/approaches/approach.py: Main RAG approach class with query rewriting and retrieval
* app/backend/approaches/prompts/chat_query_rewrite.prompty: Prompt used to rewrite the query based off search history into a better search query
* app/backend/approaches/prompts/chat_query_rewrite_tools.json: Tools used by the query rewriting prompt
* app/backend/approaches/prompts/chat_answer_question.prompty: Prompt used by the Chat approach to actually answer the question based off sources
Expand Down Expand Up @@ -86,11 +83,9 @@ When adding a new developer setting, update:
* app/frontend/src/components/Settings.tsx : Add a UI element for the setting
* app/frontend/src/locales/*/translations.json: Add a translation for the setting label/tooltip for all languages
* app/frontend/src/pages/chat/Chat.tsx: Add the setting to the component, pass it to Settings
* app/frontend/src/pages/ask/Ask.tsx: Add the setting to the component, pass it to Settings

* backend:
* app/backend/approaches/chatreadretrieveread.py : Retrieve from overrides parameter
* app/backend/approaches/retrievethenread.py : Retrieve from overrides parameter
* app/backend/approaches/approach.py : Retrieve from overrides parameter
* app/backend/app.py: Some settings may need to be sent down in the /config route.

## When adding tests for a new feature
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ The repo includes sample data so it's ready to try end to end. In this sample ap

## Features

- Chat (multi-turn) and Q&A (single turn) interfaces
- Chat (multi-turn) interface
- Renders citations and thought process for each answer
- Includes settings directly in the UI to tweak the behavior and experiment with options
- Integrates Azure AI Search for indexing and retrieval of documents, with support for [many document formats](/docs/data_ingestion.md#supported-document-formats) as well as [cloud data ingestion](/docs/data_ingestion.md#cloud-data-ingestion)
Expand Down Expand Up @@ -228,7 +228,7 @@ See more tips in [the local development guide](docs/localdev.md).

Once in the web app:

- Try different topics in chat or Q&A context. For chat, try follow up questions, clarifications, ask to simplify or elaborate on answer, etc.
- Try different topics in chat. Try follow up questions, clarifications, ask to simplify or elaborate on answer, etc.
- Explore citations and sources
- Click on "settings" to try different options, tweak prompts, etc.

Expand Down
59 changes: 2 additions & 57 deletions app/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,10 @@
from quart_cors import cors

from approaches.approach import Approach, DataPoints
from approaches.chatreadretrieveread import ChatReadRetrieveReadApproach
from approaches.promptmanager import PromptyManager
from approaches.retrievethenread import RetrieveThenReadApproach
from chat_history.cosmosdb import chat_history_cosmosdb_bp
from config import (
CONFIG_AGENTIC_KNOWLEDGEBASE_ENABLED,
CONFIG_ASK_APPROACH,
CONFIG_AUTH_CLIENT,
CONFIG_CHAT_APPROACH,
CONFIG_CHAT_HISTORY_BROWSER_ENABLED,
Expand Down Expand Up @@ -182,24 +179,6 @@ async def content_file(path: str, auth_claims: dict[str, Any]):
return await send_file(blob_file, mimetype=mime_type, as_attachment=False, attachment_filename=path)


@bp.route("/ask", methods=["POST"])
@authenticated
async def ask(auth_claims: dict[str, Any]):
if not request.is_json:
return jsonify({"error": "request must be json"}), 415
request_json = await request.get_json()
context = request_json.get("context", {})
context["auth_claims"] = auth_claims
try:
approach: Approach = cast(Approach, current_app.config[CONFIG_ASK_APPROACH])
r = await approach.run(
request_json["messages"], context=context, session_state=request_json.get("session_state")
)
return jsonify(r)
except Exception as error:
return error_response(error, "/ask")


class JSONEncoder(json.JSONEncoder):
def default(self, o):
if dataclasses.is_dataclass(o) and not isinstance(o, type):
Expand Down Expand Up @@ -722,42 +701,8 @@ async def setup_clients():

prompt_manager = PromptyManager()

# Set up the two default RAG approaches for /ask and /chat
# RetrieveThenReadApproach is used by /ask for single-turn Q&A

current_app.config[CONFIG_ASK_APPROACH] = RetrieveThenReadApproach(
search_client=search_client,
search_index_name=AZURE_SEARCH_INDEX,
knowledgebase_model=AZURE_OPENAI_KNOWLEDGEBASE_MODEL,
knowledgebase_deployment=AZURE_OPENAI_KNOWLEDGEBASE_DEPLOYMENT,
knowledgebase_client=knowledgebase_client,
knowledgebase_client_with_web=knowledgebase_client_with_web,
knowledgebase_client_with_sharepoint=knowledgebase_client_with_sharepoint,
knowledgebase_client_with_web_and_sharepoint=knowledgebase_client_with_web_and_sharepoint,
openai_client=openai_client,
chatgpt_model=OPENAI_CHATGPT_MODEL,
chatgpt_deployment=AZURE_OPENAI_CHATGPT_DEPLOYMENT,
embedding_model=OPENAI_EMB_MODEL,
embedding_deployment=AZURE_OPENAI_EMB_DEPLOYMENT,
embedding_dimensions=OPENAI_EMB_DIMENSIONS,
embedding_field=AZURE_SEARCH_FIELD_NAME_EMBEDDING,
sourcepage_field=KB_FIELDS_SOURCEPAGE,
content_field=KB_FIELDS_CONTENT,
query_language=AZURE_SEARCH_QUERY_LANGUAGE,
query_speller=AZURE_SEARCH_QUERY_SPELLER,
prompt_manager=prompt_manager,
reasoning_effort=OPENAI_REASONING_EFFORT,
multimodal_enabled=USE_MULTIMODAL,
image_embeddings_client=image_embeddings_client,
global_blob_manager=global_blob_manager,
user_blob_manager=user_blob_manager,
use_web_source=current_app.config[CONFIG_WEB_SOURCE_ENABLED],
use_sharepoint_source=current_app.config[CONFIG_SHAREPOINT_SOURCE_ENABLED],
retrieval_reasoning_effort=AGENTIC_KNOWLEDGEBASE_REASONING_EFFORT,
)

# ChatReadRetrieveReadApproach is used by /chat for multi-turn conversation
current_app.config[CONFIG_CHAT_APPROACH] = ChatReadRetrieveReadApproach(
# Approach is used by /chat for multi-turn conversation
current_app.config[CONFIG_CHAT_APPROACH] = Approach(
search_client=search_client,
search_index_name=AZURE_SEARCH_INDEX,
knowledgebase_model=AZURE_OPENAI_KNOWLEDGEBASE_MODEL,
Expand Down
Loading