// プログラムコード生成関数
export async function generateCode(systemPrompt: string, userPrompt: string): Promise<string> {
    try {
        const response = await openai.chat.completions.create({
            model: selectedModel,
            messages: [
                { role: 'system', content: systemPrompt },
                { role: 'user', content: userPrompt }
            ],
            max_tokens: MAX_TOKENS // Adjust the token limit as needed
        });

        if (response.choices && response.choices[0].message.content ) {
            return response.choices[0].message.content ;
        } else {
            throw new Error('No completion was generated.');
        }
    } catch (error) {
        console.error('Error generating code:', error);
        throw new Error(`Failed to generate code: ${error}`);
    }
}