fix: tweak llama usage
All checks were successful
Deploy / lint-build-deploy (push) Successful in 2m28s
All checks were successful
Deploy / lint-build-deploy (push) Successful in 2m28s
This commit is contained in:
@@ -30,14 +30,25 @@ export interface ToolUseBlock {
|
|||||||
input: Record<string, unknown>;
|
input: Record<string, unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const MAX_RETRIES = 3;
|
||||||
|
|
||||||
export async function makeRequest<T extends BaseTool>(
|
export async function makeRequest<T extends BaseTool>(
|
||||||
prompt: string,
|
prompt: string,
|
||||||
toolDef: T
|
toolDef: T
|
||||||
): Promise<Record<string, unknown>> {
|
): Promise<Record<string, unknown>> {
|
||||||
|
const requiredFields = toolDef.input_schema.required
|
||||||
|
? [...toolDef.input_schema.required]
|
||||||
|
: Object.keys(toolDef.input_schema.properties);
|
||||||
|
|
||||||
|
let lastError: Error | null = null;
|
||||||
|
|
||||||
|
for (let attempt = 1; attempt <= MAX_RETRIES; attempt++) {
|
||||||
try {
|
try {
|
||||||
|
console.log(`AI request attempt ${attempt}/${MAX_RETRIES}`);
|
||||||
|
|
||||||
const completion = await getClient().chat.completions.create({
|
const completion = await getClient().chat.completions.create({
|
||||||
model: 'Meta-Llama-3_3-70B-Instruct',
|
model: 'Meta-Llama-3_3-70B-Instruct',
|
||||||
temperature: 1,
|
temperature: 0.7,
|
||||||
max_tokens: 16000,
|
max_tokens: 16000,
|
||||||
tools: [
|
tools: [
|
||||||
{
|
{
|
||||||
@@ -48,9 +59,7 @@ export async function makeRequest<T extends BaseTool>(
|
|||||||
parameters: {
|
parameters: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: toolDef.input_schema.properties,
|
properties: toolDef.input_schema.properties,
|
||||||
required: toolDef.input_schema.required
|
required: requiredFields
|
||||||
? [...toolDef.input_schema.required]
|
|
||||||
: undefined
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,8 +71,14 @@ export async function makeRequest<T extends BaseTool>(
|
|||||||
messages: [
|
messages: [
|
||||||
{
|
{
|
||||||
role: 'system',
|
role: 'system',
|
||||||
content:
|
content: `You are a data generation assistant that creates realistic synthetic data.
|
||||||
'You are a data generation assistant. Generate realistic, diverse synthetic data. You must respond ONLY with the function call. Do not include any text outside the function call.'
|
|
||||||
|
CRITICAL REQUIREMENTS:
|
||||||
|
1. You MUST call the function with ALL required fields populated
|
||||||
|
2. Required top-level fields: ${requiredFields.join(', ')}
|
||||||
|
3. Every nested object and array must be fully populated with realistic data
|
||||||
|
4. Do NOT leave any field as null, undefined, or empty
|
||||||
|
5. Generate diverse, realistic Italian consumer data`
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
role: 'user',
|
role: 'user',
|
||||||
@@ -89,7 +104,17 @@ export async function makeRequest<T extends BaseTool>(
|
|||||||
const result = JSON.parse(toolCall.function.arguments);
|
const result = JSON.parse(toolCall.function.arguments);
|
||||||
return result;
|
return result;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error making request:', error);
|
console.error(`Attempt ${attempt} failed:`, error);
|
||||||
throw Error('OVH AI Endpoints client error.');
|
lastError = error as Error;
|
||||||
|
|
||||||
|
if (attempt < MAX_RETRIES) {
|
||||||
|
const delay = 1000 * attempt;
|
||||||
|
console.log(`Retrying in ${delay}ms...`);
|
||||||
|
await new Promise(resolve => setTimeout(resolve, delay));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.error('All retry attempts failed');
|
||||||
|
throw lastError || new Error('OVH AI Endpoints client error.');
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user