Files
webstudio/packages/ai/src/models
Bogdan Chadkin 6f3ac9d20a refactor: drop fetch polyfills (#3125)
Remix Vite no longer polyfills streams and fetch.
Should be safe to drop them.

Stream polyfills broke ai, fetch broke trpc.
2024-04-10 10:56:56 +07:00
..
2024-04-10 10:56:56 +07:00

Models

The Webstudio AI package contemplates a generic, vendor-agnostic messages format and LLM client.

Each vendor (eg. OpenAI) implementation follows the same API and is passed to chains which can use them to interact with a model. This allows to swap LLM without having to modify the chain(s).

export type Model<ModelMessageFormat> = {
  // Turns ModelMessages into a model-specific messages format.
  generateMessages: ModelGenerateMessages<ModelMessageFormat>;
  // JSON completion.
  completion: ModelCompletion<ModelMessageFormat>;
  // Streaming completion.
  completionStream: ModelCompletionStream<ModelMessageFormat>;
};

Currently the package offers an implementation that allows to use OpenAI's Chat Completion endpoint.

Please refer to the type definitions for the baseline vendor-agnostic format and the OpenAI implementation in this folder for an example.