Skip to content

Commit 211ac85

Browse files
authored
Properly not require login locally and fix tracing (#134)
1 parent 336f88b commit 211ac85

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/api/routes.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@
5656

5757
security = HTTPBasic()
5858

59+
RUNNING_PROD = os.getenv("RUNNING_IN_PRODUCTION", "false").lower() == "true"
5960

60-
def authenticate(credentials: Optional[HTTPBasicCredentials] = Depends(security) if os.getenv("RUNNING_IN_PRODUCTION") else None) -> None:
61+
def authenticate(credentials: Optional[HTTPBasicCredentials] = Depends(security)) -> None:
6162
# Only perform authentication if RUNNING_IN_PRODUCTION is set to "true" (case-insensitive)
6263
if not os.getenv("RUNNING_IN_PRODUCTION"):
6364
# Not in production mode (or RUNNING_IN_PRODUCTION is not "true"),
@@ -86,6 +87,8 @@ def authenticate(credentials: Optional[HTTPBasicCredentials] = Depends(security)
8687
)
8788
return
8889

90+
auth_dependency = Depends(authenticate) if RUNNING_PROD else None
91+
8992

9093
def get_ai_project(request: Request) -> AIProjectClient:
9194
return request.app.state.ai_project
@@ -190,7 +193,7 @@ async def on_run_step(self, step: RunStep) -> Optional[str]:
190193
return None
191194

192195
@router.get("/", response_class=HTMLResponse)
193-
async def index(request: Request, _ = Depends(authenticate)):
196+
async def index(request: Request, _ = auth_dependency):
194197
return templates.TemplateResponse(
195198
"index.html",
196199
{
@@ -236,7 +239,7 @@ async def history(
236239
request: Request,
237240
ai_project : AIProjectClient = Depends(get_ai_project),
238241
agent : Agent = Depends(get_agent),
239-
_ = Depends(authenticate)
242+
_ = auth_dependency
240243
):
241244
with tracer.start_as_current_span("chat_history"):
242245
# Retrieve the thread ID from the cookies (if available).
@@ -295,7 +298,7 @@ async def chat(
295298
agent : Agent = Depends(get_agent),
296299
ai_project: AIProjectClient = Depends(get_ai_project),
297300
app_insights_conn_str : str = Depends(get_app_insights_conn_str),
298-
_ = Depends(authenticate)
301+
_ = auth_dependency
299302
):
300303
# Retrieve the thread ID from the cookies (if available).
301304
thread_id = request.cookies.get('thread_id')

src/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ aiohttp==3.11.1
77
azure_ai_agents==1.0.0
88
azure_ai_projects==1.0.0b11
99

10-
azure-core==1.31.0 # other versions might not compatible
10+
azure-core==1.34.0 # other versions might not compatible
1111
azure-core-tracing-opentelemetry
1212
azure-monitor-opentelemetry>=1.6.9
1313
azure-search-documents

0 commit comments

Comments
 (0)