Skip to content

Commit cfa570d

Browse files
committed
Update async credentials, rm GitHub Models
1 parent eea45c3 commit cfa570d

8 files changed

Lines changed: 31 additions & 29 deletions

File tree

.github/copilot-instructions.md

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ RAG on PostgreSQL is a Python FastAPI backend with React TypeScript frontend tha
1111
Install the following tools before beginning development:
1212

1313
- **Python 3.10+** (3.12 recommended)
14-
- **Node.js 18+** for frontend development
14+
- **Node.js 18+** for frontend development
1515
- **PostgreSQL 14+** with pgvector extension
1616
- **Azure Developer CLI (azd)** for deployment
1717
- **Docker Desktop** for dev containers (optional)
@@ -37,7 +37,7 @@ Run these commands in sequence. NEVER CANCEL any long-running commands:
3737
```bash
3838
# Ubuntu/Debian:
3939
sudo apt update && sudo apt install -y postgresql-16-pgvector
40-
40+
4141
# Start PostgreSQL and set password
4242
sudo service postgresql start
4343
sudo -u postgres psql -c "ALTER USER postgres PASSWORD 'postgres'"
@@ -97,7 +97,7 @@ Use "Frontend & Backend" configuration in the VS Code Run & Debug menu.
9797
### Linting and Formatting (ALWAYS run before committing)
9898
```bash
9999
ruff check . # Lint code (takes <1 second)
100-
ruff format . # Format code (takes <1 second)
100+
ruff format . # Format code (takes <1 second)
101101
mypy . --python-version 3.12 # Type check (takes ~42 seconds)
102102
```
103103

@@ -121,7 +121,7 @@ pytest tests/e2e.py --tracing=retain-on-failure
121121
**CRITICAL TIMING INFORMATION** - Set these timeout values and NEVER CANCEL:
122122

123123
- **Dependencies install**: 90 seconds (use 180+ second timeout)
124-
- **Frontend npm install**: 22 seconds (use 60+ second timeout)
124+
- **Frontend npm install**: 22 seconds (use 60+ second timeout)
125125
- **Frontend build**: 12 seconds (use 30+ second timeout)
126126
- **MyPy type checking**: 42 seconds (use 90+ second timeout)
127127
- **Full test suite**: 25 seconds (use 60+ second timeout)
@@ -156,7 +156,7 @@ pytest tests/e2e.py --tracing=retain-on-failure
156156
# Test API endpoints
157157
curl http://localhost:8000/items/1
158158
# Should return JSON with item data
159-
159+
160160
# Test frontend
161161
curl http://localhost:8000/ | head -n 5
162162
# Should return HTML with "RAG on PostgreSQL" title
@@ -226,9 +226,6 @@ The application supports multiple OpenAI providers:
226226
3. **Ollama** (local):
227227
Set `OPENAI_CHAT_HOST=ollama`
228228

229-
4. **GitHub Models**:
230-
Set `OPENAI_CHAT_HOST=github`
231-
232229
## Common Issues and Solutions
233230

234231
### Database Connection Issues
@@ -267,7 +264,7 @@ Open `http://localhost:8089/` and point to your running application.
267264
The application provides these REST API endpoints (view full docs at `http://localhost:8000/docs`):
268265

