separa rutas api
This commit is contained in:
parent
2f74e893bf
commit
f7b23a3cec
2 changed files with 9 additions and 9 deletions
10
app.py
10
app.py
|
|
@ -23,11 +23,11 @@ async def serve_frontend(request):
|
||||||
|
|
||||||
routes = [
|
routes = [
|
||||||
Route("/", serve_frontend, methods=["GET"]),
|
Route("/", serve_frontend, methods=["GET"]),
|
||||||
Route("/models", get_models, methods=["GET"]),
|
Route("/api/models", get_models, methods=["GET"]),
|
||||||
Route("/chats", create_chat, methods=["POST"]),
|
Route("/api/chats", create_chat, methods=["POST"]),
|
||||||
Route("/chats/{chat_id:str}", history, methods=["GET"]),
|
Route("/api/chats/{chat_id:str}", history, methods=["GET"]),
|
||||||
Route("/chats/{chat_id:str}/messages", post_message, methods=["POST"]),
|
Route("/api/chats/{chat_id:str}/messages", post_message, methods=["POST"]),
|
||||||
Route("/chats/{chat_id:str}/stream", chat_stream, methods=["GET"]),
|
Route("/api/chats/{chat_id:str}/stream", chat_stream, methods=["GET"]),
|
||||||
Mount("/assets", StaticFiles(directory=os.path.join("frontend", "dist", "assets")), name="assets"),
|
Mount("/assets", StaticFiles(directory=os.path.join("frontend", "dist", "assets")), name="assets"),
|
||||||
Mount("/icon", StaticFiles(directory=os.path.join("frontend", "dist", "icon")), name="icon"),
|
Mount("/icon", StaticFiles(directory=os.path.join("frontend", "dist", "icon")), name="icon"),
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
const API = import.meta.env.CHATSBT_API_URL || "";
|
const API = import.meta.env.CHATSBT_API_URL || "";
|
||||||
|
|
||||||
export async function createChat(model = "qwen/qwen3-235b-a22b-2507") {
|
export async function createChat(model = "qwen/qwen3-235b-a22b-2507") {
|
||||||
const r = await fetch(`${API}/chats`, {
|
const r = await fetch(`${API}/api/chats`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({ model }),
|
body: JSON.stringify({ model }),
|
||||||
});
|
});
|
||||||
|
|
@ -9,7 +9,7 @@ export async function createChat(model = "qwen/qwen3-235b-a22b-2507") {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sendUserMessage(chatId, text, model = "") {
|
export async function sendUserMessage(chatId, text, model = "") {
|
||||||
const r = await fetch(`${API}/chats/${chatId}/messages`, {
|
const r = await fetch(`${API}/api/chats/${chatId}/messages`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { "Content-Type": "application/json" },
|
headers: { "Content-Type": "application/json" },
|
||||||
body: JSON.stringify({ message: text, model }),
|
body: JSON.stringify({ message: text, model }),
|
||||||
|
|
@ -19,13 +19,13 @@ export async function sendUserMessage(chatId, text, model = "") {
|
||||||
|
|
||||||
export function openStream(chatId, messageId) {
|
export function openStream(chatId, messageId) {
|
||||||
return new EventSource(
|
return new EventSource(
|
||||||
`${API}/chats/${chatId}/stream?message_id=${messageId}`,
|
`${API}/api/chats/${chatId}/stream?message_id=${messageId}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchModels() {
|
export async function fetchModels() {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API}/models`);
|
const response = await fetch(`${API}/api/models`);
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
return data.models || [];
|
return data.models || [];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue