import { Injectable } from '@nestjs/common';
import type { AssistantAPI } from 'Assistant';
import 'isomorphic-fetch';

const importDynamic = new Function('modulePath', 'return import(modulePath)');

@Injectable()
export class ChatgptUnofficialProxyApiService {
  async sendMessage(prompt: string): Promise<{ text: string }> {
    const { AssistantAPIBrowser } = await importDynamic('Assistant');
    const api = new AssistantAPIBrowser({
      email: '996251389@qq.com',
      password: 'Qwer123@',
    });
    await api.initSession();

    const result = await api.sendMessage(prompt);
    return { text: JSON.stringify(result) };
  }
}
帮我优化上述代码，要求：只初始化一次