qwen.js 0.1.1 → 0.1.3
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/dist/client.d.ts +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +25 -4
- package/dist/tools.test.d.ts +1 -0
- package/dist/types.d.ts +32 -2
- package/package.json +1 -1
package/dist/client.d.ts
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { QwenClient } from "./client";
|
|
2
2
|
export { generatePKCE, requestDeviceCode, pollForToken, refreshAccessToken, isTokenExpired, } from "./auth";
|
|
3
|
-
export type { QwenConfig, ChatMessage, ChatOptions, ChatResponse, ChatSession, StreamChunk, TokenState, DeviceCodeResponse, TokenResponse, PKCEPair, } from "./types";
|
|
3
|
+
export type { QwenConfig, ChatMessage, ChatOptions, ChatResponse, ChatSession, StreamChunk, TokenState, DeviceCodeResponse, TokenResponse, PKCEPair, Tool, ToolCall, ToolResult, } from "./types";
|
|
4
4
|
import { QwenClient } from "./client";
|
|
5
5
|
export declare function createQwen(config?: {
|
|
6
6
|
accessToken?: string;
|
package/dist/index.js
CHANGED
|
@@ -175,22 +175,36 @@ ${url}
|
|
|
175
175
|
return response;
|
|
176
176
|
}
|
|
177
177
|
async chat(messages, options) {
|
|
178
|
-
const
|
|
178
|
+
const body = {
|
|
179
179
|
model: options?.model ?? this.model,
|
|
180
180
|
messages,
|
|
181
181
|
temperature: options?.temperature,
|
|
182
182
|
stream: false
|
|
183
|
-
}
|
|
183
|
+
};
|
|
184
|
+
if (options?.tools) {
|
|
185
|
+
body.tools = options.tools;
|
|
186
|
+
}
|
|
187
|
+
if (options?.tool_choice) {
|
|
188
|
+
body.tool_choice = options.tool_choice;
|
|
189
|
+
}
|
|
190
|
+
const response = await this.request("/chat/completions", body);
|
|
184
191
|
return response.json();
|
|
185
192
|
}
|
|
186
193
|
async* chatStream(messages, options) {
|
|
187
194
|
const msgs = typeof messages === "string" ? [{ role: "user", content: messages }] : messages;
|
|
188
|
-
const
|
|
195
|
+
const body = {
|
|
189
196
|
model: options?.model ?? this.model,
|
|
190
197
|
messages: msgs,
|
|
191
198
|
temperature: options?.temperature,
|
|
192
199
|
stream: true
|
|
193
|
-
}
|
|
200
|
+
};
|
|
201
|
+
if (options?.tools) {
|
|
202
|
+
body.tools = options.tools;
|
|
203
|
+
}
|
|
204
|
+
if (options?.tool_choice) {
|
|
205
|
+
body.tool_choice = options.tool_choice;
|
|
206
|
+
}
|
|
207
|
+
const response = await this.request("/chat/completions", body);
|
|
194
208
|
const reader = response.body?.getReader();
|
|
195
209
|
if (!reader)
|
|
196
210
|
throw new Error("No response body");
|
|
@@ -234,6 +248,13 @@ ${url}
|
|
|
234
248
|
getModel() {
|
|
235
249
|
return this.model;
|
|
236
250
|
}
|
|
251
|
+
createToolResult(toolCallId, content) {
|
|
252
|
+
return {
|
|
253
|
+
role: "tool",
|
|
254
|
+
content,
|
|
255
|
+
tool_call_id: toolCallId
|
|
256
|
+
};
|
|
257
|
+
}
|
|
237
258
|
}
|
|
238
259
|
// src/index.ts
|
|
239
260
|
function createQwen(config) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types.d.ts
CHANGED
|
@@ -4,13 +4,22 @@ export interface QwenConfig {
|
|
|
4
4
|
model?: string;
|
|
5
5
|
}
|
|
6
6
|
export interface ChatMessage {
|
|
7
|
-
role: "system" | "user" | "assistant";
|
|
8
|
-
content: string;
|
|
7
|
+
role: "system" | "user" | "assistant" | "tool";
|
|
8
|
+
content: string | null;
|
|
9
|
+
tool_calls?: ToolCall[];
|
|
10
|
+
tool_call_id?: string;
|
|
9
11
|
}
|
|
10
12
|
export interface ChatOptions {
|
|
11
13
|
model?: string;
|
|
12
14
|
temperature?: number;
|
|
13
15
|
stream?: boolean;
|
|
16
|
+
tools?: Tool[];
|
|
17
|
+
tool_choice?: "none" | "auto" | {
|
|
18
|
+
type: "function";
|
|
19
|
+
function: {
|
|
20
|
+
name: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
14
23
|
}
|
|
15
24
|
export interface DeviceCodeResponse {
|
|
16
25
|
device_code: string;
|
|
@@ -51,6 +60,26 @@ export interface ChatResponse {
|
|
|
51
60
|
total_tokens: number;
|
|
52
61
|
};
|
|
53
62
|
}
|
|
63
|
+
export interface Tool {
|
|
64
|
+
type: "function";
|
|
65
|
+
function: {
|
|
66
|
+
name: string;
|
|
67
|
+
description: string;
|
|
68
|
+
parameters: Record<string, any>;
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
export interface ToolCall {
|
|
72
|
+
id: string;
|
|
73
|
+
type: "function";
|
|
74
|
+
function: {
|
|
75
|
+
name: string;
|
|
76
|
+
arguments: string;
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export interface ToolResult {
|
|
80
|
+
tool_call_id: string;
|
|
81
|
+
content: string;
|
|
82
|
+
}
|
|
54
83
|
export interface StreamChunk {
|
|
55
84
|
id?: string;
|
|
56
85
|
object?: string;
|
|
@@ -61,6 +90,7 @@ export interface StreamChunk {
|
|
|
61
90
|
delta: {
|
|
62
91
|
role?: string;
|
|
63
92
|
content?: string;
|
|
93
|
+
tool_calls?: ToolCall[];
|
|
64
94
|
};
|
|
65
95
|
finish_reason?: string | null;
|
|
66
96
|
}[];
|