feat: use llama
Some checks failed
Deploy / lint-build-deploy (push) Failing after 57s

This commit is contained in:
2026-02-01 13:03:51 +01:00
parent e51942a9b2
commit 7d1ef8a7e5
10 changed files with 13205 additions and 1058 deletions

100
utils/commands/llama.ts Normal file
View File

@@ -0,0 +1,100 @@
import { queryAi } from '@utils/aiGatewayClient';
import { ShortcutsResponse } from '../types';
import { dbOperations } from '@utils/db';
export async function llamaCommand(
parameters: Record<string, string> | undefined
): Promise<ShortcutsResponse> {
const commandId = Math.random().toString(36).substring(7);
const startTime = Date.now();
let question = '';
let response = '';
let success = false;
let errorMessage: string | undefined;
let tokensUsed: number | undefined;
console.info(`[CMD-${commandId}] Llama command started`, {
hasParameters: !!parameters,
timestamp: new Date().toISOString()
});
try {
if (!parameters || !parameters['question']) {
console.warn(`[CMD-${commandId}] Missing question parameter`);
errorMessage = 'Need to provide a question.';
return {
success: false,
message: 'Sorry. Need to provide a question.'
};
}
question = parameters['question'];
console.info(`[CMD-${commandId}] Processing question`, {
questionLength: question.length,
question:
question.substring(0, 100) + (question.length > 100 ? '...' : '')
});
const prompt =
'I want to know ' +
question +
'. Structure the response in a manner suitable for spoken communication.';
const aiResponse = await queryAi(prompt);
response = aiResponse.text;
tokensUsed = aiResponse.tokensUsed;
success = true;
const duration = Date.now() - startTime;
console.info(
`[CMD-${commandId}] Llama command completed in ${duration}ms`,
{
responseLength: response.length,
tokensUsed,
success: true
}
);
return {
success: true,
message: response,
data: {
tokensUsed
}
};
} catch (error) {
const duration = Date.now() - startTime;
console.error(
`[CMD-${commandId}] Llama command failed after ${duration}ms:`,
error
);
success = false;
errorMessage = error instanceof Error ? error.message : 'Unknown error';
response = 'Sorry. There was a problem with the AI service.';
return {
success: false,
message: response
};
} finally {
if (question) {
try {
console.info(`[CMD-${commandId}] Saving query to database`);
await dbOperations.saveQuery({
question,
response,
success,
errorMessage,
tokensUsed
});
console.info(`[CMD-${commandId}] Query saved to database successfully`);
} catch (error) {
console.error(
`[CMD-${commandId}] Failed to log query to database:`,
error
);
}
}
}
}