269266
- `GET /items/{id}` - Get specific item by ID
270-
- `GET /search` - Search items with text query
267+
- `GET /search` - Search items with text query
271268
- `GET /similar` - Find similar items using vector search
272269
- `POST /chat` - Chat with RAG system (requires OpenAI configuration)
273270
- `POST /chat/stream` - Streaming chat responses
@@ -286,7 +283,7 @@ curl "http://localhost:8000/search?query=tent&limit=5"
286283
**Quick ls -la output for repository root:**
287284
```
288285
.devcontainer/ # Dev container configuration
289-
.env.sample # Environment variables template
286+
.env.sample # Environment variables template
290287
.github/ # GitHub Actions workflows
291288
.gitignore # Git ignore patterns
292289
.pre-commit-config.yaml # Pre-commit hook configuration
@@ -309,8 +306,8 @@ tests/ # Test suite
309306
- **Always build and test locally before committing**
310307
- **Use pre-commit hooks** - they run ruff automatically
311308
- **Check the GitHub Actions** in `.github/workflows/` for CI requirements
312-
- **Reference the full README.md** for deployment and Azure-specific details
309+
- **Reference the full README.md** for deployment and Azure-specific details
313310
- **Use VS Code with the Python and Ruff extensions** for the best development experience
314311
- **Never skip the frontend build** - the backend serves static files from `src/backend/static/`
315312

316-
This project follows modern Python and TypeScript development practices with comprehensive tooling for code quality, testing, and deployment.
313+
This project follows modern Python and TypeScript development practices with comprehensive tooling for code quality, testing, and deployment.

evals/eval_config.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
"use_advanced_flow": true,
99
"top": 3,
1010
"retrieval_mode": "hybrid",
11-
"temperature": 0.3,
12-
"seed": 42
11+
"temperature": 0.3
1312
}
1413
},
1514
"target_response_answer_jmespath": "message.content",

evals/evaluate.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ def get_openai_config() -> dict:
6868
openai_config["model"] = os.environ["AZURE_OPENAI_EVAL_MODEL"]
6969
elif os.environ.get("OPENAI_CHAT_HOST") == "ollama":
7070
raise NotImplementedError("Ollama is not supported. Switch to Azure or OpenAI.com")
71-
elif os.environ.get("OPENAI_CHAT_HOST") == "github":
72-
raise NotImplementedError("GitHub Models is not supported. Switch to Azure or OpenAI.com")
7371
else:
7472
logger.info("Using OpenAI Service with API Key from OPENAICOM_KEY")
7573
openai_config = {"api_key": os.environ["OPENAICOM_KEY"], "model": "gpt-4"}

evals/generate_ground_truth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def generate_ground_truth_data(num_questions_total: int, num_questions_per_sourc
121121
{"role": "system", "content": generate_prompt},
122122
{"role": "user", "content": json.dumps(source)},
123123
],
124-
tools=[qa_pairs_tool(num_questions=2)],
124+
tools=[qa_pairs_tool(num_questions=2)], # type: ignore[list-item]
125125
max_output_tokens=1000,
126126
store=False,
127127
)

src/backend/fastapi_app/dependencies.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from collections.abc import AsyncGenerator
44
from typing import Annotated, Optional
55

6-
import azure.identity
6+
import azure.identity.aio
77
from fastapi import Depends, Request
88
from openai import AsyncOpenAI
99
from pydantic import BaseModel
@@ -77,9 +77,9 @@ async def common_parameters():
7777

7878

7979
async def get_azure_credential() -> (
80-
azure.identity.AzureDeveloperCliCredential | azure.identity.ManagedIdentityCredential
80+
azure.identity.aio.AzureDeveloperCliCredential | azure.identity.aio.ManagedIdentityCredential
8181
):
82-
azure_credential: azure.identity.AzureDeveloperCliCredential | azure.identity.ManagedIdentityCredential
82+
azure_credential: azure.identity.aio.AzureDeveloperCliCredential | azure.identity.aio.ManagedIdentityCredential
8383
try:
8484
if client_id := os.getenv("APP_IDENTITY_ID"):
8585
# Authenticate using a user-assigned managed identity on Azure
@@ -88,14 +88,14 @@ async def get_azure_credential() -> (
8888
"Using managed identity for client ID %s",
8989
client_id,
9090
)
91-
azure_credential = azure.identity.ManagedIdentityCredential(client_id=client_id)
91+
azure_credential = azure.identity.aio.ManagedIdentityCredential(client_id=client_id)
9292
else:
9393
if tenant_id := os.getenv("AZURE_TENANT_ID"):
9494
logger.info("Authenticating to Azure using Azure Developer CLI Credential for tenant %s", tenant_id)
95-
azure_credential = azure.identity.AzureDeveloperCliCredential(tenant_id=tenant_id, process_timeout=60)
95+
azure_credential = azure.identity.aio.AzureDeveloperCliCredential(tenant_id=tenant_id)
9696
else:
9797
logger.info("Authenticating to Azure using Azure Developer CLI Credential")
98-
azure_credential = azure.identity.AzureDeveloperCliCredential(process_timeout=60)
98+
azure_credential = azure.identity.aio.AzureDeveloperCliCredential()
9999
return azure_credential
100100
except Exception as e:
101101
logger.warning("Failed to authenticate to Azure: %s", e)

src/backend/fastapi_app/openai_clients.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import logging
22
import os
33

4-
import azure.identity
54
import azure.identity.aio
65
import openai
76

87
logger = logging.getLogger("ragapp")
98

109

1110
async def create_openai_chat_client(
12-
azure_credential: azure.identity.AzureDeveloperCliCredential | azure.identity.ManagedIdentityCredential | None,
11+
azure_credential: azure.identity.aio.AzureDeveloperCliCredential
12+
| azure.identity.aio.ManagedIdentityCredential
13+
| None,
1314
) -> openai.AsyncOpenAI:
1415
openai_chat_client: openai.AsyncOpenAI
1516
OPENAI_CHAT_HOST = os.getenv("OPENAI_CHAT_HOST")
@@ -55,7 +56,9 @@ async def create_openai_chat_client(
5556

5657

5758
async def create_openai_embed_client(
58-
azure_credential: azure.identity.AzureDeveloperCliCredential | azure.identity.ManagedIdentityCredential | None,
59+
azure_credential: azure.identity.aio.AzureDeveloperCliCredential
60+
| azure.identity.aio.ManagedIdentityCredential
61+
| None,
5962
) -> openai.AsyncOpenAI:
6063
openai_embed_client: openai.AsyncOpenAI
6164
OPENAI_EMBED_HOST = os.getenv("OPENAI_EMBED_HOST")

src/backend/fastapi_app/update_embeddings.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ async def update_embeddings(in_seed_data=False):
2929
embedding_column = os.getenv("AZURE_OPENAI_EMBEDDING_COLUMN", "embedding_3l")
3030
elif OPENAI_EMBED_HOST == "ollama":
3131
embedding_column = os.getenv("OLLAMA_EMBEDDING_COLUMN", "embedding_nomic")
32-
elif OPENAI_EMBED_HOST == "github":
33-
embedding_column = os.getenv("GITHUB_EMBEDDING_COLUMN", "embedding_3l")
3432
else:
3533
embedding_column = os.getenv("OPENAICOM_EMBEDDING_COLUMN", "embedding_3l")
3634
logger.info(f"Updating embeddings in column: {embedding_column}")

tests/conftest.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import openai
77
import openai.resources
8+
import openai.resources.responses
89
import pytest
910
import pytest_asyncio
1011
from fastapi.testclient import TestClient
@@ -184,6 +185,8 @@ def __init__(self, answer: str):
184185
delta=parts[0] + "<<",
185186
item_id="msg-1",
186187
output_index=0,
188+
logprobs=[],
189+
sequence_number=0,
187190
)
188191
)
189192
self.events.append(
@@ -193,6 +196,8 @@ def __init__(self, answer: str):
193196
delta=parts[1],
194197
item_id="msg-1",
195198
output_index=0,
199+
logprobs=[],
200+
sequence_number=1,
196201
)
197202
)
198203
else:
@@ -203,6 +208,8 @@ def __init__(self, answer: str):
203208
delta=answer,
204209
item_id="msg-1",
205210
output_index=0,
211+
logprobs=[],
212+
sequence_number=0,
206213
)
207214
)
208215

@@ -305,7 +312,7 @@ async def mock_acreate(*args, **kwargs):
305312
@pytest.fixture(scope="function")
306313
def mock_azure_credential(mock_session_env):
307314
"""Mock the Azure credential for testing."""
308-
with mock.patch("azure.identity.AzureDeveloperCliCredential") as mock_azure_credential:
315+
with mock.patch("azure.identity.aio.AzureDeveloperCliCredential") as mock_azure_credential:
309316
mock_azure_credential.return_value = MockAzureCredential()
310317
yield mock_azure_credential
311318

0 commit comments

Comments
 (0)