Skip to content

Commit 8224439

Browse files
committed
docs: x-provider
1 parent 27a36a9 commit 8224439

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

packages/x-sdk/src/x-request/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export interface XRequestOptions<
4747
/**
4848
* @description The parameters to be sent
4949
*/
50-
params?: Input;
50+
params?: Partial<Input>;
5151
/**
5252
* @description The custom headers to be sent
5353
*/

packages/x/docs/x-sdk/demos/chat-providers/custom-provider-width-ui.tsx

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { BubbleListProps } from '@ant-design/x';
22
import { Bubble, Sender } from '@ant-design/x';
3-
import { AbstractChatProvider, useXChat, XRequest } from '@ant-design/x-sdk';
3+
import { AbstractChatProvider, useXChat, XRequest, XRequestOptions } from '@ant-design/x-sdk';
44
import { Button, Flex } from 'antd';
55
import React from 'react';
66

@@ -9,7 +9,8 @@ import React from 'react';
99
interface CustomInput {
1010
query: string;
1111
role: 'user';
12-
stream?: boolean;
12+
stream: boolean;
13+
model: string;
1314
}
1415

1516
interface CustomOutput {
@@ -30,14 +31,14 @@ class CustomProvider<
3031
> extends AbstractChatProvider<ChatMessage, Input, Output> {
3132
// 转换请求参数:将用户输入转换为标准格式
3233
// Transform request parameters: convert user input to standard format
33-
transformParams(requestParams: Partial<Input>): Input {
34+
35+
transformParams(requestParams: Partial<Input>, options: XRequestOptions<Input, Output>): Input {
3436
if (typeof requestParams !== 'object') {
3537
throw new Error('requestParams must be an object');
3638
}
3739
return {
38-
query: requestParams.query || '',
39-
role: 'user',
40-
stream: requestParams.stream ?? false,
40+
...(options?.params || {}),
41+
...(requestParams || {}),
4142
} as Input;
4243
}
4344

@@ -146,6 +147,10 @@ const App = () => {
146147
new CustomProvider<CustomMessage, CustomInput, CustomOutput>({
147148
request: XRequest('https://api.x.ant.design/api/custom_chat_provider_stream', {
148149
manual: true,
150+
params: {
151+
stream: true,
152+
model: 'qwen2.5-7b-instruct',
153+
},
149154
}),
150155
}),
151156
);

0 commit comments

Comments
 (0)