Chatoyant - v0.2.1
    Preparing search index...

    Class Chat

    Chat class for unified LLM interactions.

    // Simple conversation
    const chat = new Chat({ model: "gpt-4o" });
    chat.system("You are a helpful assistant");

    const reply = await chat.user("Hello!").generate();
    console.log(reply);

    // Streaming
    for await (const delta of chat.user("Tell me a story").stream()) {
    process.stdout.write(delta);
    }

    // Structured output
    const person = await chat.user("Extract: Alice is 30").generateData(PersonSchema);

    // Serialization
    const json = chat.toJSON();
    const restored = Chat.fromJSON(json);
    Index

    Constructors

    • Create a new Chat instance.

      Parameters

      Returns Chat

      // With specific model
      new Chat({ model: 'gpt-4o' });

      // With model preset
      new Chat({ model: 'fast' }); // Uses fastest model for default provider
      new Chat({ model: 'best' }); // Uses highest quality model
      new Chat({ model: 'cheap' }); // Uses most cost-effective model
      new Chat({ model: 'balanced' }); // Good quality/speed/cost balance

    Accessors

    • get model(): string

      Get current model

      Returns string

    • set model(value: string): void

      Set model

      Parameters

      • value: string

      Returns void

    • get tools(): readonly Tool<unknown, unknown>[]

      Get registered tools (readonly)

      Returns readonly Tool<unknown, unknown>[]

    Methods

    • Add a system message.

      Parameters

      • content: string
      • Optionalmetadata: Record<string, unknown>

      Returns this

      this for chaining

    • Add a user message.

      Parameters

      • content: string
      • Optionalmetadata: Record<string, unknown>

      Returns this

      this for chaining

    • Add an assistant message.

      Parameters

      • content: string
      • Optionalmetadata: Record<string, unknown>

      Returns this

      this for chaining

    • Clear all messages.

      Returns this

      this for chaining

    • Register a tool for tool-calling.

      Parameters

      Returns this

      this for chaining

    • Register multiple tools.

      Parameters

      • tools: Tool<unknown, unknown>[]

      Returns this

      this for chaining

    • Clear all tools.

      Returns this

      this for chaining

    • Generate a text response. Automatically uses registered tools if any exist. Appends assistant response to message history.

      Parameters

      Returns Promise<string>

      Generated text content

    • Generate a text response with full result metadata. Does NOT use tools - for direct generation only. Appends assistant response to message history.

      Parameters

      Returns Promise<GenerateResult>

      Full generation result with rich metadata (usage, timing, cost)

    • Stream a text response. Appends assistant response to history after streaming completes.

      Parameters

      Returns AsyncGenerator<string, void, undefined>

      Async generator of content strings

    • Stream and accumulate the full response. Convenience method that collects all chunks.

      Parameters

      Returns Promise<string>

      Full accumulated content

    • Generate structured data using a Schema. Appends assistant response to history.

      Type Parameters

      Parameters

      • schema: T | (new () => T)

        Schema class or instance

      • Optionaloptions: GenerateOptions

        Generation options

      Returns Promise<T>

      Populated schema instance

    • Serialize to JSON string.

      Parameters

      • pretty: boolean = false

      Returns string

    • Load state from JSON object. Replaces current messages and config.

      Parameters

      Returns this