generative-ts

Function createCohereModelProvider

  • Creates a Cohere ModelProvider with the CohereChatApi or legacy CohereGenerateApi

    import { createCohereModelProvider } from "generative-ts";

    const commandR = createCohereModelProvider({
    modelId: "command-r-plus", // Cohere defined model ID
    // you can explicitly pass auth here, otherwise by default it is read from process.env
    });

    const response = await commandR.sendRequest({
    $prompt: "Brief History of NY Mets:",
    preamble: "Talk like Jafar from Aladdin",
    // all other Cohere /generate options available here
    });

    console.log(response.text);

    Compatible APIs

    Provider Setup and Notes

    Create an API account at Cohere

    Obtain a Cohere API key and either pass them explicitly in auth or set them in the environment as COHERE_API_KEY

    By default, this will use the Cohere /chat API. To use the Legacy Cohere /generate API instead, pass CohereGenerateApi as the api parameter.

    Model Parameters

    Model IDs

    Type Parameters

    • TCohereApi extends CohereApi = CohereChatApi
    • THttpClientOptions = HttpClientOptions

    Parameters

    • params: {
          api?: TCohereApi;
          auth?: CohereAuthConfig;
          client?: HttpClient<THttpClientOptions>;
          modelId: string;
      }
      • Optional api?: TCohereApi

        The API instance to use for making requests. Defaults to CohereChatApi.

      • Optional auth?: CohereAuthConfig

        Authentication configuration for Cohere. If not supplied, it will be loaded from the environment.

      • Optional client?: HttpClient<THttpClientOptions>

        HTTP client to use for requests. If not supplied, the built-in fetch-based implementation will be used.

      • modelId: string

        The model ID as defined by Cohere.

    Returns HttpModelProvider<InferRequestOptions<TCohereApi>, InferResponse<TCohereApi>, THttpClientOptions, BaseModelProviderConfig>

    The Cohere Model Provider with the api specified by params.api

    See

    Throws

    If no auth is passed and COHERE_API_KEY is not found in process.env

    Example: Usage

    import { createCohereModelProvider } from "generative-ts";

    const commandR = createCohereModelProvider({
    modelId: "command-r-plus", // Cohere defined model ID
    // you can explicitly pass auth here, otherwise by default it is read from process.env
    });

    const response = await commandR.sendRequest({
    $prompt: "Brief History of NY Mets:",
    preamble: "Talk like Jafar from Aladdin",
    // all other Cohere /generate options available here
    });

    console.log(response.text);

    Example: Generate API

    import { createCohereModelProvider, CohereGenerateApi } from "generative-ts";

    const command = createCohereModelProvider({
    api: CohereGenerateApi,
    modelId: "command",
    });

    const response = await command.sendRequest({
    $prompt: "Brief History of NY Mets:",
    });