Spaces:
Sleeping
Sleeping
File size: 4,906 Bytes
1a25b7f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | import axios from "axios";
export const config = {
API_BASE_URL: typeof window !== "undefined"
? (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1"
? `${window.location.protocol}//${window.location.hostname}:8001`
: window.location.origin)
: "http://localhost:8001",
};
const client = axios.create({
baseURL: typeof window !== "undefined"
? (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1"
? `${window.location.protocol}//${window.location.hostname}:8001/api`
: "/api")
: `${config.API_BASE_URL}/api`,
timeout: 3600000, // Increased timeout for slow local LLMs and evaluation requests
});
export default {
// Project Management
async getProjects() {
const response = await client.get("/projects");
return response.data;
},
async getProject(id: string) {
const response = await client.get(`/projects/${id}`);
return response.data;
},
async deleteProject(id: string) {
const response = await client.delete(`/projects/${id}`);
return response.data;
},
// Generation
async startGeneration(data: any) {
const response = await client.post("/generate", data);
return response.data;
},
async stopGeneration(sessionId: string, deleteDir: boolean = false) {
const response = await client.post(
`/generate/stop/${sessionId}?delete_dir=${deleteDir}`,
);
return response.data;
},
async retryScene(projectId: string, sceneNumber: number, data: any) {
const response = await client.post(
`/projects/${projectId}/retry-scene/${sceneNumber}`,
data,
);
return response.data;
},
async continueGeneration(projectId: string, data: any) {
const response = await client.post(`/projects/${projectId}/continue`, data);
return response.data;
},
// File Management
async getProjectFile(projectId: string, filePath: string) {
const response = await client.get(
`/projects/${projectId}/files/${filePath}`,
);
return response.data;
},
// Evaluation
async evaluateProject(projectId: string, evaluationConfig: any) {
const response = await client.post(`/projects/${projectId}/evaluate`, {
project_id: projectId,
...evaluationConfig,
});
return response.data;
},
// System
async getModels() {
const response = await client.get("/models");
return response.data;
},
async getSystemStatus() {
const response = await client.get("/system/status");
return response.data;
},
async validateApiKeys(data: {
openai_api_key?: string;
anthropic_api_key?: string;
gemini_api_key?: string;
}) {
const response = await client.post("/validate-keys", data);
return response.data;
},
async getActiveSessions() {
const response = await client.get("/sessions/active");
return response.data;
},
async getVoices() {
const response = await client.get("/voices");
return response.data;
},
async previewVoice(voiceId: string): Promise<string> {
const response = await client.post(
"/voices/preview",
{ voice_id: voiceId },
{ responseType: "blob" },
);
return URL.createObjectURL(response.data);
},
async draftPlan(data: any) {
// Axios doesn't handle streams as easily as fetch for simple text/plain streams
const response = await fetch(`${config.API_BASE_URL}/api/assist/plan`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response;
},
async testApiKey(data: any) {
const response = await client.post("/assist/test-key", data);
return response.data;
},
// Interactive Learning
async chat(projectId: string, data: any) {
const response = await client.post(`/assist/chat`, {
project_id: projectId,
...data,
});
return response.data;
},
async chatSuggestions(projectId: string, data: any) {
const response = await client.post(
`/projects/${projectId}/chat/suggestions`,
data,
);
return response.data;
},
async generateQuiz(payload: any, axiosConfig: any) {
const response = await client.post("/assist/quiz", payload, axiosConfig);
return response.data;
},
// Plan Approval Workflow
async generatePlan(data: any) {
const response = await client.post("/generate/plan", data);
return response.data;
},
async revisePlan(
projectId: string,
data: any,
) {
const response = await client.post(`/projects/${projectId}/revise-plan`, data);
return response.data;
},
async approvePlan(projectId: string, data: any = {}) {
const response = await client.post(`/projects/${projectId}/approve`, data);
return response.data;
},
};
|