mirror of
https://github.com/multipleof4/lynchmark.git
synced 2026-01-14 08:37:56 +00:00
Refactor: Make code export handling more robust
This commit is contained in:
@@ -20,7 +20,7 @@ const getLlmCode = async (prompt, model, functionName, temperature) => {
|
|||||||
const duration = (performance.now() - start) / 1000;
|
const duration = (performance.now() - start) / 1000;
|
||||||
const content = res.data.choices[0].message.content;
|
const content = res.data.choices[0].message.content;
|
||||||
const code = content.match(/```(?:javascript|js)?\n([\s\S]+?)\n```/)?.[1].trim() ?? content.trim();
|
const code = content.match(/```(?:javascript|js)?\n([\s\S]+?)\n```/)?.[1].trim() ?? content.trim();
|
||||||
const finalCode = `${code.replace(/^export\s+(default\s+)?/, '')}\nexport default ${functionName};`;
|
const finalCode = `${code.replace(/export\s+default\s+.*$/m, '')}\nexport default ${functionName};`;
|
||||||
return { code: finalCode, duration };
|
return { code: finalCode, duration };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`API Error for ${model}: ${error.message}`);
|
console.error(`API Error for ${model}: ${error.message}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user