forked from mendableai/firecrawl
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Caleb: got it to a testable state I believe
- Loading branch information
1 parent
6ee1f2d
commit 0649772
Showing
7 changed files
with
163 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Turndown from 'turndown' | ||
import OpenAI from 'openai' | ||
// import { LlamaModel } from 'node-llama-cpp' | ||
import { z } from 'zod' | ||
import { zodToJsonSchema } from 'zod-to-json-schema' | ||
import { | ||
ScraperCompletionResult, | ||
generateOpenAICompletions, | ||
} from './models.js' | ||
import { ExtractorOptions } from '../entities.js' | ||
|
||
// Generate completion using OpenAI | ||
export function generateCompletions( | ||
documents: Document[], | ||
extractionOptions: ExtractorOptions | ||
): Promise < ScraperCompletionResult < T >> [] { | ||
// const schema = zodToJsonSchema(options.schema) | ||
|
||
const schema = extractionOptions.extractionSchema; | ||
const prompt = extractionOptions.extractionPrompt; | ||
|
||
const loader = documents.map(async (document, i) => { | ||
switch (this.client.constructor) { | ||
case true: | ||
return generateOpenAICompletions<T>( | ||
this.client as OpenAI, | ||
|
||
schema, | ||
options?.prompt, | ||
options?.temperature | ||
) | ||
|
||
//TODO add other models | ||
// case LlamaModel: | ||
// return generateLlamaCompletions<T>( | ||
// this.client, | ||
// await page, | ||
// schema, | ||
// options?.prompt, | ||
// options?.temperature | ||
// ) | ||
default: | ||
throw new Error('Invalid client') | ||
} | ||
}) | ||
|
||
return loader | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters