Skip to content

Commit

Permalink
API docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ariya committed Mar 11, 2024
1 parent 1b3b58e commit e259ece
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ask-llm.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,29 @@ const LLM_STREAMING = process.env.LLM_STREAMING !== 'no';

const LLM_DEBUG = process.env.LLM_DEBUG;

/**
* Represents a chat message.
*
* @typedef {Object} Message
* @property {'system'|'user'|'assistant'} role
* @property {string} content
*/

/**
* A callback function to stream then completion.
*
* @callback CompletionHandler
* @param {string} text
* @returns {void}
*/

/**
* Generates a chat completion using a RESTful LLM API service.
*
* @param {Array<Message>} messages - List of chat messages.
* @param {CompletionHandler=} handler - An optional callback to stream the completion.
* @returns {Promise<string>} The completion generated by the LLM.
*/
const chat = async (messages, handler) => {
const url = `${LLM_API_BASE_URL}/chat/completions`;
const auth = LLM_API_KEY ? { 'Authorization': `Bearer ${LLM_API_KEY}` } : {};
Expand Down

0 comments on commit e259ece

Please sign in to comment.