Fix: add type hints for all API endpoint parameters (gr.OAuthProfile | None)
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@ from pathlib import Path
|
|
| 7 |
from fastapi import FastAPI
|
| 8 |
from fastapi.responses import HTMLResponse
|
| 9 |
from fastapi.staticfiles import StaticFiles
|
| 10 |
-
|
| 11 |
from openai import OpenAI
|
| 12 |
|
| 13 |
# Default system prompt for DeepSeek V4 Flash
|
|
@@ -22,7 +22,7 @@ def get_user_sessions(username):
|
|
| 22 |
return USER_DATA[username]
|
| 23 |
|
| 24 |
# ββ Initialize Gradio Server (FastAPI subclass) βββββββββββββββββββββββββ
|
| 25 |
-
app = Server()
|
| 26 |
|
| 27 |
# Create static directory if it doesn't exist
|
| 28 |
STATIC_DIR = Path(__file__).parent / "static"
|
|
@@ -95,7 +95,7 @@ def chat_with_deepseek(
|
|
| 95 |
|
| 96 |
# ββ API Endpoint: Get User Info (OAuth) ββββββββββββββββββββββββββββββββ
|
| 97 |
@app.api(name="get_user_info")
|
| 98 |
-
def get_user_info(profile) -> str:
|
| 99 |
"""Return the logged-in user's name, or empty string if not logged in."""
|
| 100 |
# The Gradio Server passes the OAuth profile automatically
|
| 101 |
if profile is None:
|
|
@@ -109,7 +109,7 @@ def save_chat_session(
|
|
| 109 |
messages_json: str,
|
| 110 |
title: str,
|
| 111 |
session_id: str,
|
| 112 |
-
profile = None,
|
| 113 |
) -> str:
|
| 114 |
if profile is None:
|
| 115 |
return json.dumps({"status": "error", "message": "Not logged in"})
|
|
@@ -146,7 +146,7 @@ def save_chat_session(
|
|
| 146 |
@app.api(name="load_chat_session")
|
| 147 |
def load_chat_session(
|
| 148 |
session_id: str,
|
| 149 |
-
profile = None,
|
| 150 |
) -> str:
|
| 151 |
if profile is None:
|
| 152 |
return json.dumps({"status": "error", "message": "Not logged in"})
|
|
@@ -170,7 +170,7 @@ def load_chat_session(
|
|
| 170 |
|
| 171 |
# ββ API Endpoint: List Chat Sessions βββββββββββββββββββββββββββββββββββ
|
| 172 |
@app.api(name="list_chat_sessions")
|
| 173 |
-
def list_chat_sessions(profile = None) -> str:
|
| 174 |
if profile is None:
|
| 175 |
return json.dumps({"status": "error", "message": "Not logged in", "sessions": []})
|
| 176 |
|
|
@@ -197,7 +197,7 @@ def list_chat_sessions(profile = None) -> str:
|
|
| 197 |
@app.api(name="delete_chat_session")
|
| 198 |
def delete_chat_session(
|
| 199 |
session_id: str,
|
| 200 |
-
profile = None,
|
| 201 |
) -> str:
|
| 202 |
if profile is None:
|
| 203 |
return json.dumps({"status": "error", "message": "Not logged in"})
|
|
|
|
| 7 |
from fastapi import FastAPI
|
| 8 |
from fastapi.responses import HTMLResponse
|
| 9 |
from fastapi.staticfiles import StaticFiles
|
| 10 |
+
import gradio as gr
|
| 11 |
from openai import OpenAI
|
| 12 |
|
| 13 |
# Default system prompt for DeepSeek V4 Flash
|
|
|
|
| 22 |
return USER_DATA[username]
|
| 23 |
|
| 24 |
# ββ Initialize Gradio Server (FastAPI subclass) βββββββββββββββββββββββββ
|
| 25 |
+
app = gr.Server()
|
| 26 |
|
| 27 |
# Create static directory if it doesn't exist
|
| 28 |
STATIC_DIR = Path(__file__).parent / "static"
|
|
|
|
| 95 |
|
| 96 |
# ββ API Endpoint: Get User Info (OAuth) ββββββββββββββββββββββββββββββββ
|
| 97 |
@app.api(name="get_user_info")
|
| 98 |
+
def get_user_info(profile: gr.OAuthProfile | None = None) -> str:
|
| 99 |
"""Return the logged-in user's name, or empty string if not logged in."""
|
| 100 |
# The Gradio Server passes the OAuth profile automatically
|
| 101 |
if profile is None:
|
|
|
|
| 109 |
messages_json: str,
|
| 110 |
title: str,
|
| 111 |
session_id: str,
|
| 112 |
+
profile: gr.OAuthProfile | None = None,
|
| 113 |
) -> str:
|
| 114 |
if profile is None:
|
| 115 |
return json.dumps({"status": "error", "message": "Not logged in"})
|
|
|
|
| 146 |
@app.api(name="load_chat_session")
|
| 147 |
def load_chat_session(
|
| 148 |
session_id: str,
|
| 149 |
+
profile: gr.OAuthProfile | None = None,
|
| 150 |
) -> str:
|
| 151 |
if profile is None:
|
| 152 |
return json.dumps({"status": "error", "message": "Not logged in"})
|
|
|
|
| 170 |
|
| 171 |
# ββ API Endpoint: List Chat Sessions βββββββββββββββββββββββββββββββββββ
|
| 172 |
@app.api(name="list_chat_sessions")
|
| 173 |
+
def list_chat_sessions(profile: gr.OAuthProfile | None = None) -> str:
|
| 174 |
if profile is None:
|
| 175 |
return json.dumps({"status": "error", "message": "Not logged in", "sessions": []})
|
| 176 |
|
|
|
|
| 197 |
@app.api(name="delete_chat_session")
|
| 198 |
def delete_chat_session(
|
| 199 |
session_id: str,
|
| 200 |
+
profile: gr.OAuthProfile | None = None,
|
| 201 |
) -> str:
|
| 202 |
if profile is None:
|
| 203 |
return json.dumps({"status": "error", "message": "Not logged in"})
|