Skip to main content

Namespace: cohere

Functions

Api

Api(settings): CohereApiConfiguration

Creates an API configuration for the Cohere API. It calls the API at https://api.cohere.ai/v1 and uses the COHERE_API_KEY env variable by default.

Parameters

NameType
settingsOmit<BaseUrlPartsApiConfigurationOptions, "baseUrl"> & { baseUrl?: string | Partial<UrlParts> } & { apiKey?: string }

Returns

CohereApiConfiguration

Defined in

packages/modelfusion/src/model-provider/cohere/CohereFacade.ts:17


TextEmbedder

TextEmbedder(settings): CohereTextEmbeddingModel

Create a text embedding model that calls the Cohere Co.Embed API.

Parameters

NameType
settingsCohereTextEmbeddingModelSettings

Returns

CohereTextEmbeddingModel

A new instance of CohereTextEmbeddingModel.

See

https://docs.cohere.com/reference/embed

Example

const embeddings = await embedMany(
cohere.TextEmbedder({ model: "embed-english-light-v2.0" }),
[
"At first, Nox didn't know what to do with the pup.",
"He keenly observed and absorbed everything around him, from the birds in the sky to the trees in the forest.",
]
);

Defined in

packages/modelfusion/src/model-provider/cohere/CohereFacade.ts:64


TextGenerator

TextGenerator(settings): CohereTextGenerationModel

Create a text generation model that calls the Cohere Co.Generate API.

Parameters

NameType
settingsCohereTextGenerationModelSettings

Returns

CohereTextGenerationModel

A new instance of CohereTextGenerationModel.

See

https://docs.cohere.com/reference/generate

Example

const model = cohere.TextGenerator({
model: "command",
temperature: 0.7,
maxGenerationTokens: 500,
});

const text = await generateText(
model,
"Write a short story about a robot learning to love:\n\n"
);

Defined in

packages/modelfusion/src/model-provider/cohere/CohereFacade.ts:44


Tokenizer

Tokenizer(settings): CohereTokenizer

Tokenizer for the Cohere models. It uses the Co.Tokenize and Co.Detokenize APIs.

Parameters

NameType
settingsCohereTokenizerSettings

Returns

CohereTokenizer

A new instance of CohereTokenizer.

See

Example

const tokenizer = cohere.Tokenizer({ model: "command" });

const text = "At first, Nox didn't know what to do with the pup.";

const tokenCount = await countTokens(tokenizer, text);
const tokens = await tokenizer.tokenize(text);
const tokensAndTokenTexts = await tokenizer.tokenizeWithTexts(text);
const reconstructedText = await tokenizer.detokenize(tokens);

Defined in

packages/modelfusion/src/model-provider/cohere/CohereFacade.ts:86