pull/643/head^2
Travis Fischer 2024-06-02 19:35:48 -05:00
rodzic 1a90a1e129
commit 8fb9ddf271
3 zmienionych plików z 253 dodań i 219 usunięć

Wyświetl plik

@ -1,222 +1,229 @@
import defaultKy, { type KyInstance } from 'ky' import defaultKy, { type KyInstance } from 'ky'
import { z } from 'zod'
import { aiFunction, AIFunctionsProvider } from '../fns.js'
import { assert, getEnv, omit, pick, pruneUndefined } from '../utils.js' import { assert, getEnv, omit, pick, pruneUndefined } from '../utils.js'
export namespace searxng { export namespace searxng {
export type SearchCategory = export const SearchCategorySchema = z.enum([
| 'general' 'general',
| 'images' 'images',
| 'videos' 'videos',
| 'news' 'news',
| 'map' 'map',
| 'music' 'music',
| 'it' 'it',
| 'science' 'science',
| 'files' 'files',
| 'social media' 'social media'
])
export type SearchCategory = z.infer<typeof SearchCategorySchema>
export type SearchEngine = export const SearchEngineSchema = z.enum([
| '9gag' '9gag',
| 'annas archive' 'annas archive',
| 'apk mirror' 'apk mirror',
| 'apple app store' 'apple app store',
| 'ahmia' 'ahmia',
| 'anaconda' 'anaconda',
| 'arch linux wiki' 'arch linux wiki',
| 'artic' 'artic',
| 'arxiv' 'arxiv',
| 'ask' 'ask',
| 'bandcamp' 'bandcamp',
| 'wikipedia' 'wikipedia',
| 'bilibili' 'bilibili',
| 'bing' 'bing',
| 'bing images' 'bing images',
| 'bing news' 'bing news',
| 'bing videos' 'bing videos',
| 'bitbucket' 'bitbucket',
| 'bpb' 'bpb',
| 'btdigg' 'btdigg',
| 'ccc-tv' 'ccc-tv',
| 'openverse' 'openverse',
| 'chefkoch' 'chefkoch',
| 'crossref' 'crossref',
| 'crowdview' 'crowdview',
| 'yep' 'yep',
| 'yep images' 'yep images',
| 'yep news' 'yep news',
| 'curlie' 'curlie',
| 'currency' 'currency',
| 'bahnhof' 'bahnhof',
| 'deezer' 'deezer',
| 'destatis' 'destatis',
| 'deviantart' 'deviantart',
| 'ddg definitions' 'ddg definitions',
| 'docker hub' 'docker hub',
| 'erowid' 'erowid',
| 'wikidata' 'wikidata',
| 'duckduckgo' 'duckduckgo',
| 'duckduckgo images' 'duckduckgo images',
| 'duckduckgo videos' 'duckduckgo videos',
| 'duckduckgo news' 'duckduckgo news',
| 'duckduckgo weather' 'duckduckgo weather',
| 'apple maps' 'apple maps',
| 'emojipedia' 'emojipedia',
| 'tineye' 'tineye',
| 'etymonline' 'etymonline',
| '1x' '1x',
| 'fdroid' 'fdroid',
| 'flickr' 'flickr',
| 'free software directory' 'free software directory',
| 'frinkiac' 'frinkiac',
| 'fyyd' 'fyyd',
| 'genius' 'genius',
| 'gentoo' 'gentoo',
| 'gitlab' 'gitlab',
| 'github' 'github',
| 'codeberg' 'codeberg',
| 'goodreads' 'goodreads',
| 'google' 'google',
| 'google images' 'google images',
| 'google news' 'google news',
| 'google videos' 'google videos',
| 'google scholar' 'google scholar',
| 'google play apps' 'google play apps',
| 'google play movies' 'google play movies',
| 'material icons' 'material icons',
| 'gpodder' 'gpodder',
| 'habrahabr' 'habrahabr',
| 'hackernews' 'hackernews',
| 'hoogle' 'hoogle',
| 'imdb' 'imdb',
| 'imgur' 'imgur',
| 'ina' 'ina',
| 'invidious' 'invidious',
| 'jisho' 'jisho',
| 'kickass' 'kickass',
| 'lemmy communities' 'lemmy communities',
| 'lemmy users' 'lemmy users',
| 'lemmy posts' 'lemmy posts',
| 'lemmy comments' 'lemmy comments',
| 'library genesis' 'library genesis',
| 'z-library' 'z-library',
| 'library of congress' 'library of congress',
| 'lingva' 'lingva',
| 'lobste.rs' 'lobste.rs',
| 'mastodon users' 'mastodon users',
| 'mastodon hashtags' 'mastodon hashtags',
| 'mdn' 'mdn',
| 'metacpan' 'metacpan',
| 'mixcloud' 'mixcloud',
| 'mozhi' 'mozhi',
| 'mwmbl' 'mwmbl',
| 'npm' 'npm',
| 'nyaa' 'nyaa',
| 'mankier' 'mankier',
| 'odysee' 'odysee',
| 'openairedatasets' 'openairedatasets',
| 'openairepublications' 'openairepublications',
| 'openstreetmap' 'openstreetmap',
| 'openrepos' 'openrepos',
| 'packagist' 'packagist',
| 'pdbe' 'pdbe',
| 'photon' 'photon',
| 'pinterest' 'pinterest',
| 'piped' 'piped',
| 'piped.music' 'piped.music',
| 'piratebay' 'piratebay',
| 'podcastindex' 'podcastindex',
| 'presearch' 'presearch',
| 'presearch images' 'presearch images',
| 'presearch videos' 'presearch videos',
| 'presearch news' 'presearch news',
| 'pub.dev' 'pub.dev',
| 'pubmed' 'pubmed',
| 'pypi' 'pypi',
| 'qwant' 'qwant',
| 'qwant news' 'qwant news',
| 'qwant images' 'qwant images',
| 'qwant videos' 'qwant videos',
| 'radio browser' 'radio browser',
| 'reddit' 'reddit',
| 'rottentomatoes' 'rottentomatoes',
| 'sepiasearch' 'sepiasearch',
| 'soundcloud' 'soundcloud',
| 'stackoverflow' 'stackoverflow',
| 'askubuntu' 'askubuntu',
| 'internetarchivescholar' 'internetarchivescholar',
| 'superuser' 'superuser',
| 'searchcode code' 'searchcode code',
| 'semantic scholar' 'semantic scholar',
| 'startpage' 'startpage',
| 'tokyotoshokan' 'tokyotoshokan',
| 'solidtorrents' 'solidtorrents',
| 'tagesschau' 'tagesschau',
| 'tmdb' 'tmdb',
| 'torch' 'torch',
| 'unsplash' 'unsplash',
| 'yandex music' 'yandex music',
| 'yahoo' 'yahoo',
| 'yahoo news' 'yahoo news',
| 'youtube' 'youtube',
| 'dailymotion' 'dailymotion',
| 'vimeo' 'vimeo',
| 'wiby' 'wiby',
| 'alexandria' 'alexandria',
| 'wikibooks' 'wikibooks',
| 'wikinews' 'wikinews',
| 'wikiquote' 'wikiquote',
| 'wikisource' 'wikisource',
| 'wikispecies' 'wikispecies',
| 'wiktionary' 'wiktionary',
| 'wikiversity' 'wikiversity',
| 'wikivoyage' 'wikivoyage',
| 'wikicommons.images' 'wikicommons.images',
| 'wolframalpha' 'wolframalpha',
| 'dictzone' 'dictzone',
| 'mymemory translated' 'mymemory translated',
| '1337x' '1337x',
| 'duden' 'duden',
| 'seznam' 'seznam',
| 'mojeek' 'mojeek',
| 'moviepilot' 'moviepilot',
| 'naver' 'naver',
| 'rubygems' 'rubygems',
| 'peertube' 'peertube',
| 'mediathekviewweb' 'mediathekviewweb',
| 'yacy' 'yacy',
| 'yacy images' 'yacy images',
| 'rumble' 'rumble',
| 'livespace' 'livespace',
| 'wordnik' 'wordnik',
| 'woxikon.de synonyme' 'woxikon.de synonyme',
| 'seekr news' 'seekr news',
| 'seekr images' 'seekr images',
| 'seekr videos' 'seekr videos',
| 'sjp.pwn' 'sjp.pwn',
| 'stract' 'stract',
| 'svgrepo' 'svgrepo',
| 'tootfinder' 'tootfinder',
| 'wallhaven' 'wallhaven',
| 'wikimini' 'wikimini',
| 'wttr.in' 'wttr.in',
| 'yummly' 'yummly',
| 'brave' 'brave',
| 'brave.images' 'brave.images',
| 'brave.videos' 'brave.videos',
| 'brave.news' 'brave.news',
| 'lib.rs' 'lib.rs',
| 'sourcehut' 'sourcehut',
| 'goo' 'goo',
| 'bt4g' 'bt4g',
| 'pkg.go.dev' 'pkg.go.dev'
])
export type SearchEngine = z.infer<typeof SearchEngineSchema>
export interface SearchOptions { export const SearchOptionsSchema = z.object({
query: string query: z.string().describe('search query'),
categories?: SearchCategory[] categories: z.array(SearchCategorySchema).optional(),
engines?: SearchEngine[] engines: z.array(SearchEngineSchema).optional(),
language?: string language: z.string().optional(),
pageno?: number pageno: z.number().int().optional()
} })
export type SearchOptions = z.infer<typeof SearchOptionsSchema>
export interface SearchResult { export interface SearchResult {
title: string title: string
@ -246,7 +253,7 @@ export namespace searxng {
* *
* See [perplexica](https://github.com/ItzCrazyKns/Perplexica/blob/master/docker-compose.yaml) for an example. * See [perplexica](https://github.com/ItzCrazyKns/Perplexica/blob/master/docker-compose.yaml) for an example.
*/ */
export class SearxngClient { export class SearxngClient extends AIFunctionsProvider {
readonly ky: KyInstance readonly ky: KyInstance
readonly apiBaseUrl: string readonly apiBaseUrl: string
@ -254,7 +261,6 @@ export class SearxngClient {
apiBaseUrl = getEnv('SEARXNG_API_BASE_URL'), apiBaseUrl = getEnv('SEARXNG_API_BASE_URL'),
ky = defaultKy ky = defaultKy
}: { }: {
apiKey?: string
apiBaseUrl?: string apiBaseUrl?: string
ky?: KyInstance ky?: KyInstance
} = {}) { } = {}) {
@ -262,12 +268,34 @@ export class SearxngClient {
apiBaseUrl, apiBaseUrl,
'SearxngClient missing required "apiBaseUrl" (defaults to "SEARXNG_API_BASE_URL")' 'SearxngClient missing required "apiBaseUrl" (defaults to "SEARXNG_API_BASE_URL")'
) )
super()
this.apiBaseUrl = apiBaseUrl this.apiBaseUrl = apiBaseUrl
this.ky = ky.extend({ prefixUrl: apiBaseUrl }) this.ky = ky.extend({ prefixUrl: apiBaseUrl })
} }
@aiFunction({
name: 'searxng',
description: `Searches across multiple search engines using a local instance of Searxng. To search only specific engines, use the \`engines\` parameter.
The most important search engines are:
- "reddit" (Reddit posts)
- "google" (Google web search)
- "google news" (Google News search)
- "brave" (Brave web search)
- "arxiv" (academic papers)
- "genius" (Genius.com for song lyrics)
- "imdb" (movies and TV shows)
- "hackernews" (Hacker News)
- "wikidata" (Wikidata)
- "wolframalpha" (Wolfram Alpha)
- "youtube" (YouTube videos)
- "github" (GitHub code and repositories)
`,
inputSchema: searxng.SearchOptionsSchema
})
async search({ async search({
query, query,
...opts ...opts

Wyświetl plik

@ -649,7 +649,7 @@ export class SerpAPIClient extends AIFunctionsProvider {
apiBaseUrl?: string apiBaseUrl?: string
ky?: KyInstance ky?: KyInstance
} & serpapi.ClientParams = {}) { } & serpapi.ClientParams = {}) {
assert(apiKey, `Error SerpAPIClient missing required "apiKey"`) assert(apiKey, 'Error SerpAPIClient missing required "apiKey"')
super() super()
this.apiKey = apiKey this.apiKey = apiKey
@ -667,7 +667,13 @@ export class SerpAPIClient extends AIFunctionsProvider {
'Uses Google Search to return the most relevant web pages for a given query. Can also be used to find up-to-date news and information about many topics.', 'Uses Google Search to return the most relevant web pages for a given query. Can also be used to find up-to-date news and information about many topics.',
inputSchema: z.object({ inputSchema: z.object({
q: z.string().describe('search query'), q: z.string().describe('search query'),
num: z.number().int().positive().default(5).optional() num: z
.number()
.int()
.positive()
.default(5)
.optional()
.describe('number of results to return')
}) })
}) })
async search(queryOrOpts: string | serpapi.GoogleParameters) { async search(queryOrOpts: string | serpapi.GoogleParameters) {
@ -685,7 +691,7 @@ export class SerpAPIClient extends AIFunctionsProvider {
...rest, ...rest,
engine: 'google', engine: 'google',
api_key: this.apiKey, api_key: this.apiKey,
...(options as any) // TODO ...(options as any)
}, },
timeout timeout
}) })

Wyświetl plik

@ -227,7 +227,7 @@ export class SerperClient extends AIFunctionsProvider {
} & serper.ClientParams = {}) { } & serper.ClientParams = {}) {
assert( assert(
apiKey, apiKey,
`SerperClient missing required "apiKey" (defaults to "SERPER_API_KEY" env var)` 'SerperClient missing required "apiKey" (defaults to "SERPER_API_KEY" env var)'
) )
super() super()
@ -239,7 +239,7 @@ export class SerperClient extends AIFunctionsProvider {
this.ky = ky.extend({ this.ky = ky.extend({
prefixUrl: this.apiBaseUrl, prefixUrl: this.apiBaseUrl,
headers: { headers: {
'X-API-KEY': this.apiKey 'x-api-key': this.apiKey
} }
}) })
} }