x-crawl
Version:
x-crawl is a flexible Node.js AI-assisted crawler library.
71 lines (56 loc) • 1.7 kB
TypeScript
/// <reference types="node" />
import OpenAI, { ClientOptions } from 'openai'
type OpenAIChatModel = string
export interface CreateCrawlOpenAIConfig {
defaultModel?: {
chatModel: (string & {}) | OpenAIChatModel
}
clientOptions?: ClientOptions
}
export interface CrawlOpenAICommonAPIOtherOption {
model?: (string & {}) | OpenAIChatModel
}
export interface CrawlOpenAIRunChatOption {
model: (string & {}) | OpenAIChatModel | undefined
context: string
HTMLContent: string
userContent: string
responseFormatType: 'text' | 'json_object'
}
export interface CrawlOpenAIParseElementsContentOptions {
message: string
}
export interface CrawlOpenAIGetElementSelectorsContentOptions {
message: string
pathMode: 'default' | 'strict'
}
export interface CrawlOpenAIGetElementSelectorsResult {
selectors: string
type: 'single' | 'multiple' | 'none'
}
export interface CrawlOpenAIParseElementsResult<
T extends Record<string, string>
> {
elements: T[]
type: 'single' | 'multiple' | 'none'
}
export interface CrawlOpenAIApp {
parseElements<T extends Record<string, string>>(
HTML: string,
content: string | CrawlOpenAIParseElementsContentOptions,
option?: CrawlOpenAICommonAPIOtherOption
): Promise<CrawlOpenAIParseElementsResult<T>>
getElementSelectors(
HTML: string,
content: string | CrawlOpenAIGetElementSelectorsContentOptions,
option?: CrawlOpenAICommonAPIOtherOption
): Promise<CrawlOpenAIGetElementSelectorsResult>
help(
content: string,
option?: CrawlOpenAICommonAPIOtherOption
): Promise<string>
custom(): OpenAI
}
export declare function createCrawlOpenAI(
config?: CreateCrawlOpenAIConfig
): CrawlOpenAIApp