* feat: use vercel ai gateway * fix: correct response handling * ci: add pipeline
34 lines
991 B
TypeScript
34 lines
991 B
TypeScript
import 'dotenv/config';
|
|
import { Consumer, consumerSchema } from './types';
|
|
import { Tool } from './tool';
|
|
import { BaseTool, makeRequest } from '@utils/aiGatewayClient';
|
|
import { generatePrompt } from './prompt';
|
|
import { generateConsumerSeed } from '@utils/generateConsumerSeed';
|
|
|
|
export async function generate() {
|
|
const { letters, birthday, zipCode } = generateConsumerSeed();
|
|
|
|
console.info(`New consumer being generated`);
|
|
|
|
const prompt = generatePrompt(letters, birthday, zipCode);
|
|
|
|
try {
|
|
const result = (await makeRequest(prompt, Tool as BaseTool)) as Consumer;
|
|
|
|
const validConsumer = consumerSchema.safeParse(result);
|
|
|
|
if (validConsumer.error) {
|
|
throw Error(`Invalid consumer generated: ${validConsumer.error.message}`);
|
|
}
|
|
|
|
console.info('Generated consumer by Anthropic', validConsumer.data);
|
|
|
|
return {
|
|
consumer: validConsumer.data
|
|
};
|
|
} catch (error) {
|
|
console.error('Error generating purchases:', error);
|
|
throw error;
|
|
}
|
|
}
|