Skip to content

Commit addb5af

Browse files
fix: biome lint ignore for OpenRouter API extraBody any type
1 parent c54f243 commit addb5af

File tree

7 files changed

+206
-240
lines changed

7 files changed

+206
-240
lines changed

.DS_Store

2 KB
Binary file not shown.

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,71 @@ The server exposes MCP tools for:
2727
- Removing indexed documents (`remove_docs`).
2828
- Fetching single URLs (`fetch_url`): Fetches a URL and returns its content as Markdown.
2929

30+
## 🆕 OpenRouter API 集成与多模型支持
31+
32+
### Chat/Completions 功能
33+
34+
本服务已全面适配 OpenRouter API,支持主流大模型(GPT-4.1、Claude 3.7、Gemini 2.5、Grok、Qwen 等),并支持多模态输入(文本+图片)。
35+
36+
#### 主要特性
37+
- ✅ 支持 OpenRouter 官方所有主流模型,模型列表见 `src/utils/openrouter.ts``OPENROUTER_MODELS`
38+
- ✅ 支持多模态消息格式(如 text、image_url)
39+
- ✅ 支持自定义 HTTP-Referer、X-Title 等 header,便于 openrouter.ai 统计和排名
40+
- ✅ 支持 OpenRouter API 的所有扩展参数(如 stream、tools、temperature、max_tokens 等)
41+
42+
#### 环境变量配置
43+
- `OPENAI_API_KEY`:OpenRouter API Key(必填)
44+
- `OPENAI_API_BASE`:OpenRouter API Base,推荐 `https://openrouter.ai/api/v1`
45+
- `MODEL_ID`:默认模型(如 `openai/gpt-4.1`),可选
46+
47+
#### 示例代码
48+
49+
```typescript
50+
import { openrouterChat } from './src/utils/openrouter';
51+
52+
const messages = [
53+
{
54+
role: 'user',
55+
content: [
56+
{ type: 'text', text: 'What is in this image?' },
57+
{ type: 'image_url', image_url: { url: 'https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg' } }
58+
]
59+
}
60+
];
61+
62+
const result = await openrouterChat({
63+
model: 'openai/gpt-4.1',
64+
messages,
65+
referer: 'https://your-site.com', // 可选
66+
xTitle: 'Your Site Name' // 可选
67+
// 还可加 extraBody, headers 等参数
68+
});
69+
console.log(result);
70+
```
71+
72+
#### 支持的主流模型(部分示例)
73+
- openai/gpt-4.1
74+
- openai/gpt-4.1-mini
75+
- anthropic/claude-3.7-sonnet
76+
- google/gemini-2.5-pro-preview-03-25
77+
- x-ai/grok-3-beta
78+
- qwen/qwen2.5-vl-32b-instruct:free
79+
- deepseek/deepseek-chat-v3-0324:free
80+
- thudm/glm-z1-32b:free
81+
- openrouter/auto
82+
- ...(详见源码 OPENROUTER_MODELS)
83+
84+
#### 更多 API 参数
85+
如需支持流式输出、函数调用、system prompt、stop、temperature、max_tokens 等 OpenRouter API 参数,只需通过 `extraBody` 字段传递即可,无需修改底层代码。
86+
87+
## ⚠️ Embedding 功能说明
88+
89+
> **Embedding 功能已禁用!**
90+
>
91+
> 本项目当前版本已彻底移除所有 embedding 相关实现和依赖,不再支持向量生成与检索。所有 embedding 相关 API 均会直接抛出异常提示。
92+
>
93+
> 仅保留全文检索与大模型 chat/completions 能力。
94+
3095
## Configuration
3196

3297
The following environment variables are supported to configure the embedding model behavior:

package-lock.json

Lines changed: 83 additions & 52 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"@langchain/core": "^0.3.49",
4141
"@langchain/google-genai": "^0.2.3",
4242
"@langchain/google-vertexai": "^0.2.4",
43-
"@langchain/openai": "^0.5.0",
4443
"@modelcontextprotocol/sdk": "^1.6.1",
4544
"axios": "^1.8.3",
4645
"axios-retry": "^4.5.0",

src/store/DocumentStore.ts

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -185,43 +185,10 @@ export class DocumentStore {
185185
}
186186

187187
/**
188-
* Initializes embeddings client using environment variables for configuration.
189-
*
190-
* The embedding model is configured using DOCS_MCP_EMBEDDING_MODEL environment variable.
191-
* Format: "provider:model_name" (e.g., "google:text-embedding-004") or just "model_name"
192-
* for OpenAI (default).
193-
*
194-
* Supported providers and their required environment variables:
195-
* - openai: OPENAI_API_KEY (and optionally OPENAI_API_BASE, OPENAI_ORG_ID)
196-
* - google: GOOGLE_APPLICATION_CREDENTIALS (path to service account JSON)
197-
* - aws: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION (or BEDROCK_AWS_REGION)
198-
* - microsoft: Azure OpenAI credentials (AZURE_OPENAI_API_*)
188+
* Embedding 已禁用,无需初始化 embedding
199189
*/
200-
private async initializeEmbeddings(): Promise<void> {
201-
const modelSpec = process.env.DOCS_MCP_EMBEDDING_MODEL || "text-embedding-3-small";
202-
203-
// Import dynamically to avoid circular dependencies
204-
const { createEmbeddingModel } = await import("./embeddings/EmbeddingFactory");
205-
this.embeddings = createEmbeddingModel(modelSpec);
206-
207-
// Determine the model's actual dimension by embedding a test string
208-
const testVector = await this.embeddings.embedQuery("test");
209-
this.modelDimension = testVector.length;
210-
211-
if (this.modelDimension > this.dbDimension) {
212-
throw new DimensionError(modelSpec, this.modelDimension, this.dbDimension);
213-
}
214-
}
215-
216-
/**
217-
* Escapes a query string for use with SQLite FTS5 MATCH operator.
218-
* Wraps the query in double quotes and escapes internal double quotes.
219-
*/
220-
private escapeFtsQuery(query: string): string {
221-
// Escape internal double quotes by doubling them
222-
const escapedQuotes = query.replace(/"/g, '""');
223-
// Wrap the entire string in double quotes
224-
return `"${escapedQuotes}"`;
190+
async initializeEmbeddings(): Promise<void> {
191+
throw new Error("Embedding functionality has been disabled in this build.");
225192
}
226193

227194
/**

0 commit comments

Comments
 (0)