Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/adapter-gemini/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-plugin-chatluna-google-gemini-adapter",
"description": "google-gemini adapter for chatluna",
"version": "1.3.28",
"version": "1.3.29",
"main": "lib/index.cjs",
"module": "lib/index.mjs",
"typings": "lib/index.d.ts",
Expand Down
14 changes: 14 additions & 0 deletions packages/adapter-gemini/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ export const Config: Schema<Config> = Schema.intersect([
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}) as any

export const usage = `
## Gemini 适配器说明

在 apiKeys 配置中填入你的 Gemini API Key 和 API 请求地址。

**如果你没有可用的 Gemini 格式 API,请前往以下地址注册:**

[https://api.bltcy.ai/register](https://api.bltcy.ai/register?aff=ec5e312997)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The new usage documentation includes a hardcoded affiliate link. While this might be intentional, it's generally better to avoid embedding affiliate links directly in the source code to maintain neutrality and avoid potential user trust issues. Consider removing the affiliate query parameter (?aff=...) or making it configurable if this is part of a partnership.

Suggested change
[https://api.bltcy.ai/register](https://api.bltcy.ai/register?aff=ec5e312997)
[https://api.bltcy.ai/register](https://api.bltcy.ai/register)


完成后记得填写:
- API Key:从注册的账号中复制
- API 请求地址:\`https://api.bltcy.ai/v1beta\`
`

export const inject = {
required: ['chatluna'],
optional: ['chatluna_storage']
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-openai-like/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-plugin-chatluna-openai-like-adapter",
"description": "openai style api adapter for chatluna",
"version": "1.3.9",
"version": "1.3.10",
"main": "lib/index.cjs",
"module": "lib/index.mjs",
"typings": "lib/index.d.ts",
Expand Down
14 changes: 14 additions & 0 deletions packages/adapter-openai-like/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,20 @@ export const Config: Schema<Config> = Schema.intersect([
'en-US': require('./locales/en-US.schema.yml')
}) as Schema<Config>

export const usage = `
## OpenAI 兼容格式适配器说明

在 apiKeys 配置中填入你的 OpenAI 兼容格式 API Key 和 API 请求地址。

**如果你没有可用的 OpenAI 格式 API,请前往以下地址注册:**

[https://api.bltcy.ai/register](https://api.bltcy.ai/register?aff=ec5e312997)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The new usage documentation includes a hardcoded affiliate link. While this might be intentional, it's generally better to avoid embedding affiliate links directly in the source code to maintain neutrality and avoid potential user trust issues. Consider removing the affiliate query parameter (?aff=...) or making it configurable if this is part of a partnership.

Suggested change
[https://api.bltcy.ai/register](https://api.bltcy.ai/register?aff=ec5e312997)
[https://api.bltcy.ai/register](https://api.bltcy.ai/register)


完成后记得填写:
- API Key:从注册的账号中复制
- API 请求地址:\`https://api.bltcy.ai/v1\`
`

export const inject = ['chatluna']

export const name = 'chatluna-openai-like-adapter'
2 changes: 1 addition & 1 deletion packages/adapter-openai/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-plugin-chatluna-openai-adapter",
"description": "openai adapter for chatluna",
"version": "1.3.8",
"version": "1.3.9",
"main": "lib/index.cjs",
"module": "lib/index.mjs",
"typings": "lib/index.d.ts",
Expand Down
14 changes: 14 additions & 0 deletions packages/adapter-openai/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ export const Config: Schema<Config> = Schema.intersect([
// eslint-disable-next-line @typescript-eslint/no-explicit-any
}) as any

export const usage = `
## OpenAI 适配器说明

在 apiKeys 配置中填入你的 OpenAI API Key 和 API 请求地址。

**如果你没有可用的 OpenAI 格式 API,请前往以下地址注册:**

[https://api.bltcy.ai/register](https://api.bltcy.ai/register?aff=ec5e312997)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The new usage documentation includes a hardcoded affiliate link. While this might be intentional, it's generally better to avoid embedding affiliate links directly in the source code to maintain neutrality and avoid potential user trust issues. Consider removing the affiliate query parameter (?aff=...) or making it configurable if this is part of a partnership.

Suggested change
[https://api.bltcy.ai/register](https://api.bltcy.ai/register?aff=ec5e312997)
[https://api.bltcy.ai/register](https://api.bltcy.ai/register)


完成后记得填写:
- API Key:从注册的账号中复制
- API 请求地址:\`https://api.bltcy.ai/v1\`
`

export const inject = ['chatluna']

export const name = 'chatluna-openai-adapter'
2 changes: 1 addition & 1 deletion packages/adapter-spark/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-plugin-chatluna-spark-adapter",
"description": "spark adapter for chatluna",
"version": "1.3.6",
"version": "1.3.7",
"main": "lib/index.cjs",
"module": "lib/index.mjs",
"typings": "lib/index.d.ts",
Expand Down
38 changes: 18 additions & 20 deletions packages/adapter-spark/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Context } from 'koishi'
import { PlatformModelClient } from 'koishi-plugin-chatluna/llm-core/platform/client'
import { ChatLunaChatModel } from 'koishi-plugin-chatluna/llm-core/platform/model'
import {
ModelCapabilities,
ModelInfo,
ModelType
} from 'koishi-plugin-chatluna/llm-core/platform/types'
Expand All @@ -14,6 +13,7 @@ import { Config, logger } from '.'
import { SparkRequester } from './requester'
import { SparkClientConfig } from './types'
import { ChatLunaPlugin } from 'koishi-plugin-chatluna/services/chat'
import { hasSparkModelPassword, sparkModelCatalog } from './utils'

