Skip to content

Commit

Permalink
chore: bump versions
Browse files Browse the repository at this point in the history
  • Loading branch information
dingyi222666 committed Jun 3, 2024
1 parent 550b24a commit da3585e
Show file tree
Hide file tree
Showing 23 changed files with 240 additions and 27 deletions.
2 changes: 1 addition & 1 deletion packages/bard-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
"peerDependencies": {
"koishi": "^4.17.0",
"koishi-plugin-chatluna": "^1.0.0-beta.51"
"koishi-plugin-chatluna": "^1.0.0-beta.52"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/chatglm-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
},
"peerDependencies": {
"koishi": "^4.17.0",
"koishi-plugin-chatluna": "^1.0.0-beta.51"
"koishi-plugin-chatluna": "^1.0.0-beta.52"
},
"engines": {
"node": ">=18.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/claude-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
"peerDependencies": {
"koishi": "^4.17.0",
"koishi-plugin-chatluna": "^1.0.0-beta.51"
"koishi-plugin-chatluna": "^1.0.0-beta.52"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/claude2-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"peerDependencies": {
"koishi": "^4.17.0",
"koishi-plugin-chatluna": "^1.0.0-beta.51"
"koishi-plugin-chatluna": "^1.0.0-beta.52"
},
"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.0.0-beta.51",
"version": "1.0.0-beta.52",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/embeddings-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"peerDependencies": {
"koishi": "^4.17.0",
"koishi-plugin-chatluna": "^1.0.0-beta.51"
"koishi-plugin-chatluna": "^1.0.0-beta.52"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/gemini-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
},
"peerDependencies": {
"koishi": "^4.17.0",
"koishi-plugin-chatluna": "^1.0.0-beta.51"
"koishi-plugin-chatluna": "^1.0.0-beta.52"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/gptfree-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"peerDependencies": {
"koishi": "^4.17.0",
"koishi-plugin-chatluna": "^1.0.0-beta.51"
"koishi-plugin-chatluna": "^1.0.0-beta.52"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/newbing-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
},
"peerDependencies": {
"koishi": "^4.17.0",
"koishi-plugin-chatluna": "^1.0.0-beta.51"
"koishi-plugin-chatluna": "^1.0.0-beta.52"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/ollama-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"peerDependencies": {
"koishi": "^4.17.0",
"koishi-plugin-chatluna": "^1.0.0-beta.51"
"koishi-plugin-chatluna": "^1.0.0-beta.52"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/openai-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
"peerDependencies": {
"koishi": "^4.17.0",
"koishi-plugin-chatluna": "^1.0.0-beta.51"
"koishi-plugin-chatluna": "^1.0.0-beta.52"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/openai-like-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
"peerDependencies": {
"koishi": "^4.17.0",
"koishi-plugin-chatluna": "^1.0.0-beta.51"
"koishi-plugin-chatluna": "^1.0.0-beta.52"
},
"koishi": {
"description": {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"peerDependencies": {
"koishi": "^4.17.0",
"koishi-plugin-chatluna": "^1.0.0-beta.51"
"koishi-plugin-chatluna": "^1.0.0-beta.52"
},
"koishi": {
"description": {
Expand Down
8 changes: 5 additions & 3 deletions packages/qwen-adapter/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-plugin-chatluna-qwen-adapter",
"description": "qwen adapter for chatluna",
"version": "1.0.0-beta.16",
"version": "1.0.0-beta.17",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"files": [
Expand Down Expand Up @@ -36,15 +36,17 @@
"adapter"
],
"dependencies": {
"@langchain/core": "^0.2.5"
"@langchain/core": "^0.2.5",
"zod": "^3.24.0-canary.20240523T174819",
"zod-to-json-schema": "^3.23.0"
},
"devDependencies": {
"atsc": "^2.0.1",
"koishi": "^4.17.7"
},
"peerDependencies": {
"koishi": "^4.17.0",
"koishi-plugin-chatluna": "^1.0.0-beta.51"
"koishi-plugin-chatluna": "^1.0.0-beta.52"
},
"koishi": {
"description": {
Expand Down
173 changes: 169 additions & 4 deletions packages/qwen-adapter/src/requester.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import { ToolCallChunk } from '@langchain/core/dist/messages/tool'
import {
AIMessageChunk,
BaseMessageChunk,
ChatMessageChunk,
FunctionMessageChunk,
HumanMessageChunk,
SystemMessageChunk,
ToolMessageChunk
} from '@langchain/core/messages'
import { ChatGenerationChunk } from '@langchain/core/outputs'
import {
EmbeddingsRequester,
Expand All @@ -21,6 +31,7 @@ import {
} from './types'
import {
convertDeltaToMessageChunk,
formatToolsToQWenTools,
langchainMessageToQWenMessage
} from './utils'

Expand All @@ -47,6 +58,10 @@ export class QWenRequester
messages: langchainMessageToQWenMessage(params.input)
},
parameters: {
tools:
params.tools != null
? formatToolsToQWenTools(params.tools)
: undefined,
result_format: 'message',
top_p: params.topP,
temperature: params.temperature,
Expand All @@ -58,12 +73,17 @@ export class QWenRequester
}
)

const findTools = params.tools != null

const iterator = sseIterable(response)

const defaultRole: ChatCompletionResponseMessageRoleEnum =
'assistant'
// TODO: function calling with incremental response
// let lastMessageChunk: BaseMessageChunk

let lastMessageChunk: BaseMessageChunk = new ChatMessageChunk({
content: '',
role: defaultRole
})

for await (const event of iterator) {
const chunk = event.data
Expand Down Expand Up @@ -101,18 +121,32 @@ export class QWenRequester
continue
}

const messageChunk = convertDeltaToMessageChunk(
let messageChunk = convertDeltaToMessageChunk(
choice,
defaultRole
)

const generationChunk = new ChatGenerationChunk({
let generationChunk = new ChatGenerationChunk({
message: messageChunk,
text: messageChunk.content as string
})

if (findTools) {
messageChunk = this._diffChunk(
messageChunk,
lastMessageChunk
)

generationChunk = new ChatGenerationChunk({
message: messageChunk,
text: messageChunk.content as string
})
}

yield generationChunk

lastMessageChunk = messageChunk

if (data.output.choices[0]?.finish_reason === 'stop') {
break
}
Expand Down Expand Up @@ -219,4 +253,135 @@ export class QWenRequester
async init(): Promise<void> {}

async dispose(): Promise<void> {}

private _diffChunk(
messageChunk: BaseMessageChunk,
baseMessageChunk: BaseMessageChunk
) {
// diff content

// maybe the function is not incremental
// just change the content
const cloned = cloneMessageChunk(messageChunk)

if (messageChunk.content !== baseMessageChunk.content) {
const diffContent = messageChunk.content.slice(
baseMessageChunk.content.length
)

cloned.content = diffContent
}

if (cloned instanceof AIMessageChunk) {
cloned.tool_call_chunks = this._diffToolCallChunks(
(baseMessageChunk as AIMessageChunk).tool_call_chunks,
(messageChunk as AIMessageChunk).tool_call_chunks
)
// cloned.tool_calls = []
return new AIMessageChunk({
...cloned
})
}

cloned.additional_kwargs.tool_calls = []

return cloned
}

private _diffToolCallChunks(
baseToolCallChunks: ToolCallChunk[],
additionalToolCallChunks: ToolCallChunk[]
) {
const cloned: ToolCallChunk[] = []
for (let i = 0; i < additionalToolCallChunks.length; i++) {
const baseToolCall = baseToolCallChunks?.[i]
const additionalToolCall = additionalToolCallChunks[i]

if (baseToolCall == null) {
cloned.push(additionalToolCall)
} else {
cloned.push(
this._diffToolCallChunk(baseToolCall, additionalToolCall)
)
}
}

return cloned
}

private _diffToolCallChunk(
baseToolCall: ToolCallChunk,
additionalToolCall: ToolCallChunk
) {
const cloned: ToolCallChunk = {
...baseToolCall
}

if (additionalToolCall.name !== baseToolCall.name) {
cloned.name = additionalToolCall.name.slice(
baseToolCall.name?.length ?? 0
)
}

if (additionalToolCall.id !== baseToolCall.id) {
cloned.id = additionalToolCall.id.slice(
baseToolCall.id?.length ?? 0
)
}

if (additionalToolCall.args !== baseToolCall.args) {
cloned.args = additionalToolCall.args.slice(
baseToolCall.args?.length ?? 0
)
}

return cloned
}
}

function cloneMessageChunk(messageChunk: BaseMessageChunk) {
const content = messageChunk.content
const additional_kwargs = messageChunk.additional_kwargs

Check warning on line 344 in packages/qwen-adapter/src/requester.ts

View workflow job for this annotation

GitHub Actions / lint

Variable name `additional_kwargs` must match one of the following formats: camelCase, UPPER_CASE, PascalCase
const name = messageChunk.name

if (messageChunk instanceof AIMessageChunk) {
return new AIMessageChunk({
content,
additional_kwargs,
name,
tool_call_chunks: messageChunk.tool_call_chunks
})
} else if (messageChunk instanceof HumanMessageChunk) {
return new HumanMessageChunk({
content,
additional_kwargs,
name
})
} else if (messageChunk instanceof SystemMessageChunk) {
return new SystemMessageChunk({
content,
additional_kwargs,
name
})
} else if (messageChunk instanceof FunctionMessageChunk) {
return new FunctionMessageChunk({
content,
additional_kwargs,
name
})
} else if (messageChunk instanceof ToolMessageChunk) {
return new ToolMessageChunk({
content,
additional_kwargs,
name,
tool_call_id: messageChunk.tool_call_id
})
} else {
return new ChatMessageChunk({
content,
additional_kwargs,
name,
role: messageChunk._getType()
})
}
}
21 changes: 21 additions & 0 deletions packages/qwen-adapter/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@ export type ChatCompletionResponseMessageRoleEnum =
| 'function'
| 'tool'

export interface ChatCompletionFunction {
name: string
description?: string
// eslint-disable-next-line @typescript-eslint/no-explicit-any
parameters?: { [key: string]: any }
}

export interface ChatCompletionTool {
type: string
function: ChatCompletionFunction
}

export interface ChatCompletionRequestMessageToolCall {
id: string
type: 'function'
function: {
name: string
arguments: string
}
}

/**
*
* @export
Expand Down
Loading

0 comments on commit da3585e

Please sign in to comment.