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-azure-openai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.3.0-alpha.54"
"koishi-plugin-chatluna": "^1.3.0-alpha.55"
},
"resolutions": {
"@langchain/core": "0.3.62",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-claude/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.3.0-alpha.54"
"koishi-plugin-chatluna": "^1.3.0-alpha.55"
},
"resolutions": {
"@langchain/core": "0.3.62",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-deepseek/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.3.0-alpha.54"
"koishi-plugin-chatluna": "^1.3.0-alpha.55"
},
"koishi": {
"category": "ai",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-dify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.3.0-alpha.54"
"koishi-plugin-chatluna": "^1.3.0-alpha.55"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-doubao/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.3.0-alpha.54"
"koishi-plugin-chatluna": "^1.3.0-alpha.55"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-gemini/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.3.0-alpha.54",
"koishi-plugin-chatluna": "^1.3.0-alpha.55",
"koishi-plugin-chatluna-storage-service": "^0.0.9"
},
"peerDependenciesMeta": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-hunyuan/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.3.0-alpha.54"
"koishi-plugin-chatluna": "^1.3.0-alpha.55"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-ollama/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.3.0-alpha.54"
"koishi-plugin-chatluna": "^1.3.0-alpha.55"
},
"resolutions": {
"@langchain/core": "0.3.62",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-openai-like/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.3.0-alpha.54"
"koishi-plugin-chatluna": "^1.3.0-alpha.55"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-openai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.3.0-alpha.54"
"koishi-plugin-chatluna": "^1.3.0-alpha.55"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-qwen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.3.0-alpha.54"
"koishi-plugin-chatluna": "^1.3.0-alpha.55"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-rwkv/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.3.0-alpha.54"
"koishi-plugin-chatluna": "^1.3.0-alpha.55"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-spark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.3.0-alpha.54"
"koishi-plugin-chatluna": "^1.3.0-alpha.55"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-wenxin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.3.0-alpha.54"
"koishi-plugin-chatluna": "^1.3.0-alpha.55"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-zhipu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.3.0-alpha.54"
"koishi-plugin-chatluna": "^1.3.0-alpha.55"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-plugin-chatluna",
"description": "chatluna for koishi",
"version": "1.3.0-alpha.54",
"version": "1.3.0-alpha.55",
"main": "lib/index.cjs",
"module": "lib/index.mjs",
"typings": "lib/index.d.ts",
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface Config {
sendThinkingMessageTimeout: number
showThoughtMessage: boolean
splitMessage: boolean
blackList: Computed<Awaitable<boolean>>
blackList: Computed<Awaitable<number>>
censor: boolean
autoDelete: boolean
autoDeleteTimeout: number
Expand Down Expand Up @@ -99,9 +99,9 @@ export const Config: Schema<Config> = Schema.intersect([
}),

Schema.object({
blackList: Schema.computed(Schema.boolean().default(false)).default(
false
)
blackList: Schema.computed(
Schema.number().min(0).max(1).step(1).default(0)
).default(0)
Comment thread
dingyi222666 marked this conversation as resolved.
}),

Schema.object({
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/llm-core/chain/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,16 @@ Your goal is to craft an insightful, engaging response that seamlessly integrate
usedTokens += messageTokens
}

if (usedTokens > this.sendTokenLimit) {
logger?.warn(
`After system prompts, the max tokens exceeded: ${usedTokens} > ${this.sendTokenLimit}. Try increasing the adapter token limit or optimizing the system prompts.`
)
}

const inputTokens = await this.tokenCounter(
getMessageContent(input.content)
)

const longHistory = (variables?.['long_memory'] ?? []) as Document[]
const knowledge = (variables?.['knowledge'] ?? []) as Document[]
const otherDocuments = (variables?.['documents'] ?? []) as Document[][]
Expand All @@ -191,6 +198,7 @@ Your goal is to craft an insightful, engaging response that seamlessly integrate
authorsNote && (authorsNote.content?.length ?? 0) > 0
? await this._counterAuthorsNote(authorsNote, variables)
: [null, 0]

usedTokens += inputTokens

if (usedTokensAuthorsNote > 0) {
Expand Down Expand Up @@ -382,6 +390,9 @@ Your goal is to craft an insightful, engaging response that seamlessly integrate
usedTokens + messageTokens >
this.sendTokenLimit - (documents.length > 0 ? 480 : 80)
) {
logger?.warn(
`Exceeded token limit (${usedTokens} + ${messageTokens} > ${this.sendTokenLimit}) of the message placeholder`
)
break
}

Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/llm-core/platform/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { chunkArray } from 'koishi-plugin-chatluna/llm-core/utils/chunk'
import { encodingForModel } from '../utils/tiktoken'
import { formatFunctionDefinitions } from '../utils/function_def'
import { getMessageContent } from 'koishi-plugin-chatluna/utils/string'
import { logger } from 'koishi-plugin-chatluna'

export interface ChatLunaModelCallOptions extends BaseChatModelCallOptions {
model?: string
Expand Down Expand Up @@ -434,6 +435,10 @@ export class ChatLunaChatModel extends BaseChatModel<ChatLunaModelCallOptions> {
const messageTokens = await this._countMessageTokens(message)

if (totalTokens + messageTokens > maxTokenLimit) {
logger?.warn(
// eslint-disable-next-line max-len
`Message length exceeds token limit. ${totalTokens + messageTokens} > ${maxTokenLimit}. Try increasing the adapter token limit or reducing the message length.`
)
break
}

Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/llm-core/vectorstores/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export abstract class ChatLunaSaveableVectorStore<
)
)

await this.save()

return ids
}

Expand All @@ -90,6 +92,7 @@ export abstract class ChatLunaSaveableVectorStore<

if (options.deleteAll) {
await this._docstore.delete({ deleteAll: true })
await this.save()
return
}

Expand All @@ -113,6 +116,8 @@ export abstract class ChatLunaSaveableVectorStore<
if (!ids || ids.length === 0) return

await this._docstore.delete({ ids })
Comment thread
dingyi222666 marked this conversation as resolved.

await this.save()
}

_vectorstoreType(): string {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/locales/en-US.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $inner:
streamResponse: 'Enable stream response. Initiates message sending during reply generation. Note: Disables rendering output mode and incompatible with plugin mode.'

- $desc: Blacklist Management
blackList: Configure blacklist. Use cautiously to avoid unintended blocking.
blackList: Configure blacklist. Use cautiously to avoid unintended blocking. The number 1 indicates enabled blacklist. Set to zero value to unenable blacklist.
blockText: Set fixed reply for blacklisted users.

- $desc: History Management
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/locales/zh-CN.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $inner:

- $desc: 黑名单选项
blackList:
$desc: 设置黑名单列表。请谨慎使用,只对需要拉黑的用户或群启用。错误配置可能导致所有聊天被拉黑而无法响应
$desc: 设置黑名单列表。请谨慎使用,只对需要拉黑的用户或群启用。1 表示启用黑名单,0 表示不启用黑名单。默认值为 0
blockText: 设置对被拉黑用户的固定回复内容。

- $desc: 历史记录选项
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/middlewares/auth/black_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function apply(ctx: Context, config: Config, chain: ChatChain) {
.middleware('black_list', async (session, context) => {
const resolved = await session.resolve(config.blackList)

if (resolved === true) {
if (resolved === 1) {
logger.debug(
`[黑名单] ${session.username}(${session.userId}): ${session.content}`
)
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/middlewares/system/wipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function apply(ctx: Context, config: Config, chain: ChatChain) {
}

try {
await fs.rm('data/chathub/temp', { recursive: true })
await fs.rm('data/chatluna/temp', { recursive: true })
} catch (e) {
logger.warn(`wipe: ${e}`)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/services/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ export class ChatLunaService extends Service {
private _createTempDir() {
// create dir data/chathub/temp use fs
// ?
const tempPath = path.resolve(this.ctx.baseDir, 'data/chathub/temp')
const tempPath = path.resolve(this.ctx.baseDir, 'data/chatluna/temp')
if (!fs.existsSync(tempPath)) {
fs.mkdirSync(tempPath, { recursive: true })
}
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-long-memory/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.3.0-alpha.54"
"koishi-plugin-chatluna": "^1.3.0-alpha.55"
},
"resolutions": {
"@langchain/core": "0.3.62",
Expand Down
4 changes: 2 additions & 2 deletions packages/extension-mcp/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-plugin-chatluna-mcp-client",
"description": "MCP Client for ChatLuna",
"version": "1.3.0-alpha.6",
"version": "1.3.0-alpha.7",
"main": "lib/index.cjs",
"module": "lib/index.mjs",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -59,7 +59,7 @@
},
"peerDependencies": {
"koishi": "^4.18.9",
"koishi-plugin-chatluna": "^1.3.0-alpha.54",
"koishi-plugin-chatluna": "^1.3.0-alpha.55",
"koishi-plugin-chatluna-storage-service": "^0.0.9"
},
"peerDependenciesMeta": {
Expand Down
Loading
Loading