AbstractChatCompletionRunner.d.ts 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import * as Core from "../core.js";
  2. import { type CompletionUsage } from "../resources/completions.js";
  3. import { type ChatCompletion, type ChatCompletionMessage, type ChatCompletionMessageParam, type ChatCompletionCreateParams } from "../resources/chat/completions.js";
  4. import { type BaseFunctionsArgs } from "./RunnableFunction.js";
  5. import { ChatCompletionFunctionRunnerParams, ChatCompletionToolRunnerParams } from "./ChatCompletionRunner.js";
  6. import { ChatCompletionStreamingFunctionRunnerParams, ChatCompletionStreamingToolRunnerParams } from "./ChatCompletionStreamingRunner.js";
  7. import { BaseEvents, EventStream } from "./EventStream.js";
  8. import { ParsedChatCompletion } from "../resources/beta/chat/completions.js";
  9. import OpenAI from "../index.js";
  10. export interface RunnerOptions extends Core.RequestOptions {
  11. /** How many requests to make before canceling. Default 10. */
  12. maxChatCompletions?: number;
  13. }
  14. export declare class AbstractChatCompletionRunner<EventTypes extends AbstractChatCompletionRunnerEvents, ParsedT> extends EventStream<EventTypes> {
  15. #private;
  16. protected _chatCompletions: ParsedChatCompletion<ParsedT>[];
  17. messages: ChatCompletionMessageParam[];
  18. protected _addChatCompletion(this: AbstractChatCompletionRunner<AbstractChatCompletionRunnerEvents, ParsedT>, chatCompletion: ParsedChatCompletion<ParsedT>): ParsedChatCompletion<ParsedT>;
  19. protected _addMessage(this: AbstractChatCompletionRunner<AbstractChatCompletionRunnerEvents, ParsedT>, message: ChatCompletionMessageParam, emit?: boolean): void;
  20. /**
  21. * @returns a promise that resolves with the final ChatCompletion, or rejects
  22. * if an error occurred or the stream ended prematurely without producing a ChatCompletion.
  23. */
  24. finalChatCompletion(): Promise<ParsedChatCompletion<ParsedT>>;
  25. /**
  26. * @returns a promise that resolves with the content of the final ChatCompletionMessage, or rejects
  27. * if an error occurred or the stream ended prematurely without producing a ChatCompletionMessage.
  28. */
  29. finalContent(): Promise<string | null>;
  30. /**
  31. * @returns a promise that resolves with the the final assistant ChatCompletionMessage response,
  32. * or rejects if an error occurred or the stream ended prematurely without producing a ChatCompletionMessage.
  33. */
  34. finalMessage(): Promise<ChatCompletionMessage>;
  35. /**
  36. * @returns a promise that resolves with the content of the final FunctionCall, or rejects
  37. * if an error occurred or the stream ended prematurely without producing a ChatCompletionMessage.
  38. */
  39. finalFunctionCall(): Promise<ChatCompletionMessage.FunctionCall | undefined>;
  40. finalFunctionCallResult(): Promise<string | undefined>;
  41. totalUsage(): Promise<CompletionUsage>;
  42. allChatCompletions(): ChatCompletion[];
  43. protected _emitFinal(this: AbstractChatCompletionRunner<AbstractChatCompletionRunnerEvents, ParsedT>): void;
  44. protected _createChatCompletion(client: OpenAI, params: ChatCompletionCreateParams, options?: Core.RequestOptions): Promise<ParsedChatCompletion<ParsedT>>;
  45. protected _runChatCompletion(client: OpenAI, params: ChatCompletionCreateParams, options?: Core.RequestOptions): Promise<ChatCompletion>;
  46. protected _runFunctions<FunctionsArgs extends BaseFunctionsArgs>(client: OpenAI, params: ChatCompletionFunctionRunnerParams<FunctionsArgs> | ChatCompletionStreamingFunctionRunnerParams<FunctionsArgs>, options?: RunnerOptions): Promise<void>;
  47. protected _runTools<FunctionsArgs extends BaseFunctionsArgs>(client: OpenAI, params: ChatCompletionToolRunnerParams<FunctionsArgs> | ChatCompletionStreamingToolRunnerParams<FunctionsArgs>, options?: RunnerOptions): Promise<void>;
  48. }
  49. export interface AbstractChatCompletionRunnerEvents extends BaseEvents {
  50. functionCall: (functionCall: ChatCompletionMessage.FunctionCall) => void;
  51. message: (message: ChatCompletionMessageParam) => void;
  52. chatCompletion: (completion: ChatCompletion) => void;
  53. finalContent: (contentSnapshot: string) => void;
  54. finalMessage: (message: ChatCompletionMessageParam) => void;
  55. finalChatCompletion: (completion: ChatCompletion) => void;
  56. finalFunctionCall: (functionCall: ChatCompletionMessage.FunctionCall) => void;
  57. functionCallResult: (content: string) => void;
  58. finalFunctionCallResult: (content: string) => void;
  59. totalUsage: (usage: CompletionUsage) => void;
  60. }
  61. //# sourceMappingURL=AbstractChatCompletionRunner.d.ts.map