# Class LLMInstance

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

#### Example: Usage example

    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)

- SDKObject
  - LLMInstance

- Defined in src/LLM/LLMInstance.class.ts:188

##### Index

### Constructors

constructor

### Properties

_readyPromise

### Accessors

modelSettings
ready
requester

### Methods

chat
emit
init
initSignal
off
on
once
prompt
removeListener

## Constructors

### constructor

- new LLMInstance(
  _providerId: TLLMProvider,
  _modelSettings: TLLMInstanceParams,
  _candidate?: AccessCandidate,
  ): LLMInstance

  #### Parameters

  - _providerId: TLLMProvider
  - _modelSettings: TLLMInstanceParams
  - `Optional`_candidate: AccessCandidate

  #### Returns LLMInstance

  Overrides SDKObject.constructor

  - Defined in src/LLM/LLMInstance.class.ts:198

## Properties

### `Protected`_readyPromise

_readyPromise: ControlledPromise<any>

Inherited from SDKObject._readyPromise

- Defined in src/Core/SDKObject.class.ts:17

## Accessors

### modelSettings

- get modelSettings(): TLLMInstanceParams

  #### Returns TLLMInstanceParams

  - Defined in src/LLM/LLMInstance.class.ts:190

### ready

- get ready(): ControlledPromise<any>

  #### Returns ControlledPromise<any>

  Inherited from SDKObject.ready

  - Defined in src/Core/SDKObject.class.ts:19

### requester

- get requester(): ILLMConnectorRequest

  #### Returns ILLMConnectorRequest

  - Defined in src/LLM/LLMInstance.class.ts:194

## Methods

### chat

- chat(options?: string | ChatOptions): Chat

  #### Parameters

  - `Optional` options: string | ChatOptions

  #### Returns Chat

  - Defined in src/LLM/LLMInstance.class.ts:257

### emit

- emit(event: string, ...args: any[]): void

  #### Parameters

  - event: string
  - ...args: any[]

  #### Returns void

  Inherited from SDKObject.emit

  - Defined in src/Core/SDKObject.class.ts:45

### `Protected` init

- init(): Promise<void>

  #### Returns Promise<void>

  Overrides SDKObject.init

  - Defined in src/LLM/LLMInstance.class.ts:202

### `Protected` initSignal

- initSignal(): Promise<void>

  #### Returns Promise<void>

  Inherited from SDKObject.initSignal

  - Defined in src/Core/SDKObject.class.ts:37

### off

- off(event: string, listener: (...args: any[]) => void): void

  #### Parameters

  - event: string
  - listener: (...args: any[]) => void

  #### Returns void

  Inherited from SDKObject.off

  - Defined in src/Core/SDKObject.class.ts:49

### on

- on(event: string, listener: (...args: any[]) => void): void

  #### Parameters

  - event: string
  - listener: (...args: any[]) => void

  #### Returns void

  Inherited from SDKObject.on

  - Defined in src/Core/SDKObject.class.ts:41

### once

- once(event: string, listener: (...args: any[]) => void): void

  #### Parameters

  - event: string
  - listener: (...args: any[]) => void

  #### Returns void

  Inherited from SDKObject.once

  - Defined in src/Core/SDKObject.class.ts:53

### prompt

- prompt(prompt: string, options?: TLLMCommandOptions): LLMCommand

  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
  - `Optional` options: TLLMCommandOptions

  #### Returns LLMCommand

  #### Example

      // 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));

  - Defined in src/LLM/LLMInstance.class.ts:247

### removeListener

- removeListener(event: string, listener: (...args: any[]) => void): void

  #### Parameters

  - event: string
  - listener: (...args: any[]) => void

  #### Returns void

  Inherited from SDKObject.removeListener

  - Defined in src/Core/SDKObject.class.ts:56