diff --git a/actors/extended-gpt-scraper/.actor/input_schema.json b/actors/extended-gpt-scraper/.actor/input_schema.json index b11e8e5..7b675bf 100644 --- a/actors/extended-gpt-scraper/.actor/input_schema.json +++ b/actors/extended-gpt-scraper/.actor/input_schema.json @@ -39,7 +39,8 @@ "gpt-4-32k", "text-davinci-003", "gpt-4-turbo", - "gpt-4o" + "gpt-4o", + "gpt-4o-mini" ], "enumTitles": [ "GPT-3.5 Turbo", @@ -48,7 +49,8 @@ "GPT-4 32k", "GTP-3 (davinci)", "GPT-4 Turbo (Preview)", - "GPT-4o" + "GPT-4o", + "gpt-4o-mini" ] }, "includeUrlGlobs": { diff --git a/code/src/entrypoint.ts b/code/src/entrypoint.ts index 9489de2..6eacc99 100644 --- a/code/src/entrypoint.ts +++ b/code/src/entrypoint.ts @@ -46,7 +46,7 @@ function adjustPprScraperInput(input: Input) { return { ...input, skipGptGlobs: [], - model: 'gpt-3.5-turbo', + model: 'DEFAULT_PPR_SCRAPER', openaiApiKey: getOpenAiApiKeyEnvOrFail(), actorType: ACTORS.PPR_PRICING, }; diff --git a/code/src/models/models.ts b/code/src/models/models.ts index 02a03a2..477ab71 100644 --- a/code/src/models/models.ts +++ b/code/src/models/models.ts @@ -84,4 +84,27 @@ const OPEN_AI_MODELS: { [modelKey: string]: ModelConfig } = { output: 0.015, }, }, + 'gpt-4o-mini': { + modelName: 'gpt-4o-mini', + maxTokens: 128_000, + interface: 'chat', + cost: { + input: 0.00015, + output: 0.0006, + }, + }, + /** + * Default scraper model that we use for the PPR scraper. + * - We limit the max tokens here so the price is capped. + */ + DEFAULT_PPR_SCRAPER: { + modelName: 'gpt-4o-mini', + limitGenerationTokens: true, + maxTokens: 10_000, + interface: 'chat', + cost: { + input: 0.00015, + output: 0.0006, + }, + }, } as const; diff --git a/code/src/models/openai.ts b/code/src/models/openai.ts index fb36643..b34b5e7 100644 --- a/code/src/models/openai.ts +++ b/code/src/models/openai.ts @@ -54,13 +54,16 @@ const wrapInOpenaiError = (error: LangchainError): OpenaiAPIError => { export class OpenAIModelHandler extends GeneralModelHandler { async processInstructions(options: ProcessInstructionsOptions) { - const { instructions, content, schema, schemaDescription, modelSettings } = options; + const { instructions, content, schema, schemaDescription, modelSettings, remainingTokens } = options; + const { modelName, limitGenerationTokens, maxTokens } = this.modelConfig; + log.debug(`Calling Openai API with model ${this.modelConfig.modelName}`); const handleLLMEndCallback = this.handleLLMEndCallbackHandler(); const modelOptions = { ...modelSettings, - modelName: this.modelConfig.modelName, + modelName, + maxTokens: limitGenerationTokens ? remainingTokens : maxTokens, callbacks: [{ handleLLMEnd: handleLLMEndCallback.handleLLMEnd }], }; diff --git a/code/src/routes/crawl-route.ts b/code/src/routes/crawl-route.ts index ba4d50a..9d8c664 100644 --- a/code/src/routes/crawl-route.ts +++ b/code/src/routes/crawl-route.ts @@ -152,6 +152,7 @@ export const crawlRoute = async (context: PlaywrightCrawlingContext) => { } else { log.info(`Processing page ${url} with GPT instruction...`, { contentLength: pageContent.length }); } + const remainingTokens = getNumberOfTextTokens(pageContent) + instructionTokenLength; try { const answerResult = await model.processInstructionsWithRetry({ @@ -160,6 +161,7 @@ export const crawlRoute = async (context: PlaywrightCrawlingContext) => { schema, schemaDescription, modelSettings, + remainingTokens, apifyClient: Actor.apifyClient, }); answer = answerResult.answer; diff --git a/code/src/types/model.ts b/code/src/types/model.ts index 7053557..6b78db3 100644 --- a/code/src/types/model.ts +++ b/code/src/types/model.ts @@ -7,6 +7,8 @@ export interface ModelConfig { maxOutputTokens?: number; interface: 'chat' | 'text'; cost?: Cost; + /** Only used for cases where we need to limit the token limit earlier than the actual maximum (e.g. our PPR Actor) */ + limitGenerationTokens?: true; } export interface Usage { @@ -29,6 +31,7 @@ export interface ProcessInstructionsOptions { modelSettings: ModelSettings; schema?: AnySchema; schemaDescription: string; + remainingTokens: number; } export interface ProcessedInstructions { diff --git a/shared/CHANGELOG.md b/shared/CHANGELOG.md index 73259a2..09d846e 100644 --- a/shared/CHANGELOG.md +++ b/shared/CHANGELOG.md @@ -1,5 +1,11 @@ This changelog tracks updates to both GTP Scraper and Extended GPT Scraper actors. +# 2024-07-30 +*Features* +- Added support for GPT-4o-mini model. (Extended GPT scraper) +- Set this model as the default one for the the *Pay Per Result* scraper with a set token limit. + - With this, the maximum token limit for the *Pay Per Result* scraper was increased by 150%. + # 2024-05-20 *Features* - Added support for GPT-4o model. (Extended GPT Scraper only)