Class: CohereTextGenerationModel
Create a text generation model that calls the Cohere Co.Generate API.
See
https://docs.cohere.com/reference/generate
Example
const model = new CohereTextGenerationModel({
model: "command",
temperature: 0.7,
maxGenerationTokens: 500,
});
const text = await generateText(
model,
"Write a short story about a robot learning to love:\n\n"
);
Hierarchy
-
AbstractModel
<CohereTextGenerationModelSettings
>↳
CohereTextGenerationModel
Implements
Accessors
modelInformation
• get
modelInformation(): ModelInformation
Returns
Implementation of
TextStreamingBaseModel.modelInformation
Inherited from
AbstractModel.modelInformation
Defined in
packages/modelfusion/src/model-function/AbstractModel.ts:17
modelName
• get
modelName(): "command"
| "command-light"
Returns
"command"
| "command-light"
Overrides
AbstractModel.modelName
Defined in
packages/modelfusion/src/model-provider/cohere/CohereTextGenerationModel.ts:96
settingsForEvent
• get
settingsForEvent(): Partial
<CohereTextGenerationModelSettings
>
Returns settings that should be recorded in observability events. Security-related settings (e.g. API keys) should not be included here.
Returns
Partial
<CohereTextGenerationModelSettings
>
Implementation of
TextStreamingBaseModel.settingsForEvent
Overrides
AbstractModel.settingsForEvent
Defined in
packages/modelfusion/src/model-provider/cohere/CohereTextGenerationModel.ts:154
Constructors
constructor
• new CohereTextGenerationModel(settings
): CohereTextGenerationModel
Parameters
Name | Type |
---|---|
settings | CohereTextGenerationModelSettings |
Returns
Overrides
AbstractModel<CohereTextGenerationModelSettings>.constructor
Defined in
packages/modelfusion/src/model-provider/cohere/CohereTextGenerationModel.ts:83
Methods
callAPI
▸ callAPI<RESPONSE
>(prompt
, callOptions
, options
): Promise
<RESPONSE
>
Type parameters
Name |
---|
RESPONSE |
Parameters
Name | Type |
---|---|
prompt | string |
callOptions | FunctionCallOptions |
options | Object |
options.responseFormat | CohereTextGenerationResponseFormatType <RESPONSE > |
Returns
Promise
<RESPONSE
>
Defined in
packages/modelfusion/src/model-provider/cohere/CohereTextGenerationModel.ts:107
countPromptTokens
▸ countPromptTokens(input
): Promise
<number
>
Parameters
Name | Type |
---|---|
input | string |
Returns
Promise
<number
>
Implementation of
TextStreamingBaseModel.countPromptTokens
Defined in
packages/modelfusion/src/model-provider/cohere/CohereTextGenerationModel.ts:103
doGenerateTexts
▸ doGenerateTexts(prompt
, options
): Promise
<{ rawResponse
: { generations
: { finish_reason?
: string
; id
: string
; text
: string
}[] ; id
: string
; meta?
: { api_version
: { version
: string
} } ; prompt
: string
} ; textGenerationResults
: { finishReason
: TextGenerationFinishReason
; text
: string
= generation.text }[] }>
Parameters
Name | Type |
---|---|
prompt | string |
options | FunctionCallOptions |
Returns
Promise
<{ rawResponse
: { generations
: { finish_reason?
: string
; id
: string
; text
: string
}[] ; id
: string
; meta?
: { api_version
: { version
: string
} } ; prompt
: string
} ; textGenerationResults
: { finishReason
: TextGenerationFinishReason
; text
: string
= generation.text }[] }>
Implementation of
TextStreamingBaseModel.doGenerateTexts
Defined in
packages/modelfusion/src/model-provider/cohere/CohereTextGenerationModel.ts:176
doStreamText
▸ doStreamText(prompt
, options
): Promise
<AsyncIterable
<Delta
<{ is_finished
: false
; text
: string
} | { finish_reason
: string
; is_finished
: true
; response
: { generations
: { finish_reason?
: string
; id
: string
; text
: string
}[] ; id
: string
; meta?
: { api_version
: { version
: string
} } ; prompt
: string
} = cohereTextGenerationResponseSchema }>>>
Parameters
Name | Type |
---|---|
prompt | string |
options | FunctionCallOptions |
Returns
Promise
<AsyncIterable
<Delta
<{ is_finished
: false
; text
: string
} | { finish_reason
: string
; is_finished
: true
; response
: { generations
: { finish_reason?
: string
; id
: string
; text
: string
}[] ; id
: string
; meta?
: { api_version
: { version
: string
} } ; prompt
: string
} = cohereTextGenerationResponseSchema }>>>
Implementation of
TextStreamingBaseModel.doStreamText
Defined in
packages/modelfusion/src/model-provider/cohere/CohereTextGenerationModel.ts:220
extractTextDelta
▸ extractTextDelta(delta
): string
Parameters
Name | Type |
---|---|
delta | unknown |
Returns
string
Implementation of
TextStreamingBaseModel.extractTextDelta
Defined in
packages/modelfusion/src/model-provider/cohere/CohereTextGenerationModel.ts:226
processTextGenerationResponse
▸ processTextGenerationResponse(rawResponse
): Object
Parameters
Name | Type |
---|---|
rawResponse | Object |
rawResponse.generations | { finish_reason? : string ; id : string ; text : string }[] |
rawResponse.id | string |
rawResponse.meta? | Object |
rawResponse.meta.api_version | Object |
rawResponse.meta.api_version.version | string |
rawResponse.prompt | string |
Returns
Object
Name | Type |
---|---|
rawResponse | { generations : { finish_reason? : string ; id : string ; text : string }[] ; id : string ; meta? : { api_version : { version : string } } ; prompt : string } |
rawResponse.generations | { finish_reason? : string ; id : string ; text : string }[] |
rawResponse.id | string |
rawResponse.meta? | { api_version : { version : string } } |
rawResponse.meta.api_version | { version : string } |
rawResponse.meta.api_version.version | string |
rawResponse.prompt | string |
textGenerationResults | { finishReason : TextGenerationFinishReason ; text : string = generation.text }[] |
Defined in
packages/modelfusion/src/model-provider/cohere/CohereTextGenerationModel.ts:193
restoreGeneratedTexts
▸ restoreGeneratedTexts(rawResponse
): Object
Parameters
Name | Type |
---|---|
rawResponse | unknown |
Returns
Object
Name | Type |
---|---|
rawResponse | { generations : { finish_reason? : string ; id : string ; text : string }[] ; id : string ; meta? : { api_version : { version : string } } ; prompt : string } |
rawResponse.generations | { finish_reason? : string ; id : string ; text : string }[] |
rawResponse.id | string |
rawResponse.meta? | { api_version : { version : string } } |
rawResponse.meta.api_version | { version : string } |
rawResponse.meta.api_version.version | string |
rawResponse.prompt | string |
textGenerationResults | { finishReason : TextGenerationFinishReason ; text : string = generation.text }[] |
Implementation of
TextStreamingBaseModel.restoreGeneratedTexts
Defined in
packages/modelfusion/src/model-provider/cohere/CohereTextGenerationModel.ts:184
withChatPrompt
▸ withChatPrompt(options?
): PromptTemplateTextStreamingModel
<ChatPrompt
, string
, CohereTextGenerationModelSettings
, CohereTextGenerationModel
>
Returns this model with a chat prompt template.
Parameters
Name | Type |
---|---|
options? | Object |
options.assistant? | string |
options.user? | string |
Returns
PromptTemplateTextStreamingModel
<ChatPrompt
, string
, CohereTextGenerationModelSettings
, CohereTextGenerationModel
>
Implementation of
TextStreamingBaseModel.withChatPrompt
Defined in
packages/modelfusion/src/model-provider/cohere/CohereTextGenerationModel.ts:243
withInstructionPrompt
▸ withInstructionPrompt(): PromptTemplateTextStreamingModel
<InstructionPrompt
, string
, CohereTextGenerationModelSettings
, CohereTextGenerationModel
>
Returns this model with an instruction prompt template.
Returns
PromptTemplateTextStreamingModel
<InstructionPrompt
, string
, CohereTextGenerationModelSettings
, CohereTextGenerationModel
>
Implementation of
TextStreamingBaseModel.withInstructionPrompt
Defined in
packages/modelfusion/src/model-provider/cohere/CohereTextGenerationModel.ts:239
withJsonOutput
▸ withJsonOutput(): this
When possible, limit the output generation to the specified JSON schema, or super sets of it (e.g. JSON in general).
Returns
this
Implementation of
TextStreamingBaseModel.withJsonOutput
Defined in
packages/modelfusion/src/model-provider/cohere/CohereTextGenerationModel.ts:231
withPromptTemplate
▸ withPromptTemplate<INPUT_PROMPT
>(promptTemplate
): PromptTemplateTextStreamingModel
<INPUT_PROMPT
, string
, CohereTextGenerationModelSettings
, CohereTextGenerationModel
>
Type parameters
Name |
---|
INPUT_PROMPT |
Parameters
Name | Type |
---|---|
promptTemplate | TextGenerationPromptTemplate <INPUT_PROMPT , string > |
Returns
PromptTemplateTextStreamingModel
<INPUT_PROMPT
, string
, CohereTextGenerationModelSettings
, CohereTextGenerationModel
>
Implementation of
TextStreamingBaseModel.withPromptTemplate
Defined in
packages/modelfusion/src/model-provider/cohere/CohereTextGenerationModel.ts:247
withSettings
▸ withSettings(additionalSettings
): CohereTextGenerationModel
The withSettings
method creates a new model with the same configuration as the original model, but with the specified settings changed.
Parameters
Name | Type |
---|---|
additionalSettings | Partial <CohereTextGenerationModelSettings > |
Returns
Example
const model = new OpenAICompletionModel({
model: "gpt-3.5-turbo-instruct",
maxGenerationTokens: 500,
});
const modelWithMoreTokens = model.withSettings({
maxGenerationTokens: 1000,
});
Implementation of
TextStreamingBaseModel.withSettings
Overrides
AbstractModel.withSettings
Defined in
packages/modelfusion/src/model-provider/cohere/CohereTextGenerationModel.ts:266
withTextPrompt
▸ withTextPrompt(): PromptTemplateTextStreamingModel
<string
, string
, CohereTextGenerationModelSettings
, CohereTextGenerationModel
>
Returns this model with a text prompt template.
Returns
PromptTemplateTextStreamingModel
<string
, string
, CohereTextGenerationModelSettings
, CohereTextGenerationModel
>
Implementation of
TextStreamingBaseModel.withTextPrompt
Defined in
packages/modelfusion/src/model-provider/cohere/CohereTextGenerationModel.ts:235
Properties
contextWindowSize
• Readonly
contextWindowSize: number
Implementation of
TextStreamingBaseModel.contextWindowSize
Defined in
packages/modelfusion/src/model-provider/cohere/CohereTextGenerationModel.ts:100
provider
• Readonly
provider: "cohere"
Overrides
AbstractModel.provider
Defined in
packages/modelfusion/src/model-provider/cohere/CohereTextGenerationModel.ts:95
settings
• Readonly
settings: CohereTextGenerationModelSettings
Implementation of
TextStreamingBaseModel.settings
Inherited from
AbstractModel.settings
Defined in
packages/modelfusion/src/model-function/AbstractModel.ts:7
tokenizer
• Readonly
tokenizer: CohereTokenizer
Implementation of
TextStreamingBaseModel.tokenizer
Defined in
packages/modelfusion/src/model-provider/cohere/CohereTextGenerationModel.ts:101