//native
/**
* Search
* Search the web with Linkup and get ranked sources, a sourced answer or structured JSON matching a schema.
*/
export async function main(
auth: RT.Linkup,
query: string,
depth: "flash" | "fast" | "standard" | "deep",
output_type: "searchResults" | "sourcedAnswer" | "structured",
structured_output_schema: { [key: string]: any } | undefined,
include_sources: boolean | undefined,
include_inline_citations: boolean | undefined,
include_images: boolean | undefined,
include_domains: string[] | undefined,
exclude_domains: string[] | undefined,
from_date: string | undefined,
to_date: string | undefined,
max_results: number | undefined
) {
const url = new URL("https://api.linkup.so/v1/search")
const hasSchema =
structured_output_schema != null &&
Object.keys(structured_output_schema).length > 0
const response = await fetch(url, {
method: "POST",
headers: {
Authorization: `Bearer ${auth.token}`,
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({
q: query,
depth: depth || "fast",
outputType: output_type || "searchResults",
structuredOutputSchema: hasSchema
? JSON.stringify(structured_output_schema)
: undefined,
includeSources: include_sources || undefined,
includeInlineCitations: include_inline_citations || undefined,
includeImages: include_images || undefined,
includeDomains: include_domains?.length ? include_domains : undefined,
excludeDomains: exclude_domains?.length ? exclude_domains : undefined,
fromDate: from_date || undefined,
toDate: to_date || undefined,
maxResults: max_results ?? undefined,
}),
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 3 hours ago