

    // Prepare messages for the LLM
    const messages = [
      { role: "system", content: systemPrompt },
      { role: "user", content: message },
    ];

    // Get config for inference parameters if exists
    const config = engine.getConfig(engine.feature);
    const inferenceParams = config?.parameters || {};

    // Call the LLM
    const response = await engine.run({
      messages,
      fxAccountToken: await openAIEngine.getFxAccountToken(),
      ...inferenceParams,
    });

    // Extract the generated title from the response
    const title =
      response?.choices?.[0]?.message?.content?.trim() ||
      generateDefaultTitle(message);

    return title;
  } catch (error) {
    console.error("Failed to generate chat title:", error);
    return generateDefaultTitle(message);
  }
}
PK