types.ts 925 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { DEFAULT_MODELS } from "../constant";
  2. export interface LLMUsage {
  3. used: number;
  4. total: number;
  5. available: boolean;
  6. }
  7. export interface LLMModel {
  8. name: string;
  9. available: boolean;
  10. }
  11. export const ROLES = ["system", "user", "assistant"] as const;
  12. export type MessageRole = (typeof ROLES)[number];
  13. export type ChatModel = (typeof DEFAULT_MODELS)[number]["name"];
  14. export interface RequestMessage {
  15. role: MessageRole;
  16. content: string;
  17. }
  18. export interface ChatOptions {
  19. messages: RequestMessage[];
  20. shouldSummarize?: boolean;
  21. onUpdate?: (message: string, chunk: string) => void;
  22. onFinish: (message: string) => void;
  23. onError?: (err: Error) => void;
  24. onController?: (controller: AbortController) => void;
  25. }
  26. export type LLMClient = {
  27. chat(options: ChatOptions): Promise<void>;
  28. chatStream(options: ChatOptions): Promise<void>;
  29. usage(): Promise<LLMUsage>;
  30. models(): Promise<LLMModel[]>;
  31. };