Full API reference for Cord's OpenAI chatbot SDK, npm package @cord-sdk/chatbot-openai


Overview #

This page is a detailed reference of the OpenAI chatbot SDK. For a beginner's overview of how this all fits together, see our Getting Started document, which includes chatbot example code.

The OpenAI chatbot SDK sits on top of the base SDK. The goal of this SDK is to provide utility functions and helpers to connect OpenAI to the base SDK. In particular, the main helpers here provide a getResponse function to use when defining a Chatbot with the base SDK.

The functions exported from the package are:


openaiCompletion #

Provides a getResponse function which connects to OpenAI's completion API and streams the response back to Cord.

What this function returns #

A function which can be used as the getResponse for a Chatbot definition in the base SDK.

Arguments this function takes #


apiKey #

required
string
An OpenAI API key. You can get this from the OpenAI platform website.


getOpenaiMessages #

required
(messages: CoreMessageData[], thread: CoreThreadData) => ChatCompletionMessageParam[] | Promise<ChatCompletionMessageParam[]> | CompletionParams | Promise<...>
The core of your AI logic: a function which takes a Cord thread and message (the same parameters as getResponse) and returns data suitable for sending to OpenAI. This "suitable" data can be any of the following:
  1. An array of OpenAI messages (ChatCompletionMessageParam). In this case, a default model will be used (currently, gpt-4-0613, though this may change in the future).
  2. A full set of OpenAI CompletionParams, which can specify any model (or any other parameters) that you wish. The stream parameter will be forced to true since this Cord SDK supports streaming.
  3. A promise which resolves to one of the above.

openaiSimpleAssistant #

Uses OpenAI's completion API to create a simple AI assistant. This is a simple wrapper on top of openaiCompletion which just injects the system prompt at the top of the list of messages. It uses a default model (currently, gpt-4-0613, though this may change in the future).

What this function returns #

A function which can be used as the getResponse for a Chatbot definition in the base SDK.

Arguments this function takes #


apiKey #

required
string
An OpenAI API key. You can get this from the OpenAI platform website.


systemPrompt #

required
string
The system prompt to use to set the behavior of the AI.

messageToOpenaiMessage #

Converts a message from Cord's format to a one compatible with OpenAI's completion API.

What this function returns #

Arguments this function takes #


message #

required
CoreMessageData
Message data returned by any of Cord's message or thread APIs.

This is an object with the following fields:

Show property details


Not finding the answer you need? Ask our Developer Community

Ask Cordy