export class SparkClient extends PlatformModelClient<SparkClientConfig> {
platform = 'spark'
Expand All @@ -23,7 +23,7 @@ export class SparkClient extends PlatformModelClient<SparkClientConfig> {
constructor(
ctx: Context,
private _config: Config,
public plugin: ChatLunaPlugin<SparkClientConfig>
public plugin: ChatLunaPlugin<SparkClientConfig, Config>
) {
super(ctx, plugin.platformConfigPool)

Expand All @@ -36,28 +36,26 @@ export class SparkClient extends PlatformModelClient<SparkClientConfig> {
}

async refreshModels(): Promise<ModelInfo[]> {
const rawModels = [
['spark-lite', 8192],
['spark-pro', 8192],
['spark-pro-128k', 128000],
['spark-max', 8192],
['spark-max-32k', 32768],
['spark-4.0-ultra', 128000],
['spark-x1.5', 128000]
] as [string, number][]
const configs = this.configPool.getConfigs()
const result: SparkModelInfo[] = []

for (const [model, maxTokens] of rawModels) {
for (const definition of sparkModelCatalog) {
const hasPassword = configs.some((config) => {
return hasSparkModelPassword(
config.value.apiPasswords,
definition.name
)
})

if (!hasPassword) {
continue
}

result.push({
name: model,
maxTokens,
name: definition.name,
maxTokens: definition.maxTokens,
type: ModelType.llm,
capabilities: [
(model.startsWith('spark-max') ||
model.startsWith('spark-4.0-ultra') ||
model === 'spark-x1.5') &&
ModelCapabilities.ToolCall
]
capabilities: definition.capabilities
})
}

Expand Down
61 changes: 57 additions & 4 deletions packages/adapter-spark/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ import { ChatLunaPlugin } from 'koishi-plugin-chatluna/services/chat'
import { SparkClient } from './client'
import { SparkClientConfig } from './types'
import { createLogger } from 'koishi-plugin-chatluna/utils/logger'
import {
defaultSparkAppConfig,
hasSparkModelPassword,
sparkModelCatalog
} from './utils'

export let logger: Logger

Expand All @@ -17,7 +22,13 @@ export function apply(ctx: Context, config: Config) {

plugin.parseConfig((config) => {
return config.appConfigs
.filter((apiKeys) => apiKeys.enabled !== false)
.filter(
(apiKeys) =>
apiKeys.enabled !== false &&
sparkModelCatalog.some((model) => {
return hasSparkModelPassword(apiKeys, model.name)
})
)
.map((apiKeys) => {
return {
apiKey: undefined,
Expand Down Expand Up @@ -47,9 +58,11 @@ export interface Config extends ChatLunaPlugin.Config {
export const Config: Schema<Config> = Schema.intersect([
ChatLunaPlugin.Config,
Schema.object({
appConfigs: Schema.array(Schema.dict(String).default({}).role('table'))

.default([])
appConfigs: Schema.array(
Schema.dict(String)
.default({ ...defaultSparkAppConfig })
.role('table')
).default([{ ...defaultSparkAppConfig }])
}),
Schema.object({
maxContextRatio: Schema.number()
Expand All @@ -65,6 +78,46 @@ export const Config: Schema<Config> = Schema.intersect([
'en-US': require('./locales/en-US.schema.yml')
}) as Schema<Config>

export const usage = `
## 讯飞星火适配器填写说明

**appConfigs 配置说明:**
- 每一行都是一组独立的模型密码配置
- 左边填写模型别名,右边填写该模型在讯飞控制台里对应的 APIPassword
- 只有填写了非空密码的模型,才会出现在 ChatLuna 的模型列表里

### 模型别名与讯飞控制台的对应关系

访问 https://console.xfyun.cn/services/bm4 进入星火调试中心,在下方服务列表中找到对应模型,点进去复制 APIPassword。

| ChatLuna 模型别名 | 讯飞控制台模型名称 | 说明 |
|-----------------|-----------------|------|
| spark-lite | Spark Lite | 免费模型,响应速度快 |
| spark-pro | Spark Pro | 强性能模型,速度快效果好 |
| spark-pro-128k | Spark Pro-128K | Pro 的 128K 长文本版本 |
| spark-max | Spark Max | 性能最强的基础模型 |
| spark-max-32k | Spark Max-32K | Max 的 32K 长文本版本 |
| spark-4.0-ultra | Spark Ultra-32K | 高性价比模型,指令跟随和文本生成能力强 |
| spark-x1.5 | Spark X1.5 | 支持快慢思考自主决策,语言理解和任务规划能力显著提升 |
| spark-x2 | Spark X2 | 最新发布性能最强的深度推理模型,数学、推理、语言理解、智能体等方向效果重点提升 |

### 怎么填

1. 进入 https://console.xfyun.cn/services/bm4 找到你要用的模型,复制 APIPassword。
2. 在 appConfigs 中找到对应的模型别名,填入密码。
3. 如果配置里没有,就自己添加(参考上面表格)。
4. 只有填写密码的模型才会显示。

### 升级说明

从旧版本升级到此版本,需要重新安装适配器。

### 文档参考

- 常规 HTTP 文档:https://www.xfyun.cn/doc/spark/HTTP调用文档.html#_1-接口说明
- X1.5 / X2 HTTP 文档:https://www.xfyun.cn/doc/spark/X1http.html#_2、请求示例
`

export const inject = ['chatluna']

export const name = 'chatluna-spark-adapter'
6 changes: 4 additions & 2 deletions packages/adapter-spark/src/locales/en-US.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ $inner:
- {}
- $desc: 'API Configuration'
appConfigs:
$desc: 'iFLYTEK Spark platform config (API Password)'
$desc: 'iFLYTEK Spark model-password mapping. The table is prefilled with `spark-lite`, `spark-pro`, `spark-pro-128k`, `spark-max`, `spark-max-32k`, `spark-4.0-ultra`, `spark-x1.5`, and `spark-x2`. A model is shown only after its password is filled.'
$inner:
- 'API Password for new OpenAI-compatible HTTP API (optional)'
key: 'Spark model alias'
value: 'API Password for the mapped Spark model (optional)'
assistants:
$desc: 'Spark assistant config (name, API link). Note: Use one API Key per assistant'
$inner:
Expand All @@ -13,3 +14,4 @@ $inner:

- $desc: 'Model Parameters'
maxContextRatio: 'Maximum context usage ratio (0-1). Controls the maximum percentage of model context window available for use. For example, 0.35 means at most 35% of the model context can be used.'
temperature: 'Response temperature. Higher values make outputs more random.'
29 changes: 15 additions & 14 deletions packages/adapter-spark/src/locales/zh-CN.schema.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
$inner:
- {}
- $desc: 请求设置
appConfigs:
$desc: 讯飞星火平台配置 (ModelID, API Password),不同的模型需要使用不同的 API 密钥。
$inner:
- 讯飞星火的 API Password(可选)。
assistants:
$desc: 讯飞星火助手配置 (名称, API 链接)。注意:如使用星火助手,请勿在上方配置多个 API Key,仅填入与星火助手绑定的应用 API Key,否则可能导致无法找到相关助手。
$inner:
- 讯飞星火助手的名称。
- 讯飞星火助手的链接。
- {}
- $desc: 请求设置
appConfigs:
$desc: 讯飞星火平台配置(模型别名, API Password)。表格会预填 `spark-lite`、`spark-pro`、`spark-pro-128k`、`spark-max`、`spark-max-32k`、`spark-4.0-ultra`、`spark-x1.5`、`spark-x2`,填写对应密码后才会显示并启用对应模型。
$inner:
key: 讯飞星火的模型别名
value: 讯飞星火对应模型的 API Password(可选)
assistants:
$desc: 讯飞星火助手配置 (名称, API 链接)。注意:如使用星火助手,请勿在上方配置多个 API Key,仅填入与星火助手绑定的应用 API Key,否则可能导致无法找到相关助手。
$inner:
- 讯飞星火助手的名称。
- 讯飞星火助手的链接。

- $desc: 模型设置
maxContextRatio: 最大上下文使用比例(0~1),控制可用的模型上下文窗口大小的最大百分比。例如 0.35 表示最多使用模型上下文的 35%。
temperature: 回复温度,数值越高随机性越强。
- $desc: 模型设置
maxContextRatio: 最大上下文使用比例(0~1),控制可用的模型上下文窗口大小的最大百分比。例如 0.35 表示最多使用模型上下文的 35%。
temperature: 回复温度,数值越高随机性越强。
Loading
Loading