SmythOS SDK
    Preparing search index...

    Class LLMInstance

    Represents a LLM instance. These instances are created by the LLM Factory (LLM).

    const llm = LLM.OpenAI({ model: 'gpt-4o' });
    //the above is equivalent to:
    const llm = new LLMInstance(TLLMProvider.OpenAI, { model: 'gpt-4o' });

    //then you can prompt the LLM to get the response in one shot
    const response = await llm.prompt('Hello, world!');

    //or as a stream
    const stream = await llm.prompt('Hello, world!').stream();
    stream.on('data', (chunk) => console.log(chunk));
    stream.on('end', () => console.log('Stream ended'));
    stream.on('error', (err) => console.error(err));

    //or as a chat (@see )
    const chat = llm.chat();
    chat.prompt('Hello, world!');

    More examples are available in the LLM namespace.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    _readyPromise: ControlledPromise<any>

    Accessors

    Methods

    • Query the LLM with a prompt.

      The returned command can be executed in two ways:

      • Promise mode: returns the final result as a string
      • Streaming mode: returns a stream event emitter

      Parameters

      • prompt: string
      • Optionaloptions: any

      Returns LLMCommand

      // Promise mode : returns the final result as a string
      const response = await llm.prompt("Hello, world!");

      // Streaming mode : returns an EventEmitter
      const stream = await llm.prompt("Tell me a story").stream();
      stream.on('data', chunk => process.stdout.write(chunk));