ant-design / ant-design/pro-chat

👑 [需求] 添加ChatGPT主动发消息的功能

Open
#43 8 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
897
Forks
116
PR merge metrics
No merged PRs in 30d

Description

### 🥰 需求描述
遇到一个需求:用户不主动对ChatGPT发送消息,需要程序去请求ChatGPT,然后将返回的消息显示到消息列表中;
也就是说,需要ChatGPT主动发送消息给用户,而不是用户发送消息给ChatGPT后ChatGPT再回复。

### 🧐 解决方案
所以我去翻了文档,没有找到添加ChatGPT的消息到消息列表的方法,只找到了用来给ChatGPT发送消息的Ref实例上的sendMessage方法。
或许可以添加一个与sendMessage类似的方法“GPTSendMessage”

参数可以和组件Props上的request一致,是一个async函数,内部拿到这个函数就可以像调用request函数的方法一样进行调用,最终渲染一条ChatGPT的消息,比如:
```typescript
chatRef.current.GPTSendMessage(async () => {
// 在这里发起请求 获取到ChatGPT的响应
// 然后把响应数据返回
const mockedData: string = `这是一段模拟的流式字符串数据。`;
const mockResponse = new MockResponse(mockedData, 50);
return mockResponse.getResponse();
});
```
调用后的效果图:
![image](https://github.com/ant-design/pro-chat/assets/40377409/5b9b8b09-acbc-4ac1-91c6-d0ebe2355c35)

或者大家有什么更好的方法来解决这个问题?
抛砖引玉,感谢大佬们的开源!

### 🚑 其他信息

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the existing sendMessage entry point and the component's request prop, which are the only implementation points named in the issue. Trace how requests become messages in the list, then determine how a caller-supplied async request should produce a streamed assistant message. Done means the proposed GPTSendMessage-style API renders the returned response without a user message, with tests covering the behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.