OpenAI API Client.

This is a concrete implementation of the abstract AIClient class, specifically for OpenAI.

Hierarchy

Constructors

Properties

_client: any

Client for interacting with the OpenAI API.

_model: string

Model used by the AI client.

_tokenizer: any

Tokenizer for encoding messages.

Methods

  • Assembles the chat history based on user inputs, graph changes, and actions taken.

    Parameters

    • userPrompt: string

      user prompt

    • graph: Graph

      current state of the graph

    • history: HistoryElement[]

      array containing the history of actions taken by the user and the graph states

    • historyIndex: number

      index to start from in the history

    • Optional maxLookBack: number

      maximum number of past tasks to include in the output

    Returns Message[]

    assembled chat history with 'user' and 'assistant' roles, and the content for each

  • Returns an object containing the number of tokens in a message and the token limit for the AI model.

    Parameters

    • message: string

      message to count tokens for

    Returns TokenInfo

    an object with a token count and token limit

  • Transforms the history of actions taken by the user and the graph states.

    Parameters

    • history: Message[]

      array containing the history of actions taken by the user and the graph states

    Returns Message[]

    Transformed history

  • Makes a request to the AI model to generate a Q&A response to the user's input of how to use the tool.

    Parameters

    • query: string

      user's query

    Returns Promise<string>

    promise that resolves with the response from the AI model

  • Sends a user prompt to the AI model and returns a difference object between the current graph and the new graph.

    Parameters

    • userPrompt: string

      user prompt

    • params: {
          config: Config;
          graph: Graph;
          history: HistoryElement[];
          historyIndex: number;
      }

      options for the query including current state of the graph, an array containing the history of actions taken by the user and the graph states, index to start from in the history, and configuration options for the query

    Returns Promise<string>

    promise that resolves with the difference between the current graph and the new graph

  • Request completion from the AI model for the given messages.

    Parameters

    • messages: Message[]

      array representing the user's messages

    Returns Promise<string>

    promise that resolves with the response from the AI model

  • Reconfigures the API client with a new key.

    Parameters

    • apiKey: string

      new API key to use

    Returns void

  • Assembles messages for the interactive help prompt.

    Parameters

    • userPrompt: string

      user question to answer

    Returns Message[]

    messages for the interactive help prompt

Generated using TypeDoc