-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxyService.ts
More file actions
72 lines (64 loc) · 1.76 KB
/
proxyService.ts
File metadata and controls
72 lines (64 loc) · 1.76 KB
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
/**
* Proxy Service for FixTrax
* Routes Gemini API calls through secure proxy server
* Adapted from Storyteller proxy pattern
*/
const PROXY_URL = import.meta.env.VITE_PROXY_URL || 'https://gemini-proxy-572556903588.us-central1.run.app';
interface GenerateContentRequest {
model: string;
contents: string;
config?: {
systemInstruction?: string;
responseMimeType?: string;
responseSchema?: any;
};
}
interface GenerateContentResponse {
text: string;
}
/**
* Generate content using the proxy server
* This replaces direct GoogleGenAI calls
*/
export const generateContent = async (
request: GenerateContentRequest
): Promise<GenerateContentResponse> => {
try {
const response = await fetch(`${PROXY_URL}/v1/generate`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: request.model,
prompt: request.contents,
systemInstruction: request.config?.systemInstruction,
responseMimeType: request.config?.responseMimeType,
responseSchema: request.config?.responseSchema,
}),
});
if (!response.ok) {
const errorText = await response.text();
throw new Error(`Proxy request failed: ${response.status} - ${errorText}`);
}
const data = await response.json();
return {
text: data.text || data.content || '',
};
} catch (error) {
console.error('Proxy service error:', error);
throw error;
}
};
/**
* Health check for proxy server
*/
export const checkProxyHealth = async (): Promise<boolean> => {
try {
const response = await fetch(`${PROXY_URL}/health`);
return response.ok;
} catch (error) {
console.error('Proxy health check failed:', error);
return false;
}
};