Skip to main content

Class: OpenAI

OpenAI LLM implementation

Implements

Constructors

constructor

new OpenAI(init?)

Parameters

NameType
init?Partial<OpenAI> & { azure?: AzureOpenAIConfig }

Defined in

packages/core/src/llm/LLM.ts:153

Properties

additionalChatOptions

Optional additionalChatOptions: Omit<Partial<ChatCompletionCreateParams>, "model" | "temperature" | "max_tokens" | "messages" | "top_p" | "streaming">

Defined in

packages/core/src/llm/LLM.ts:136


additionalSessionOptions

Optional additionalSessionOptions: Omit<Partial<ClientOptions>, "apiKey" | "timeout" | "maxRetries">

Defined in

packages/core/src/llm/LLM.ts:146


apiKey

Optional apiKey: string = undefined

Defined in

packages/core/src/llm/LLM.ts:142


callbackManager

Optional callbackManager: CallbackManager

Defined in

packages/core/src/llm/LLM.ts:151


hasStreaming

hasStreaming: boolean = true

Implementation of

LLM.hasStreaming

Defined in

packages/core/src/llm/LLM.ts:129


maxRetries

maxRetries: number

Defined in

packages/core/src/llm/LLM.ts:143


maxTokens

Optional maxTokens: number

Defined in

packages/core/src/llm/LLM.ts:135


model

model: "gpt-3.5-turbo" | "gpt-3.5-turbo-1106" | "gpt-3.5-turbo-16k" | "gpt-4" | "gpt-4-32k" | "gpt-4-1106-preview" | "gpt-4-vision-preview"

Defined in

packages/core/src/llm/LLM.ts:132


session

session: OpenAISession

Defined in

packages/core/src/llm/LLM.ts:145


temperature

temperature: number

Defined in

packages/core/src/llm/LLM.ts:133


timeout

Optional timeout: number

Defined in

packages/core/src/llm/LLM.ts:144


topP

topP: number

Defined in

packages/core/src/llm/LLM.ts:134

Accessors

metadata

get metadata(): Object

Returns

Object

NameType
contextWindownumber
maxTokensundefined | number
model"gpt-3.5-turbo" | "gpt-3.5-turbo-1106" | "gpt-3.5-turbo-16k" | "gpt-4" | "gpt-4-32k" | "gpt-4-1106-preview" | "gpt-4-vision-preview"
temperaturenumber
tokenizerCL100K_BASE
topPnumber

Implementation of

LLM.metadata

Defined in

packages/core/src/llm/LLM.ts:207

Methods

chat

chat<T, R>(messages, parentEvent?, streaming?): Promise<R>

Get a chat response from the LLM

Type parameters

NameType
Textends undefined | boolean = undefined
RT extends true ? AsyncGenerator<string, void, unknown> : ChatResponse

Parameters

NameTypeDescription
messagesChatMessage[]The return type of chat() and complete() are set by the "streaming" parameter being set to True.
parentEvent?Event-
streaming?T-

Returns

Promise<R>

Implementation of

LLM.chat

Defined in

packages/core/src/llm/LLM.ts:250


complete

complete<T, R>(prompt, parentEvent?, streaming?): Promise<R>

Get a prompt completion from the LLM

Type parameters

NameType
Textends undefined | boolean = undefined
RT extends true ? AsyncGenerator<string, void, unknown> : ChatResponse

Parameters

NameTypeDescription
promptstringthe prompt to complete
parentEvent?Event-
streaming?T-

Returns

Promise<R>

Implementation of

LLM.complete

Defined in

packages/core/src/llm/LLM.ts:287


mapMessageType

mapMessageType(messageType): "function" | "user" | "assistant" | "system"

Parameters

NameType
messageTypeMessageType

Returns

"function" | "user" | "assistant" | "system"

Defined in

packages/core/src/llm/LLM.ts:233


streamChat

Protected streamChat(messages, parentEvent?): AsyncGenerator<string, void, unknown>

Parameters

NameType
messagesChatMessage[]
parentEvent?Event

Returns

AsyncGenerator<string, void, unknown>

Defined in

packages/core/src/llm/LLM.ts:301


streamComplete

Protected streamComplete(query, parentEvent?): AsyncGenerator<string, void, unknown>

Parameters

NameType
querystring
parentEvent?Event

Returns

AsyncGenerator<string, void, unknown>

Defined in

packages/core/src/llm/LLM.ts:365


tokens

tokens(messages): number

Calculates the number of tokens needed for the given chat messages

Parameters

NameType
messagesChatMessage[]

Returns

number

Implementation of

LLM.tokens

Defined in

packages/core/src/llm/LLM.ts:218