Skip to content
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
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ See [CONTRIBUTING.md](https://github.com/Azure-Samples/rag-postgres-openai-pytho
- [ ] The current tests all pass (`python -m pytest`).
- [ ] I added tests that prove my fix is effective or that my feature works
- [ ] I ran `python -m pytest --cov` to verify 100% coverage of added lines
- [ ] I ran `python -m mypy` to check for type errors
- [ ] I ran `python -m ty check` to check for type errors
- [ ] I either used the pre-commit hooks or ran `ruff` manually on my code.
12 changes: 5 additions & 7 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,9 @@ Use "Frontend & Backend" configuration in the VS Code Run & Debug menu.
```bash
ruff check . # Lint code (takes <1 second)
ruff format . # Format code (takes <1 second)
mypy . --python-version 3.12 # Type check (takes ~42 seconds)
ty check . --python-version 3.12 # Type check
```

**NOTE**: MyPy may show 1 minor import error in `evals/safety_evaluation.py` which is expected and safe to ignore.

### Testing (NEVER CANCEL - full test suite takes ~25 seconds)
```bash
pytest -s -vv --cov --cov-fail-under=85
Expand All @@ -123,7 +121,7 @@ pytest tests/e2e.py --tracing=retain-on-failure
- **Dependencies install**: 90 seconds (use 180+ second timeout)
- **Frontend npm install**: 22 seconds (use 60+ second timeout)
- **Frontend build**: 12 seconds (use 30+ second timeout)
- **MyPy type checking**: 42 seconds (use 90+ second timeout)
- **ty type checking**: use 90+ second timeout
- **Full test suite**: 25 seconds (use 60+ second timeout)
- **Playwright E2E tests**: 2+ minutes (use 300+ second timeout)

Expand All @@ -138,7 +136,7 @@ pytest tests/e2e.py --tracing=retain-on-failure

2. **Type check (if Python changes)**:
```bash
mypy . --python-version 3.12
ty check . --python-version 3.12
```

3. **Run relevant tests**:
Expand Down Expand Up @@ -194,7 +192,7 @@ pytest tests/e2e.py --tracing=retain-on-failure
- `main.bicep` - Main infrastructure definition

### Configuration Files
- `pyproject.toml` - Python project config (ruff, mypy, pytest)
- `pyproject.toml` - Python project config (ruff, ty, pytest)
- `requirements-dev.txt` - Development dependencies
- `azure.yaml` - Azure Developer CLI configuration
- `.env.sample` - Environment variable template
Expand Down Expand Up @@ -248,7 +246,7 @@ The GitHub Actions require:
- Python 3.10+ with specific versions (3.10, 3.11, 3.12)
- PostgreSQL with pgvector extension
- Node.js 18+
- All code passes `ruff check`, `ruff format --check`, and `mypy`
- All code passes `ruff check`, `ruff format --check`, and `ty check`

## Load Testing

Expand Down
10 changes: 2 additions & 8 deletions .github/workflows/app-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,8 @@ jobs:
npm install
npm run build

- name: Setup mypy cache
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4.3.0
with:
path: ./.mypy_cache
key: mypy${{ matrix.os }}-${{ matrix.python_version }}-${{ hashFiles('requirements-dev.txt', 'src/backend/requirements.txt', 'src/backend/pyproject.toml') }}

- name: Run MyPy
run: python3 -m mypy . --python-version ${{ matrix.python_version }}
- name: Run ty
run: python3 -m ty check . --python-version ${{ matrix.python_version }} --output-format github

- name: Run Pytest
run: python3 -m pytest -s -vv --cov --cov-fail-under=85
Expand Down
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,6 @@ venv.bak/
# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

Expand Down
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
".pytest_cache": true,
"__pycache__": true,
"htmlcov": true,
".mypy_cache": true,
".coverage": true
},
"python-envs.defaultEnvManager": "ms-python.python:system"
Expand Down
2 changes: 1 addition & 1 deletion evals/generate_ground_truth.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def generate_ground_truth_data(num_questions_total: int, num_questions_per_sourc
{"role": "system", "content": generate_prompt},
{"role": "user", "content": json.dumps(source)},
],
tools=[qa_pairs_tool(num_questions=2)], # type: ignore[list-item]
tools=[qa_pairs_tool(num_questions=2)], # ty: ignore[invalid-argument-type]
max_output_tokens=1000,
store=False,
)
Expand Down
20 changes: 10 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ lint.select = ["E", "F", "I", "UP"]
lint.ignore = ["D203"]
lint.isort.known-first-party = ["fastapi_app"]

[tool.mypy]
check_untyped_defs = true
exclude = [".venv/*"]
[tool.ty.environment]
root = ["./src/backend", "."]

[tool.ty.analysis]
allowed-unresolved-imports = [
"azure.ai.evaluation.**",
"rich.**",
"pgvector.**",
"evaltools.**",
]

[tool.pytest.ini_options]
addopts = "-ra"
testpaths = ["tests"]
pythonpath = ['src/backend']
filterwarnings = ["ignore::DeprecationWarning"]

[[tool.mypy.overrides]]
module = [
"pgvector.*",
"evaltools.*"
]
ignore_missing_imports = true

[tool.coverage.report]
show_missing = true
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-r src/backend/requirements.txt
ruff
mypy
ty
types-requests
pre-commit
pip-tools
Expand Down
3 changes: 2 additions & 1 deletion src/backend/fastapi_app/rag_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
ItemHelpers,
ModelSettings,
OpenAIResponsesModel,
RawResponsesStreamEvent,
Runner,
ToolCallOutputItem,
function_tool,
Expand Down Expand Up @@ -198,6 +199,6 @@ async def answer_stream(
)

async for event in run_results.stream_events():
if event.type == "raw_response_event" and isinstance(event.data, ResponseTextDeltaEvent):
if isinstance(event, RawResponsesStreamEvent) and isinstance(event.data, ResponseTextDeltaEvent):
yield RetrievalResponseDelta(type="response.output_text.delta", delta=str(event.data.delta))
return
12 changes: 10 additions & 2 deletions src/backend/fastapi_app/rag_simple.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
from collections.abc import AsyncGenerator
from typing import Optional

from agents import Agent, ItemHelpers, ModelSettings, OpenAIResponsesModel, Runner, set_tracing_disabled
from agents import (
Agent,
ItemHelpers,
ModelSettings,
OpenAIResponsesModel,
RawResponsesStreamEvent,
Runner,
set_tracing_disabled,
)
from openai import AsyncOpenAI
from openai.types.responses import ResponseInputItemParam, ResponseTextDeltaEvent

Expand Down Expand Up @@ -131,6 +139,6 @@ async def answer_stream(
)

async for event in run_results.stream_events():
if event.type == "raw_response_event" and isinstance(event.data, ResponseTextDeltaEvent):
if isinstance(event, RawResponsesStreamEvent) and isinstance(event.data, ResponseTextDeltaEvent):
yield RetrievalResponseDelta(type="response.output_text.delta", delta=str(event.data.delta))
return
Loading