forked from innovacion/playground
Initial commit
This commit is contained in:
29
frontend/lib/google-ai-server.ts
Normal file
29
frontend/lib/google-ai-server.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
// Servidor: Configuración de Vertex AI con autenticación
|
||||
// Este archivo SOLO debe importarse en API routes (server-side)
|
||||
|
||||
import { VertexAI } from '@google-cloud/vertexai';
|
||||
|
||||
// Leer credenciales desde variables de entorno
|
||||
export const projectId = process.env.GOOGLE_PROJECT_ID!;
|
||||
export const location = process.env.GOOGLE_LOCATION || 'us-central1';
|
||||
|
||||
// Construir objeto de credenciales desde variables de entorno
|
||||
export const credentials = {
|
||||
type: 'service_account',
|
||||
project_id: process.env.GOOGLE_PROJECT_ID,
|
||||
client_email: process.env.GOOGLE_CLIENT_EMAIL,
|
||||
private_key: process.env.GOOGLE_PRIVATE_KEY?.replace(/\\n/g, '\n'),
|
||||
};
|
||||
|
||||
console.log(`Configurando Vertex AI - Proyecto: ${projectId}, Location: ${location}`);
|
||||
|
||||
// Crear instancia de Vertex AI
|
||||
export const vertexAI = new VertexAI({
|
||||
project: projectId,
|
||||
location: location,
|
||||
googleAuthOptions: {
|
||||
credentials: credentials,
|
||||
},
|
||||
});
|
||||
|
||||
console.log('Cliente de Vertex AI creado correctamente');
|
||||
Reference in New Issue
Block a user