//native
/**
* Create research task
* Start an asynchronous Linkup research task that browses the web and returns a sourced answer or structured report. Poll it with Get research task.
*/
export async function main(
auth: RT.Linkup,
query: string,
output_type: "sourcedAnswer" | "structured",
structured_output_schema: { [key: string]: any } | undefined,
mode: "auto" | "answer" | "investigate" | "research" | undefined,
reasoning_depth: "S" | "M" | "L" | "XL" | undefined,
include_domains: string[] | undefined,
exclude_domains: string[] | undefined,
from_date: string | undefined,
to_date: string | undefined
) {
const url = new URL("https://api.linkup.so/v1/research")
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,
outputType: output_type || "sourcedAnswer",
structuredOutputSchema: hasSchema
? JSON.stringify(structured_output_schema)
: undefined,
mode: mode || undefined,
reasoningDepth: reasoning_depth || undefined,
includeDomains: include_domains?.length ? include_domains : undefined,
excludeDomains: exclude_domains?.length ? exclude_domains : undefined,
fromDate: from_date || undefined,
toDate: to_date || undefined,
}),
})
if (!response.ok) {
throw new Error(`${response.status} ${await response.text()}`)
}
return await response.json()
}
Submitted by hugo989 3 hours ago