• Processes a chat completion request by sending messages to a specified completion service. Delegates to an internal context-isolated function to ensure clean execution.

    Parameters

    • completionName: string

      The name of the completion service to use.

    • messages: IBaseMessage<BaseMessageRole>[]

      Array of messages representing the conversation history.

    Returns Promise<string>

    // Example usage
    const output = await chat("openai", [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user", content: "Hello, how are you?" }
    ]);
    console.log(output.content); // Logs the completion output