🧠 feat: Cohere support as Custom Endpoint (#2328)

* chore: bump cohere-ai, fix firebase vulnerabilities by going down versions

* feat: cohere rates and context windows

* feat(createCoherePayload): transform openai payload for cohere compatibility

* feat: cohere backend support

* refactor(UnknownIcon): optimize icon render and add cohere

* docs: add cohere to Compatible AI Endpoints

* Update ai_endpoints.md
This commit is contained in:
Danny Avila 2024-04-05 15:19:41 -04:00 committed by GitHub
parent daa5f43ac6
commit cd7f3a51e1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 1007 additions and 622 deletions

View file

@ -44,6 +44,30 @@
* @memberof typedefs
*/
/**
* @exports ChatCompletionPayload
* @typedef {import('openai').OpenAI.ChatCompletionCreateParams} ChatCompletionPayload
* @memberof typedefs
*/
/**
* @exports ChatCompletionMessages
* @typedef {import('openai').OpenAI.ChatCompletionMessageParam} ChatCompletionMessages
* @memberof typedefs
*/
/**
* @exports CohereChatStreamRequest
* @typedef {import('cohere-ai').Cohere.ChatStreamRequest} CohereChatStreamRequest
* @memberof typedefs
*/
/**
* @exports CohereChatRequest
* @typedef {import('cohere-ai').Cohere.ChatRequest} CohereChatRequest
* @memberof typedefs
*/
/**
* @exports OpenAIRequestOptions
* @typedef {import('openai').OpenAI.RequestOptions} OpenAIRequestOptions
@ -1062,3 +1086,44 @@
* @method handleMessageEvent Handles events related to messages within the run.
* @method messageCompleted Handles the completion of a message processing.
*/
/* Native app/client methods */
/**
* Accumulates tokens and sends them to the client for processing.
* @callback onTokenProgress
* @param {string} token - The current token generated by the model.
* @returns {Promise<void>}
* @memberof typedefs
*/
/**
* Main entrypoint for API completion calls
* @callback sendCompletion
* @param {Array<ChatCompletionMessages> | string} payload - The messages or prompt to send to the model
* @param {object} opts - Options for the completion
* @param {onTokenProgress} opts.onProgress - Callback function to handle token progress
* @param {AbortController} opts.abortController - AbortController instance
* @returns {Promise<string>}
* @memberof typedefs
*/
/**
* Legacy completion handler for OpenAI API.
* @callback getCompletion
* @param {Array<ChatCompletionMessages> | string} input - Array of messages or a single prompt string
* @param {(event: object | string) => Promise<void>} onProgress - SSE progress handler
* @param {onTokenProgress} onTokenProgress - Token progress handler
* @param {AbortController} [abortController] - AbortController instance
* @returns {Promise<Object | string>} - Completion response
* @memberof typedefs
*/
/**
* Cohere Stream handling. Note: abortController is not supported here.
* @callback cohereChatCompletion
* @param {object} params
* @param {CohereChatStreamRequest | CohereChatRequest} params.payload
* @param {onTokenProgress} params.onTokenProgress
* @memberof typedefs
*/