@tansy/ai-openai-compatible 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +12 -2
- package/index.d.ts +11 -0
- package/index.js +38 -0
- package/package.json +29 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mohamed Salah
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
<!-- Generated by scripts/package-metadata.mjs. Change that script, not this file. -->
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
# @tansy/ai-openai-compatible
|
|
4
|
+
|
|
5
|
+
Any OpenAI-compatible server (Ollama, LM Studio, vLLM, OpenRouter, Together) for @tansy/ai.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @tansy/ai-openai-compatible
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Add it to `tansy.config.ts`. See [the ai plugin documentation](https://github.com/mhmdsalahsebai/tansy/blob/main/docs/plugins/ai.md) for what it adds and the options it takes.
|
|
12
|
+
|
|
13
|
+
A first-party plugin for [tansy](https://github.com/mhmdsalahsebai/tansy), a self-hosted, runtime-schema CMS for Next.js. MIT licensed.
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The base address, also when someone pasted the chat endpoint itself, such as https://openrouter.ai/api/v1/chat/completions. */
|
|
2
|
+
export declare const baseUrlOf: (value: unknown) => string;
|
|
3
|
+
/**
|
|
4
|
+
* Any server that speaks OpenAI's chat API: Ollama, LM Studio, vLLM, OpenRouter, Together,
|
|
5
|
+
* Fireworks, a self-hosted model. Its address is a setting, so only people who may change
|
|
6
|
+
* settings choose where prompts, and the content in them, are sent.
|
|
7
|
+
*/
|
|
8
|
+
export declare const openaiCompatible: (options?: {
|
|
9
|
+
defaultModel?: string;
|
|
10
|
+
baseUrl?: string;
|
|
11
|
+
}) => import("@tansy/ai/provider").AiProvider;
|
package/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
2
|
+
import { chatImageModel, defineAiProvider, openAiModels, str } from "@tansy/ai/provider";
|
|
3
|
+
/** The base address, also when someone pasted the chat endpoint itself, such as https://openrouter.ai/api/v1/chat/completions. */
|
|
4
|
+
export const baseUrlOf = (value) => str(value).replace(/\/+$/, "").replace(/\/(chat\/completions|completions|models)$/, "");
|
|
5
|
+
/**
|
|
6
|
+
* Any server that speaks OpenAI's chat API: Ollama, LM Studio, vLLM, OpenRouter, Together,
|
|
7
|
+
* Fireworks, a self-hosted model. Its address is a setting, so only people who may change
|
|
8
|
+
* settings choose where prompts, and the content in them, are sent.
|
|
9
|
+
*/
|
|
10
|
+
export const openaiCompatible = (options = {}) => defineAiProvider({
|
|
11
|
+
id: "compatible",
|
|
12
|
+
label: "OpenAI-compatible server",
|
|
13
|
+
defaultModel: options.defaultModel ?? "",
|
|
14
|
+
// Its settings in other interface languages. English is each setting's own label and description.
|
|
15
|
+
messages: {
|
|
16
|
+
ar: {
|
|
17
|
+
settings: {
|
|
18
|
+
compatibleBaseUrl: {
|
|
19
|
+
label: "عنوان الخادم",
|
|
20
|
+
description: "العنوان الأساسي للـ API، منتهيًا بـ /v1، مثل http://localhost:11434/v1 لـ Ollama أو https://openrouter.ai/api/v1."
|
|
21
|
+
},
|
|
22
|
+
compatibleApiKey: {
|
|
23
|
+
label: "مفتاح API",
|
|
24
|
+
description: "اتركه فارغًا لخادم لا يحتاج مفتاحًا، مثل Ollama على هذا الجهاز."
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
settings: () => [
|
|
30
|
+
{ name: "compatibleBaseUrl", type: "text", default: options.baseUrl ?? "", maxLength: 500, label: "Server address", description: "The API's base address, ending in /v1, such as http://localhost:11434/v1 for Ollama or https://openrouter.ai/api/v1." },
|
|
31
|
+
{ name: "compatibleApiKey", type: "secret", env: "OPENAI_COMPATIBLE_API_KEY", label: "API key", description: "Leave empty for a server that needs none, such as Ollama on this machine." },
|
|
32
|
+
],
|
|
33
|
+
ready: (settings) => /^https?:\/\/\S+$/.test(str(settings.compatibleBaseUrl)),
|
|
34
|
+
model: (settings, modelId) => createOpenAICompatible({ name: "compatible", baseURL: baseUrlOf(settings.compatibleBaseUrl), apiKey: str(settings.compatibleApiKey) || undefined })(modelId),
|
|
35
|
+
// Servers that draw pictures answer through the chat API with the "image" modality, as OpenRouter does.
|
|
36
|
+
imageModel: (settings, modelId) => chatImageModel({ provider: "compatible", baseUrl: baseUrlOf(settings.compatibleBaseUrl), apiKey: str(settings.compatibleApiKey), modelId }),
|
|
37
|
+
models: (settings) => openAiModels(baseUrlOf(settings.compatibleBaseUrl), str(settings.compatibleApiKey) || undefined),
|
|
38
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tansy/ai-openai-compatible",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Any OpenAI-compatible server (Ollama, LM Studio, vLLM, OpenRouter, Together) for @tansy/ai.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"tansy",
|
|
7
|
+
"tansy-ai-provider"
|
|
8
|
+
],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"author": "Mohamed Salah <mohamedsalahsebai@gmail.com>",
|
|
11
|
+
"homepage": "https://github.com/mhmdsalahsebai/tansy",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/mhmdsalahsebai/tansy.git",
|
|
15
|
+
"directory": "plugins/ai-openai-compatible"
|
|
16
|
+
},
|
|
17
|
+
"bugs": "https://github.com/mhmdsalahsebai/tansy/issues",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./index.d.ts",
|
|
21
|
+
"default": "./index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@tansy/ai": "^0.1.0",
|
|
26
|
+
"tansy": "^0.1.0"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@ai-sdk/openai-compatible": "^3.0.92"
|
|
30
|
+
}
|
|
31
|
+
}
|