write-language 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -32
- package/dist/generate-response.d.ts +34 -0
- package/dist/generation-types.d.ts +68 -0
- package/dist/index.d.ts +20 -0
- package/dist/language-model-registry.d.ts +105 -0
- package/dist/prompt-templates.d.ts +37 -0
- package/dist/prompts/index.d.ts +5 -0
- package/dist/prompts/meta-search-types.d.ts +6 -0
- package/dist/prompts/search-prompts.d.ts +12 -0
- package/dist/provider-factory.d.ts +11 -0
- package/dist/tools/qwksearch-api-tools.d.ts +149 -0
- package/dist/types.d.ts +2 -0
- package/dist/utils/markdown-to-html.d.ts +5 -0
- package/dist/write-language.cjs.js +2 -0
- package/dist/write-language.cjs.js.map +1 -0
- package/dist/write-language.es.js +2 -0
- package/dist/write-language.es.js.map +1 -0
- package/package.json +6 -7
- package/src/generate-response.ts +2 -2
- package/src/generation-types.ts +2 -2
- package/src/index.ts +1 -1
package/README.md
CHANGED
|
@@ -34,9 +34,9 @@ npm install write-language
|
|
|
34
34
|
### Basic Response Generation
|
|
35
35
|
|
|
36
36
|
```typescript
|
|
37
|
-
import {
|
|
37
|
+
import { writeLanguageResponse } from 'write-language';
|
|
38
38
|
|
|
39
|
-
const result = await
|
|
39
|
+
const result = await writeLanguageResponse({
|
|
40
40
|
provider: 'openai',
|
|
41
41
|
model: 'gpt-4-turbo',
|
|
42
42
|
prompt: 'Explain quantum computing in simple terms',
|
|
@@ -49,7 +49,7 @@ console.log(result.text);
|
|
|
49
49
|
### Streaming Responses
|
|
50
50
|
|
|
51
51
|
```typescript
|
|
52
|
-
const result = await
|
|
52
|
+
const result = await writeLanguageResponse({
|
|
53
53
|
provider: 'anthropic',
|
|
54
54
|
model: 'claude-3-5-sonnet-20241022',
|
|
55
55
|
prompt: 'Write a short story about AI',
|
|
@@ -107,7 +107,7 @@ const model = provider('llama-3.3-70b-versatile');
|
|
|
107
107
|
```typescript
|
|
108
108
|
import { AGENT_PROMPTS } from 'write-language';
|
|
109
109
|
|
|
110
|
-
const result = await
|
|
110
|
+
const result = await writeLanguageResponse({
|
|
111
111
|
provider: 'openai',
|
|
112
112
|
model: 'gpt-4',
|
|
113
113
|
prompt: AGENT_PROMPTS.researchAgent.systemPrompt,
|
|
@@ -132,7 +132,7 @@ const html = convertMarkdownToHTMLEscaped(markdown);
|
|
|
132
132
|
|
|
133
133
|
## API Reference
|
|
134
134
|
|
|
135
|
-
### `
|
|
135
|
+
### `writeLanguageResponse(options)`
|
|
136
136
|
|
|
137
137
|
Generate an AI language response.
|
|
138
138
|
|
|
@@ -168,35 +168,30 @@ Create a provider instance.
|
|
|
168
168
|
- `getTextOnlyModels()`: Get text-only models
|
|
169
169
|
- `getMultimodalModels()`: Get multimodal models
|
|
170
170
|
|
|
171
|
-
|
|
171
|
+
Multi-provider AI agent toolkit for generating language responses, searching the web, extracting page content, and managing long-term memory across 10+ LLM providers.
|
|
172
172
|
|
|
173
|
-
|
|
174
|
-
|----------|--------|--------------|
|
|
175
|
-
| OpenAI | GPT-4, GPT-3.5, o1, o3 | Text, Multimodal, Functions |
|
|
176
|
-
| Anthropic | Claude 3.5, Claude 3 | Text, Multimodal, Functions |
|
|
177
|
-
| Google | Gemini 2.0, Gemini 1.5 | Text, Multimodal |
|
|
178
|
-
| AWS Bedrock | Claude, Llama, Mistral | Text, Multimodal |
|
|
179
|
-
| Groq | Llama 3, Mixtral | Text, Fast Inference |
|
|
180
|
-
| xAI | Grok | Text |
|
|
181
|
-
| Cloudflare | Various | Text, Edge Deployment |
|
|
182
|
-
| Ollama | Local Models | Text, Privacy |
|
|
183
|
-
| OpenRouter | 100+ Models | Text, Aggregator |
|
|
173
|
+
Built on top of the [Vercel AI SDK](https://sdk.vercel.ai), with a small registry of pre-tuned agent prompts (research, summarization, citation answering, query resolution, knowledge-graph extraction, etc.) and tool wrappers around the [QwkSearch](https://qwksearch.com) API.
|
|
184
174
|
|
|
185
|
-
##
|
|
175
|
+
## Language Intelligence Providers
|
|
186
176
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
177
|
+
| Provider | 🌍 | Top Model (Others) | 🏆 Benchmarks | 📄 Docs | 🔑 Keys | 💰 Funding |
|
|
178
|
+
| ---------------------- | --- | --------------------------------------------- | --------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------- | ------------ |
|
|
179
|
+
| **Anthropic** | 🇺🇸 | Claude Mythos / Opus (Sonnet, Haiku) | 🥇 GPQA Diamond 94.6% · 🥇 SWE-bench 93.9% · 🧬 PhD reasoning | [Docs](https://docs.anthropic.com/en/docs/welcome) | [Keys](https://console.anthropic.com/settings/keys) | ~$60B |
|
|
180
|
+
| **OpenAI** | 🇺🇸 | GPT / o3 / Codex (o1, o4, o4-mini, gpt-4o) | 🥇 AIME 2025 100% · 🥇 SWE-bench Pro · 📚 MMLU-Pro 90% | [Docs](https://platform.openai.com/docs/overview) | [Keys](https://platform.openai.com/api-keys) | ~$180B |
|
|
181
|
+
| **Google** | 🇺🇸 | Gemini Pro (Flash, Flash-Lite, Gemma) | 🥇 GPQA 94.1% · 🥇 LiveCodeBench Elo 2439 · 🌐 #1 in 6/13 Vals | [Docs](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models) | [Keys](https://cloud.google.com/vertex-ai/generative-ai/docs/start/express-mode/overview#api-keys) | Public |
|
|
182
|
+
| **xAI** | 🇺🇸 | Grok Heavy (Grok-3, Grok Vision) | 🥇 AIME 2025 100% · 🧮 Math competition · ⚡ X integration | [Docs](https://docs.x.ai/docs#models) | [Keys](https://console.x.ai/) | ~$45B |
|
|
183
|
+
| **Meta** | 🇺🇸 | Llama Maverick / Scout (Llama 3.x, CodeLlama) | 🥇 DocVQA 94.4% · 🥇 10M token context · 📊 ChartQA 90% | [Docs](https://www.llama.com/docs/overview/) | [Keys](https://www.llama.com/llama-downloads/) | Public |
|
|
184
|
+
| **NVIDIA** | 🇺🇸 | Nemotron-Cascade (Llama Nemotron, Kimi) | 🥇 LCB v6 87.2% · 🏅 IMO+IOI+ICPC gold · 🧮 AIME 98.6% | [Docs](https://docs.api.nvidia.com/nim/reference/llm-apis) | [Keys](https://build.nvidia.com/settings/api-keys) | Public |
|
|
185
|
+
| **Perplexity** | 🇺🇸 | Sonar Reasoning Pro (Sonar Deep Research) | 🥇 Search Arena · 🔍 #1 web-grounded QA · 🌐 Real-time retrieval | [Docs](https://docs.perplexity.ai/models/model-cards) | [Keys](https://www.perplexity.ai/account/api/keys) | ~$1B |
|
|
186
|
+
| **Groq** | 🇺🇸 | (Llama, DeepSeek, Gemma, Mistral, Qwen) | ⚡ #1 inference speed · 🏎️ Fastest TTFT · 🔧 LPU hardware | [Docs](https://console.groq.com/docs/overview) | [Keys](https://console.groq.com/keys) | ~$640M |
|
|
187
|
+
| **Mistral** | 🇫🇷 | Mistral Large (Small 4, Codestral, Devstral) | 🥈 Arena Elo 1418 · 🌍 Multilingual MMLU 85.5% · 🚀 Fastest TTFT | [Docs](https://docs.mistral.ai/) | [Keys](https://console.mistral.ai/api-keys/) | ~$3.1B |
|
|
188
|
+
| **Together** | 🇺🇸 | (Llama, Mistral, Gemma, Qwen, DeepSeek) | 🏗️ Widest open hosting · 💸 Best open-source pricing · 🔧 Fine-tuning | [Docs](https://docs.together.ai/docs/quickstart) | [Keys](https://api.together.xyz/settings/api-keys) | ~$225M |
|
|
189
|
+
| **Moonshot** | 🇨🇳 | Kimi Reasoning (K2.6, K2) | 🥇 AIME open 96.1% · 🥇 MATH-500 98% · 🥇 HumanEval 99% | [Docs](https://platform.moonshot.cn/docs) | [Keys](https://platform.moonshot.cn/console/api-keys) | ~$3.9B |
|
|
190
|
+
| **Zhipu** | 🇨🇳 | GLM Reasoning / GLM-4.7 (GLM-4V, CogView) | 🥇 Chatbot Arena Elo 1451 · 🥇 MMLU 96% · 🧮 AIME 95.7% | [Docs](https://bigmodel.cn/dev/api) | [Keys](https://bigmodel.cn/usercenter/apikeys) | ~$1.8B |
|
|
191
|
+
| **Alibaba** | 🇨🇳 | Qwen-Coder / Qwen (Qwen-VL, Qwen-Audio) | 🥇 Codeforces Elo 2056 · 💻 SWE-bench 69.6% · 🏎️ LCB 70.7% | [Docs](https://www.alibabacloud.com/help/en/model-studio/developer-reference/use-qwen-by-calling-api) | [Keys](https://bailian.console.aliyun.com/?apiKey=1) | Public |
|
|
192
|
+
| **DeepSeek** | 🇨🇳 | DeepSeek (DeepSeek-Coder, DeepSeek-VL) | 🥇 IMO gold (open) · 📚 MMLU-Pro 81.2 · 🧮 AIME 87.5% | [Docs](https://api-docs.deepseek.com/) | [Keys](https://platform.deepseek.com/api_keys) | Bootstrapped |
|
|
193
|
+
| **Cloudflare** | 🇺🇸 | (Llama, Mistral, Gemma, Qwen, DeepSeek) | 🌐 Edge inference · ⚡ Serverless CDN scale · 🔒 Privacy-first | [Docs](https://developers.cloudflare.com/workers-ai/) | [Keys](https://dash.cloudflare.com/profile/api-tokens) | Public |
|
|
194
|
+
| **Ollama** | 🇺🇸 | (Llama, Mistral, Gemma, Qwen, DeepSeek) | 🖥️ #1 local inference · 🔒 Fully offline · 🆓 Free self-hosted | [Docs](https://ollama.com/docs) | [Keys](https://ollama.com/settings/keys) | ~$20M |
|
|
200
195
|
|
|
201
196
|
|
|
202
197
|
## Model Rank
|
|
@@ -208,7 +203,7 @@ CLOUDFLARE_API_TOKEN=...
|
|
|
208
203
|
| 2 |  |  | MiMo-V2.5 | Xiaomi | $0.28 | 1,048,576 | — | — | — | 2mo ago |
|
|
209
204
|
| 3* |  |  | MiniMax M3 | MiniMax | $1.20 | 1,048,576 | 44.4 | 58.6 | 35.4 | 1mo ago |
|
|
210
205
|
| 4* |  |  | GLM 5.2 | Z.ai | $2.856 | 1,048,576 | 51.1 | 68.8 | 43.1 | 2w ago |
|
|
211
|
-
| 5* |  |  | Hy3 preview | Tencent | $0.21 | 262,144 | — | — | — | 2mo ago |
|
|
206
|
+
| 5* |  |  | Hy3 preview | Tencent | $0.21 | 262,144 | — | — | — | 2mo ago |
|
|
212
207
|
| 6* |  |  | DeepSeek V4 Pro | DeepSeek | $0.87 | 1,048,576 | 44.3 | 59.4 | 36.4 | 2mo ago |
|
|
213
208
|
| 7 |  |  | Claude Opus 4.7 | Anthropic | $25 | 1,000,000 | 53.5 | 73.6 | 44.4 | 2mo ago |
|
|
214
209
|
| 8 |  |  | Claude Opus 4.8 | Anthropic | $25 | 1,000,000 | 55.7 | 74.3 | 47.2 | 1mo ago |
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { GenerateLanguageOptions, GenerateLanguageResult } from './generation-types';
|
|
2
|
+
export type { LLMProviderName, GenerateLanguageOptions, GenerateLanguageResult, } from './generation-types';
|
|
3
|
+
export { convertMarkdownToHTMLEscaped } from './utils/markdown-to-html';
|
|
4
|
+
/**
|
|
5
|
+
* ### Generate Language Response
|
|
6
|
+
* Writes a language response that shows human-like understanding of the
|
|
7
|
+
* question and context.
|
|
8
|
+
* - _Requires_: LLM provider, API key, agent name, and context variables.
|
|
9
|
+
* - _Providers_: groq, togetherai, openai, anthropic, xai, google,
|
|
10
|
+
* perplexity, cloudflare, nvidia
|
|
11
|
+
* - _Agent Templates_: custom local entries defined in AGENT_PROMPTS.
|
|
12
|
+
* - _How it Works_: Language models predict the most likely next token given
|
|
13
|
+
* a prompt. They represent words as high-dimensional vectors, use
|
|
14
|
+
* transformer attention across all prior tokens, and sample from the
|
|
15
|
+
* resulting probability distribution to produce human-like text.
|
|
16
|
+
*
|
|
17
|
+
* @see [Vercel AI SDK generateText docs](https://sdk.vercel.ai/docs/reference/ai-sdk-core/generate-text)
|
|
18
|
+
* @see [Hugging Face tutorials](https://huggingface.co/learn)
|
|
19
|
+
* @see [Illustrated Transformer](https://jalammar.github.io/illustrated-transformer/)
|
|
20
|
+
* @see [Building a Transformer with PyTorch](https://www.datacamp.com/tutorial/building-a-transformer-with-py-torch)
|
|
21
|
+
* @see [LLM training example](https://github.com/vtempest/ai-research-agent/blob/master/packages/neural-net/src/train/predict-next-word.js)
|
|
22
|
+
*
|
|
23
|
+
* @param options - Configuration for the language-model call
|
|
24
|
+
* @returns Resolved response object with `content`, optional `extract`, or `error`
|
|
25
|
+
* @author [Language Model Researchers](https://arc.net/folder/D0472A20-9C20-4D3F-B145-D2865C0A9FEE)
|
|
26
|
+
* @example
|
|
27
|
+
* const response = await writeLanguageResponse({
|
|
28
|
+
* query: "Explain neural networks",
|
|
29
|
+
* agent: "question",
|
|
30
|
+
* provider: "groq",
|
|
31
|
+
* apiKey: "your-api-key",
|
|
32
|
+
* });
|
|
33
|
+
*/
|
|
34
|
+
export declare function writeLanguageResponse(options?: GenerateLanguageOptions): Promise<GenerateLanguageResult>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module research/agents/generate-language-types
|
|
3
|
+
* @description Shared types for the generate-language module.
|
|
4
|
+
*/
|
|
5
|
+
/** Supported LLM provider identifiers */
|
|
6
|
+
export type LLMProviderName = "nvidia" | "openrouter" | "anthropic" | "google" | "openai" | "xai" | "groq" | "cloudflare" | "perplexity" | "amazon" | "bedrock" | "togetherai" | (string & {});
|
|
7
|
+
/**
|
|
8
|
+
* Configuration options for {@link writeLanguageResponse}.
|
|
9
|
+
*/
|
|
10
|
+
export interface GenerateLanguageOptions {
|
|
11
|
+
/** LLM provider to use */
|
|
12
|
+
provider: LLMProviderName;
|
|
13
|
+
/**
|
|
14
|
+
* API key for the provider.
|
|
15
|
+
* For `cloudflare`, use the `"apiToken:accountId"` format.
|
|
16
|
+
* For `amazon`/`bedrock`, use bearer token or `"region:accessKeyId:secretAccessKey"` format.
|
|
17
|
+
*/
|
|
18
|
+
apiKey?: string;
|
|
19
|
+
/** Agent prompt template name (default: `"question"`) */
|
|
20
|
+
agent?: string;
|
|
21
|
+
/** Specific model ID. Falls back to the provider's registered default. */
|
|
22
|
+
model?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Sampling temperature (0\u20132).
|
|
25
|
+
* Lower = more deterministic; higher = more creative. Default: `1`
|
|
26
|
+
*/
|
|
27
|
+
temperature?: number;
|
|
28
|
+
/** User query text */
|
|
29
|
+
query?: string;
|
|
30
|
+
/** Article or document text to process */
|
|
31
|
+
article?: string;
|
|
32
|
+
/** Prior conversation history for context-aware agents */
|
|
33
|
+
chat_history?: string;
|
|
34
|
+
/** Return `HTML` (`true`) or raw Markdown (`false`). Default: `true` */
|
|
35
|
+
html?: boolean;
|
|
36
|
+
/** Truncate the prompt to the model's context window length. Default: `true` */
|
|
37
|
+
applyContextLimit?: boolean;
|
|
38
|
+
/** Additional template variables forwarded to the agent prompt */
|
|
39
|
+
[key: string]: unknown;
|
|
40
|
+
}
|
|
41
|
+
/** Return value of {@link writeLanguageResponse} */
|
|
42
|
+
export interface GenerateLanguageResult {
|
|
43
|
+
/** Generated response in HTML or Markdown format */
|
|
44
|
+
content?: string;
|
|
45
|
+
/** Structured data extracted by the agent's `after` callback */
|
|
46
|
+
extract?: unknown;
|
|
47
|
+
/** Human-readable error message when generation fails */
|
|
48
|
+
error?: string;
|
|
49
|
+
}
|
|
50
|
+
/** Agent prompt template definition */
|
|
51
|
+
export interface AgentPrompt {
|
|
52
|
+
name: string;
|
|
53
|
+
/** Mustache-style template string with `{variableName}` placeholders */
|
|
54
|
+
template?: string;
|
|
55
|
+
prompt?: string;
|
|
56
|
+
/** Called before template substitution to pre-process the prompt */
|
|
57
|
+
before?: (prompt: string | undefined, options: GenerateLanguageOptions) => string;
|
|
58
|
+
/** Called after generation to extract structured data from the raw reply */
|
|
59
|
+
after?: (reply: string, options: GenerateLanguageOptions) => unknown;
|
|
60
|
+
/** Names of registered agent tools to attach to this agent */
|
|
61
|
+
tools?: string[];
|
|
62
|
+
}
|
|
63
|
+
/** A registered agent tool with a name, schema, and async handler */
|
|
64
|
+
export interface AgentTool {
|
|
65
|
+
name: string;
|
|
66
|
+
func: (...args: unknown[]) => unknown | Promise<unknown>;
|
|
67
|
+
[key: string]: unknown;
|
|
68
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Language Generation Module
|
|
3
|
+
*
|
|
4
|
+
* Centralized exports for AI language model response generation using Vercel AI SDK.
|
|
5
|
+
* Provides prompt templates, model registries, provider factories, and response
|
|
6
|
+
* generation functions for 10+ LLM providers.
|
|
7
|
+
*
|
|
8
|
+
* @module language-generation
|
|
9
|
+
* @author ai-research-agent contributors
|
|
10
|
+
*/
|
|
11
|
+
export { writeLanguageResponse, convertMarkdownToHTMLEscaped, } from './generate-response';
|
|
12
|
+
export type { LLMProviderName, GenerateLanguageOptions, GenerateLanguageResult, } from './generate-response';
|
|
13
|
+
export type { AgentPrompt, AgentTool, } from './generation-types';
|
|
14
|
+
export { AGENT_PROMPTS, extractJSONFromLanguageReply } from './prompt-templates';
|
|
15
|
+
export { LANGUAGE_MODELS, LANGUAGE_PROVIDERS, getModelsByProvider, getAllModels, getModelsByCapability, getTextOnlyModels, getMultimodalModels, } from './language-model-registry';
|
|
16
|
+
export type { ModelCapability, ModelInfo } from './language-model-registry';
|
|
17
|
+
export { createLLMProvider } from './provider-factory';
|
|
18
|
+
export * from './prompts';
|
|
19
|
+
export { AGENT_TOOLS } from './tools/qwksearch-api-tools';
|
|
20
|
+
export { convertMarkdownToHTMLEscaped as markdownToHTML } from './utils/markdown-to-html';
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List of default models for the chat providers and a list of models
|
|
3
|
+
* @property {string} provider - The provider name
|
|
4
|
+
* @property {string} docs - The documentation URL for the model
|
|
5
|
+
* @property {string} api_key - The API key url for the model
|
|
6
|
+
* @property {string} default - The default model for the chat provider
|
|
7
|
+
* @property {Object[]} models - The list of models available for the chat provider
|
|
8
|
+
* @category Generate
|
|
9
|
+
*/
|
|
10
|
+
export declare const LANGUAGE_MODELS: ({
|
|
11
|
+
provider: string;
|
|
12
|
+
docs: string;
|
|
13
|
+
api_key: string;
|
|
14
|
+
default: string;
|
|
15
|
+
models: {
|
|
16
|
+
name: string;
|
|
17
|
+
id: string;
|
|
18
|
+
contextLength: number;
|
|
19
|
+
}[];
|
|
20
|
+
} | {
|
|
21
|
+
provider: string;
|
|
22
|
+
docs: string;
|
|
23
|
+
api_key: string;
|
|
24
|
+
models: {
|
|
25
|
+
name: string;
|
|
26
|
+
id: string;
|
|
27
|
+
contextLength: number;
|
|
28
|
+
}[];
|
|
29
|
+
default?: undefined;
|
|
30
|
+
} | {
|
|
31
|
+
provider: string;
|
|
32
|
+
docs: string;
|
|
33
|
+
api_key: string;
|
|
34
|
+
default: string;
|
|
35
|
+
models: ({
|
|
36
|
+
name: string;
|
|
37
|
+
id: string;
|
|
38
|
+
contextLength: number;
|
|
39
|
+
provider: string;
|
|
40
|
+
type?: undefined;
|
|
41
|
+
} | {
|
|
42
|
+
name: string;
|
|
43
|
+
id: string;
|
|
44
|
+
contextLength: number;
|
|
45
|
+
provider: string;
|
|
46
|
+
type: string;
|
|
47
|
+
})[];
|
|
48
|
+
})[];
|
|
49
|
+
/** List of available LLM provider services */
|
|
50
|
+
export declare const LANGUAGE_PROVIDERS: string[];
|
|
51
|
+
/**
|
|
52
|
+
* Model capability types for filtering
|
|
53
|
+
*/
|
|
54
|
+
export type ModelCapability = "text" | "vision" | "audio" | "code" | "reasoning";
|
|
55
|
+
/**
|
|
56
|
+
* Extended model information with capabilities
|
|
57
|
+
*/
|
|
58
|
+
export interface ModelInfo {
|
|
59
|
+
name: string;
|
|
60
|
+
id: string;
|
|
61
|
+
contextLength: number;
|
|
62
|
+
capabilities?: ModelCapability[];
|
|
63
|
+
provider: string;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Get all models for a specific provider
|
|
67
|
+
* @param providerName - Name of the provider (case-insensitive)
|
|
68
|
+
* @returns Array of models for that provider
|
|
69
|
+
* @example
|
|
70
|
+
* const nvidiaModels = getModelsByProvider("nvidia");
|
|
71
|
+
*/
|
|
72
|
+
export declare function getModelsByProvider(providerName: string): ModelInfo[];
|
|
73
|
+
/**
|
|
74
|
+
* Get all available models across all providers
|
|
75
|
+
* @returns Array of all models with provider information
|
|
76
|
+
*/
|
|
77
|
+
export declare function getAllModels(): ModelInfo[];
|
|
78
|
+
/**
|
|
79
|
+
* Filter models by capability (text-only, vision, etc.)
|
|
80
|
+
* @param capability - The capability to filter by
|
|
81
|
+
* @param providerName - Optional: filter by specific provider
|
|
82
|
+
* @returns Array of models with the specified capability
|
|
83
|
+
* @example
|
|
84
|
+
* const textOnlyModels = getModelsByCapability("text");
|
|
85
|
+
* const visionModels = getModelsByCapability("vision", "openai");
|
|
86
|
+
*/
|
|
87
|
+
export declare function getModelsByCapability(capability: ModelCapability, providerName?: string): ModelInfo[];
|
|
88
|
+
/**
|
|
89
|
+
* Get text-only models (no vision, audio, etc.)
|
|
90
|
+
* @param providerName - Optional: filter by specific provider
|
|
91
|
+
* @returns Array of text-only models
|
|
92
|
+
* @example
|
|
93
|
+
* const textModels = getTextOnlyModels();
|
|
94
|
+
* const groqTextModels = getTextOnlyModels("groq");
|
|
95
|
+
*/
|
|
96
|
+
export declare function getTextOnlyModels(providerName?: string): ModelInfo[];
|
|
97
|
+
/**
|
|
98
|
+
* Get multimodal models (vision, audio, etc.)
|
|
99
|
+
* @param providerName - Optional: filter by specific provider
|
|
100
|
+
* @returns Array of multimodal models
|
|
101
|
+
* @example
|
|
102
|
+
* const multimodalModels = getMultimodalModels();
|
|
103
|
+
* const openaiMultimodal = getMultimodalModels("openai");
|
|
104
|
+
*/
|
|
105
|
+
export declare function getMultimodalModels(providerName?: string): ModelInfo[];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Prompt templates and extraction logic for various AI agents.
|
|
3
|
+
* Includes templates for research, summarization, query resolution, and more.
|
|
4
|
+
*/
|
|
5
|
+
export declare const AGENT_PROMPTS: ({
|
|
6
|
+
name: string;
|
|
7
|
+
template: string;
|
|
8
|
+
before?: undefined;
|
|
9
|
+
after?: undefined;
|
|
10
|
+
tools?: undefined;
|
|
11
|
+
} | {
|
|
12
|
+
name: string;
|
|
13
|
+
template: string;
|
|
14
|
+
before: (prompt: any, params: any) => any;
|
|
15
|
+
after: any;
|
|
16
|
+
tools?: undefined;
|
|
17
|
+
} | {
|
|
18
|
+
name: string;
|
|
19
|
+
template: string;
|
|
20
|
+
tools: string[];
|
|
21
|
+
after: any;
|
|
22
|
+
before?: undefined;
|
|
23
|
+
} | {
|
|
24
|
+
name: string;
|
|
25
|
+
template: string;
|
|
26
|
+
after: (content: any, options?: {}) => any;
|
|
27
|
+
before?: undefined;
|
|
28
|
+
tools?: undefined;
|
|
29
|
+
})[];
|
|
30
|
+
/**
|
|
31
|
+
* Extracts and cleans content between XML-style tags and returns a JSON object.
|
|
32
|
+
* @param {string} text - Input text to parse
|
|
33
|
+
* @param {string} [key='questions'] - Tag name to look for
|
|
34
|
+
* @category Generate
|
|
35
|
+
* @returns {Object[]} Array of objects containing cleaned content items
|
|
36
|
+
*/
|
|
37
|
+
export declare function extractJSONFromLanguageReply(text: any, key?: any): any;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { FewShotExample } from './meta-search-types';
|
|
2
|
+
export declare const webSearchRetrieverPrompt = "\nYou are an AI question rephraser. You will be given a conversation and a follow-up question, you will have to rephrase the follow up question so it is a standalone question and can be used by another LLM to search the web for information to answer it.\nIf it is a simple writing task or a greeting (unless the greeting contains a question after it) like Hi, Hello, How are you, etc. than a question then you need to return `not_needed` as the response (This is because the LLM won't need to search the web for finding information on this topic).\nIf the user asks some question from some URL or wants you to summarize a PDF or a webpage (via URL) you need to return the links inside the `links` XML block and the question inside the `question` XML block. If the user wants to you to summarize the webpage or the PDF you need to return `summarize` inside the `question` XML block in place of a question and the link to summarize in the `links` XML block.\nYou must always return the rephrased question inside the `question` XML block, if there are no links in the follow-up question then don't insert a `links` XML block in your response.\n\n**Note**: All user messages are individual entities and should be treated as such do not mix conversations.\n";
|
|
3
|
+
export declare const webSearchRetrieverFewShots: FewShotExample[];
|
|
4
|
+
export declare const webSearchResponsePrompt = "\n You are QwkSearch, an AI model skilled in web search and crafting detailed, engaging, and well-structured answers. You excel at summarizing web pages and extracting relevant information to create professional, blog-style responses.\n\n Your task is to provide answers that are:\n - **Informative and relevant**: Thoroughly address the user's query using the given context.\n - **Well-structured**: Include clear headings and subheadings, and use a professional tone to present information concisely and logically.\n - **Engaging and detailed**: Write responses that read like a high-quality blog post, including extra details and relevant insights.\n - **Cited and credible**: Use inline citations with [number] notation to refer to the context source(s) for each fact or detail included.\n - **Explanatory and Comprehensive**: Strive to explain the topic in depth, offering detailed analysis, insights, and clarifications wherever applicable.\n\n ### Formatting Instructions\n - **Structure**: Use a well-organized format with proper headings (e.g., \"## Example heading 1\" or \"## Example heading 2\"). Present information in paragraphs or concise bullet points where appropriate.\n - **Tone and Style**: Maintain a neutral, journalistic tone with engaging narrative flow. Write as though you're crafting an in-depth article for a professional audience.\n - **Markdown Usage**: Format your response with Markdown for clarity. Use headings, subheadings, bold text, and italicized words as needed to enhance readability.\n - **Length and Depth**: Provide comprehensive coverage of the topic. Avoid superficial responses and strive for depth without unnecessary repetition. Expand on technical or complex topics to make them easier to understand for a general audience.\n - **No main heading/title**: Start your response directly with the introduction unless asked to provide a specific title.\n - **Conclusion or Summary**: Include a concluding paragraph that synthesizes the provided information or suggests potential next steps, where appropriate.\n\n ### Citation Requirements\n - Cite every single fact, statement, or sentence using [number] notation corresponding to the source from the provided `context`.\n - Integrate citations naturally at the end of sentences or clauses as appropriate. For example, \"The Eiffel Tower is one of the most visited landmarks in the world[1].\"\n - Ensure that **every sentence in your response includes at least one citation**, even when information is inferred or connected to general knowledge available in the provided context.\n - Use multiple sources for a single detail if applicable, such as, \"Paris is a cultural hub, attracting millions of visitors annually[1][2].\"\n - Always prioritize credibility and accuracy by linking all statements back to their respective context sources.\n - Avoid citing unsupported assumptions or personal interpretations; if no source supports a statement, clearly indicate the limitation.\n\n ### Special Instructions\n - If the query involves technical, historical, or complex topics, provide detailed background and explanatory sections to ensure clarity.\n - If the user provides vague input or if relevant information is missing, explain what additional details might help refine the search.\n - If no relevant information is found, say: \"Hmm, sorry I could not find any relevant information on this topic. Would you like me to search again or ask something else?\" Be transparent about limitations and suggest alternatives or ways to reframe the query.\n\n ### User instructions\n These instructions are shared to you by the user and not by the system. You will have to follow them but give them less priority than the above instructions. If the user has provided specific instructions or preferences, incorporate them into your response while adhering to the overall guidelines.\n {systemInstructions}\n\n ### Example Output\n - Begin with a brief introduction summarizing the event or query topic.\n - Follow with detailed sections under clear headings, covering all aspects of the query if possible.\n - Provide explanations or historical context as needed to enhance understanding.\n - End with a conclusion or overall perspective if relevant.\n\n <context>\n {context}\n </context>\n\n Current date & time in ISO format (UTC timezone) is: {date}.\n";
|
|
5
|
+
export declare const writingAssistantPrompt = "\nYou are QwkSearch, an AI model who is expert at searching the web and answering user's queries. You are currently set on focus mode 'Writing Assistant', this means you will be helping the user write a response to a given query.\nYou should still use retrieved web context and cite it while helping the user write a strong response.\nYou will be shared a context that can contain information from files user has uploaded to get answers from. You will have to generate answers upon that.\n\nYou have to cite the answer using [number] notation. You must cite the sentences with their relevent context number. You must cite each and every part of the answer so the user can know where the information is coming from.\nPlace these citations at the end of that particular sentence. You can cite the same sentence multiple times if it is relevant to the user's query like [number1][number2].\nHowever you do not need to cite it using the same number. You can use different numbers to cite the same sentence multiple times. The number refers to the number of the search result (passed in the context) used to generate that part of the answer.\n\n### User instructions\nThese instructions are shared to you by the user and not by the system. You will have to follow them but give them less priority than the above instructions. If the user has provided specific instructions or preferences, incorporate them into your response while adhering to the overall guidelines.\n{systemInstructions}\n\n<context>\n{context}\n</context>\n";
|
|
6
|
+
declare const _default: {
|
|
7
|
+
webSearchResponsePrompt: string;
|
|
8
|
+
webSearchRetrieverPrompt: string;
|
|
9
|
+
webSearchRetrieverFewShots: FewShotExample[];
|
|
10
|
+
writingAssistantPrompt: string;
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { LanguageModel } from 'ai';
|
|
2
|
+
/**
|
|
3
|
+
* Instantiates the appropriate Vercel AI SDK language model for the given provider.
|
|
4
|
+
*
|
|
5
|
+
* @param provider - Normalised (lowercase) provider name
|
|
6
|
+
* @param apiKey - Provider API key
|
|
7
|
+
* @param model - Model ID to use
|
|
8
|
+
* @param _temperature - Unused here; temperature is passed to generateText at call time
|
|
9
|
+
* @returns A LanguageModel instance, or `null` for an unrecognised provider
|
|
10
|
+
*/
|
|
11
|
+
export declare function createLLMProvider(provider: string, apiKey: string, model: string, _temperature: number): LanguageModel | null;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* List of tools available for agent usage, including their schemas and implementation.
|
|
4
|
+
*/
|
|
5
|
+
export declare const AGENT_TOOLS: ({
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
schema: z.ZodObject<{
|
|
9
|
+
query: z.ZodString;
|
|
10
|
+
category: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
11
|
+
general: "general";
|
|
12
|
+
news: "news";
|
|
13
|
+
videos: "videos";
|
|
14
|
+
images: "images";
|
|
15
|
+
science: "science";
|
|
16
|
+
files: "files";
|
|
17
|
+
it: "it";
|
|
18
|
+
}>>>;
|
|
19
|
+
recency: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
20
|
+
none: "none";
|
|
21
|
+
day: "day";
|
|
22
|
+
week: "week";
|
|
23
|
+
month: "month";
|
|
24
|
+
year: "year";
|
|
25
|
+
}>>>;
|
|
26
|
+
page: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
27
|
+
language: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
28
|
+
public: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
29
|
+
timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
30
|
+
baseURL: z.ZodOptional<z.ZodString>;
|
|
31
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
32
|
+
}, z.core.$strip>;
|
|
33
|
+
func: ({ query, category, recency, page, language, public: isPublic, timeout, baseURL, apiKey }: {
|
|
34
|
+
query: any;
|
|
35
|
+
category?: string;
|
|
36
|
+
recency?: string;
|
|
37
|
+
page?: number;
|
|
38
|
+
language?: string;
|
|
39
|
+
public?: boolean;
|
|
40
|
+
timeout?: number;
|
|
41
|
+
baseURL: any;
|
|
42
|
+
apiKey: any;
|
|
43
|
+
}) => Promise<string>;
|
|
44
|
+
} | {
|
|
45
|
+
name: string;
|
|
46
|
+
description: string;
|
|
47
|
+
schema: z.ZodObject<{
|
|
48
|
+
url: z.ZodString;
|
|
49
|
+
images: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
50
|
+
links: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
51
|
+
formatting: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
52
|
+
absoluteURLs: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
53
|
+
timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
54
|
+
baseURL: z.ZodOptional<z.ZodString>;
|
|
55
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
56
|
+
}, z.core.$strip>;
|
|
57
|
+
func: ({ url, images, links, formatting, absoluteURLs, timeout, baseURL, apiKey }: {
|
|
58
|
+
url: any;
|
|
59
|
+
images?: boolean;
|
|
60
|
+
links?: boolean;
|
|
61
|
+
formatting?: boolean;
|
|
62
|
+
absoluteURLs?: boolean;
|
|
63
|
+
timeout?: number;
|
|
64
|
+
baseURL: any;
|
|
65
|
+
apiKey: any;
|
|
66
|
+
}) => Promise<string>;
|
|
67
|
+
} | {
|
|
68
|
+
name: string;
|
|
69
|
+
description: string;
|
|
70
|
+
schema: z.ZodObject<{
|
|
71
|
+
provider: z.ZodEnum<{
|
|
72
|
+
groq: "groq";
|
|
73
|
+
openai: "openai";
|
|
74
|
+
anthropic: "anthropic";
|
|
75
|
+
together: "together";
|
|
76
|
+
xai: "xai";
|
|
77
|
+
google: "google";
|
|
78
|
+
perplexity: "perplexity";
|
|
79
|
+
cloudflare: "cloudflare";
|
|
80
|
+
}>;
|
|
81
|
+
key: z.ZodOptional<z.ZodString>;
|
|
82
|
+
agent: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
83
|
+
question: "question";
|
|
84
|
+
"summarize-bullets": "summarize-bullets";
|
|
85
|
+
summarize: "summarize";
|
|
86
|
+
"suggest-followups": "suggest-followups";
|
|
87
|
+
"answer-cite-sources": "answer-cite-sources";
|
|
88
|
+
"query-resolution": "query-resolution";
|
|
89
|
+
"knowledge-graph-nodes": "knowledge-graph-nodes";
|
|
90
|
+
"summary-longtext": "summary-longtext";
|
|
91
|
+
}>>>;
|
|
92
|
+
model: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
93
|
+
temperature: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
94
|
+
html: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
95
|
+
query: z.ZodOptional<z.ZodString>;
|
|
96
|
+
chat_history: z.ZodOptional<z.ZodString>;
|
|
97
|
+
article: z.ZodOptional<z.ZodString>;
|
|
98
|
+
baseURL: z.ZodOptional<z.ZodString>;
|
|
99
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
100
|
+
}, z.core.$strip>;
|
|
101
|
+
func: ({ provider, key, agent, model, temperature, html, query, chat_history, article, baseURL, apiKey }: {
|
|
102
|
+
provider: any;
|
|
103
|
+
key: any;
|
|
104
|
+
agent?: string;
|
|
105
|
+
model?: string;
|
|
106
|
+
temperature?: number;
|
|
107
|
+
html?: boolean;
|
|
108
|
+
query: any;
|
|
109
|
+
chat_history: any;
|
|
110
|
+
article: any;
|
|
111
|
+
baseURL: any;
|
|
112
|
+
apiKey: any;
|
|
113
|
+
}) => Promise<string>;
|
|
114
|
+
} | {
|
|
115
|
+
name: string;
|
|
116
|
+
description: string;
|
|
117
|
+
schema: z.ZodObject<{
|
|
118
|
+
url: z.ZodString;
|
|
119
|
+
blockImages: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
120
|
+
wait: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
121
|
+
timeout: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
122
|
+
waitUntil: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
123
|
+
domcontentloaded: "domcontentloaded";
|
|
124
|
+
load: "load";
|
|
125
|
+
networkidle0: "networkidle0";
|
|
126
|
+
networkidle2: "networkidle2";
|
|
127
|
+
}>>>;
|
|
128
|
+
bypassCaptcha: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
129
|
+
sessionId: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
130
|
+
format: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
131
|
+
html: "html";
|
|
132
|
+
json: "json";
|
|
133
|
+
}>>>;
|
|
134
|
+
scraperUrl: z.ZodOptional<z.ZodString>;
|
|
135
|
+
scraperApiKey: z.ZodOptional<z.ZodString>;
|
|
136
|
+
}, z.core.$strip>;
|
|
137
|
+
func: ({ url, blockImages, wait, timeout, waitUntil, bypassCaptcha, sessionId, format, scraperUrl, scraperApiKey }: {
|
|
138
|
+
url: any;
|
|
139
|
+
blockImages?: boolean;
|
|
140
|
+
wait?: number;
|
|
141
|
+
timeout?: number;
|
|
142
|
+
waitUntil?: string;
|
|
143
|
+
bypassCaptcha?: boolean;
|
|
144
|
+
sessionId?: string;
|
|
145
|
+
format?: string;
|
|
146
|
+
scraperUrl: any;
|
|
147
|
+
scraperApiKey: any;
|
|
148
|
+
}) => Promise<string>;
|
|
149
|
+
})[];
|
package/dist/types.d.ts
ADDED