devops
This commit is contained in:
29
devops-view/src/services/api.ts
Normal file
29
devops-view/src/services/api.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import type { Chat, CreateEntryResponse } from "../types";
|
||||
|
||||
const BASE = "/api/rag";
|
||||
|
||||
export async function createChat(token: string): Promise<Chat> {
|
||||
const res = await fetch(`${BASE}/chat/new?title=DevOps%20Chat`, {
|
||||
method: "POST",
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
if (!res.ok) throw new Error(`Failed to create chat: ${res.status}`);
|
||||
return res.json() as Promise<Chat>;
|
||||
}
|
||||
|
||||
export async function sendMessage(
|
||||
token: string,
|
||||
chatId: number,
|
||||
content: string
|
||||
): Promise<CreateEntryResponse> {
|
||||
const res = await fetch(`${BASE}/entry/${chatId}`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ content, onlyContext: true }),
|
||||
});
|
||||
if (!res.ok) throw new Error(`Failed to send message: ${res.status}`);
|
||||
return res.json() as Promise<CreateEntryResponse>;
|
||||
}
|
||||
Reference in New Issue
Block a user