From f7b23a3cec2fd072958df568ddae3d3b37b8fce0 Mon Sep 17 00:00:00 2001 From: Sebarocks Date: Sat, 2 Aug 2025 00:57:39 -0400 Subject: [PATCH] separa rutas api --- app.py | 10 +++++----- frontend/src/lib/chatApi.svelte.js | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index 236457a..acd36ba 100644 --- a/app.py +++ b/app.py @@ -23,11 +23,11 @@ async def serve_frontend(request): routes = [ Route("/", serve_frontend, methods=["GET"]), - Route("/models", get_models, methods=["GET"]), - Route("/chats", create_chat, methods=["POST"]), - Route("/chats/{chat_id:str}", history, methods=["GET"]), - Route("/chats/{chat_id:str}/messages", post_message, methods=["POST"]), - Route("/chats/{chat_id:str}/stream", chat_stream, methods=["GET"]), + Route("/api/models", get_models, methods=["GET"]), + Route("/api/chats", create_chat, methods=["POST"]), + Route("/api/chats/{chat_id:str}", history, methods=["GET"]), + Route("/api/chats/{chat_id:str}/messages", post_message, methods=["POST"]), + Route("/api/chats/{chat_id:str}/stream", chat_stream, methods=["GET"]), Mount("/assets", StaticFiles(directory=os.path.join("frontend", "dist", "assets")), name="assets"), Mount("/icon", StaticFiles(directory=os.path.join("frontend", "dist", "icon")), name="icon"), ] diff --git a/frontend/src/lib/chatApi.svelte.js b/frontend/src/lib/chatApi.svelte.js index d07688c..0de1084 100644 --- a/frontend/src/lib/chatApi.svelte.js +++ b/frontend/src/lib/chatApi.svelte.js @@ -1,7 +1,7 @@ const API = import.meta.env.CHATSBT_API_URL || ""; 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", 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 = "") { - const r = await fetch(`${API}/chats/${chatId}/messages`, { + const r = await fetch(`${API}/api/chats/${chatId}/messages`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ message: text, model }), @@ -19,13 +19,13 @@ export async function sendUserMessage(chatId, text, model = "") { export function openStream(chatId, messageId) { return new EventSource( - `${API}/chats/${chatId}/stream?message_id=${messageId}`, + `${API}/api/chats/${chatId}/stream?message_id=${messageId}`, ); } export async function fetchModels() { try { - const response = await fetch(`${API}/models`); + const response = await fetch(`${API}/api/models`); const data = await response.json(); return data.models || []; } catch (error) {