Class: OpenAI
OpenAI LLM implementation
Implements
Constructors
constructor
• new OpenAI(init?
)
Parameters
Name | Type |
---|---|
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
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
Name | Type |
---|---|
contextWindow | number |
maxTokens | undefined | 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" |
temperature | number |
tokenizer | CL100K_BASE |
topP | number |
Implementation of
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
Name | Type |
---|---|
T | extends undefined | boolean = undefined |
R | T extends true ? AsyncGenerator <string , void , unknown > : ChatResponse |
Parameters
Name | Type | Description |
---|---|---|
messages | ChatMessage [] | 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
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
Name | Type |
---|---|
T | extends undefined | boolean = undefined |
R | T extends true ? AsyncGenerator <string , void , unknown > : ChatResponse |
Parameters
Name | Type | Description |
---|---|---|
prompt | string | the prompt to complete |
parentEvent? | Event | - |
streaming? | T | - |
Returns
Promise
<R
>
Implementation of
Defined in
packages/core/src/llm/LLM.ts:287
mapMessageType
▸ mapMessageType(messageType
): "function"
| "user"
| "assistant"
| "system"
Parameters
Name | Type |
---|---|
messageType | MessageType |
Returns
"function"
| "user"
| "assistant"
| "system"
Defined in
packages/core/src/llm/LLM.ts:233
streamChat
▸ Protected
streamChat(messages
, parentEvent?
): AsyncGenerator
<string
, void
, unknown
>
Parameters
Name | Type |
---|---|
messages | ChatMessage [] |
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
Name | Type |
---|---|
query | string |
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
Name | Type |
---|---|
messages | ChatMessage [] |
Returns
number