Spaces:
Sleeping
Sleeping
File size: 4,096 Bytes
097eaf0 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | import type { Action } from "../controllers/v1/types";
import type { BrandingProfile } from "../types/branding";
export type PageOptions = {
includeMarkdown?: boolean;
includeExtract?: boolean;
onlyMainContent?: boolean;
includeHtml?: boolean;
includeRawHtml?: boolean;
fallback?: boolean;
fetchPageContent?: boolean;
waitFor?: number;
screenshot?: boolean;
fullPageScreenshot?: boolean;
headers?: Record<string, string>;
replaceAllPathsWithAbsolutePaths?: boolean;
parsePDF?: boolean;
removeTags?: string | string[];
onlyIncludeTags?: string | string[];
includeLinks?: boolean;
useFastMode?: boolean; // beta
disableJsDom?: boolean; // beta
atsv?: boolean; // anti-bot solver, beta
actions?: Action[]; // beta
geolocation?: {
country?: string;
};
skipTlsVerification?: boolean;
removeBase64Images?: boolean;
mobile?: boolean;
};
export type ExtractorOptions = {
mode:
| "markdown"
| "llm-extraction"
| "llm-extraction-from-markdown"
| "llm-extraction-from-raw-html";
extractionPrompt?: string;
extractionSchema?: Record<string, any>;
userPrompt?: string;
};
export type SearchOptions = {
limit?: number;
tbs?: string;
filter?: string;
lang?: string;
country?: string;
location?: string;
};
export class Document {
id?: string;
url?: string; // Used only in /search for now
content: string;
markdown?: string;
html?: string;
rawHtml?: string;
llm_extraction?: Record<string, any>;
createdAt?: Date;
updatedAt?: Date;
type?: string;
metadata: {
sourceURL?: string;
[key: string]: any;
};
childrenLinks?: string[];
provider?: string;
warning?: string;
actions?: {
screenshots?: string[];
scrapes?: ScrapeActionContent[];
javascriptReturns?: {
type: string;
value: unknown;
}[];
pdfs?: string[];
};
branding?: BrandingProfile;
index?: number;
linksOnPage?: string[]; // Add this new field as a separate property
constructor(data: Partial<Document>) {
if (!data.content) {
throw new Error("Missing required fields");
}
this.content = data.content;
this.createdAt = data.createdAt || new Date();
this.updatedAt = data.updatedAt || new Date();
this.type = data.type || "unknown";
this.metadata = data.metadata || { sourceURL: "" };
this.markdown = data.markdown || "";
this.childrenLinks = data.childrenLinks || undefined;
this.provider = data.provider || undefined;
this.linksOnPage = data.linksOnPage; // Assign linksOnPage if provided
}
}
export class SearchResult {
url: string;
title: string;
description: string;
constructor(url: string, title: string, description: string) {
this.url = url;
this.title = title;
this.description = description;
}
toString(): string {
return `SearchResult(url=${this.url}, title=${this.title}, description=${this.description})`;
}
}
interface ImageSearchResult {
title?: string;
imageUrl?: string;
imageWidth?: number;
imageHeight?: number;
url?: string;
position?: number;
answer?: string;
highlights?: string;
}
interface NewsSearchResult {
title?: string;
url?: string;
snippet?: string;
date?: string;
imageUrl?: string;
position?: number;
category?: string;
// Scraped content fields
markdown?: string;
html?: string;
rawHtml?: string;
links?: string[];
screenshot?: string;
metadata?: Record<string, any>;
answer?: string;
highlights?: string;
}
export interface WebSearchResult {
url: string;
title: string;
description: string;
position?: number;
category?: string;
// Scraped content fields
markdown?: string;
html?: string;
rawHtml?: string;
links?: string[];
screenshot?: string;
metadata?: Record<string, any>;
answer?: string;
highlights?: string;
}
export type SearchResultType = "web" | "images" | "news";
export interface SearchV2Response {
web?: WebSearchResult[];
images?: ImageSearchResult[];
news?: NewsSearchResult[];
}
export interface ScrapeActionContent {
url: string;
html: string;
}
|