chatgpt-api/src/task.ts

44 wiersze
1.1 KiB
TypeScript
Czysty Zwykły widok Historia

2023-05-26 19:06:39 +00:00
import { ZodRawShape, ZodTypeAny, z } from 'zod'
import * as types from './types'
export abstract class BaseTaskCallBuilder<
TInput extends ZodRawShape | ZodTypeAny = ZodTypeAny,
TOutput extends ZodRawShape | ZodTypeAny = z.ZodTypeAny
> {
2023-05-26 19:16:13 +00:00
protected _inputSchema: TInput
protected _outputSchema: TOutput
protected _timeoutMs: number
protected _retryConfig: types.RetryConfig
2023-05-26 19:06:39 +00:00
constructor(options: types.BaseTaskOptions<TInput, TOutput>) {
2023-05-26 19:16:13 +00:00
this._inputSchema = options.inputSchema
this._outputSchema = options.outputSchema
this._timeoutMs = options.timeoutMs
this._retryConfig = options.retryConfig
2023-05-26 19:06:39 +00:00
}
2023-05-26 23:50:45 +00:00
public get inputSchema(): TInput {
return this._inputSchema
2023-05-26 19:06:39 +00:00
}
2023-05-26 23:50:45 +00:00
public get outputSchema(): TOutput {
return this._outputSchema
2023-05-26 19:06:39 +00:00
}
retry(retryConfig: types.RetryConfig) {
2023-05-26 19:16:13 +00:00
this._retryConfig = retryConfig
2023-05-26 19:06:39 +00:00
return this
}
abstract call(
input?: types.ParsedData<TInput>
): Promise<types.ParsedData<TOutput>>
// TODO
// abstract stream({
// input: TInput,
// onProgress: types.ProgressFunction
// }): Promise<TOutput>
}