({
apiKey,
baseUrl,
defaultHeaders,
provider,
payToAddress,
network,
model,
temperature = 0.7,
maxTokens = 500,
seed,
}: ExampleServiceOptions)
| 35 | private readonly provider: AiProvider; |
| 36 | |
| 37 | constructor({ |
| 38 | apiKey, |
| 39 | baseUrl, |
| 40 | defaultHeaders, |
| 41 | provider, |
| 42 | payToAddress, |
| 43 | network, |
| 44 | model, |
| 45 | temperature = 0.7, |
| 46 | maxTokens = 500, |
| 47 | seed, |
| 48 | }: ExampleServiceOptions) { |
| 49 | const clientOptions: ConstructorParameters<typeof OpenAI>[0] = {}; |
| 50 | |
| 51 | if (provider === 'openai') { |
| 52 | if (!apiKey) { |
| 53 | throw new Error('OPENAI_API_KEY is required when using the OpenAI provider'); |
| 54 | } |
| 55 | clientOptions.apiKey = apiKey; |
| 56 | } else if (provider === 'eigenai') { |
| 57 | if (!defaultHeaders?.['x-api-key']) { |
| 58 | throw new Error('EIGENAI_API_KEY is required when using the EigenAI provider'); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | if (baseUrl) { |
| 63 | clientOptions.baseURL = baseUrl; |
| 64 | } |
| 65 | |
| 66 | if (defaultHeaders && Object.keys(defaultHeaders).length > 0) { |
| 67 | clientOptions.defaultHeaders = defaultHeaders; |
| 68 | } |
| 69 | |
| 70 | this.openai = new OpenAI(clientOptions); |
| 71 | this.payToAddress = payToAddress; |
| 72 | this.network = network; |
| 73 | this.model = model ?? (provider === 'eigenai' ? 'gpt-oss-120b-f16' : 'gpt-4o-mini'); |
| 74 | this.temperature = temperature; |
| 75 | this.maxTokens = maxTokens; |
| 76 | this.seed = seed; |
| 77 | this.provider = provider; |
| 78 | } |
| 79 | |
| 80 | async execute(context: RequestContext, eventQueue: EventQueue): Promise<void> { |
| 81 | const task = context.currentTask; |
nothing calls this directly
no outgoing calls
no test coverage detected