mirror of
https://gitcode.com/ageerle/ruoyi-ai.git
synced 2026-04-05 15:57:32 +00:00
Merge remote-tracking branch 'origin/main'
# Conflicts: # ruoyi-modules/ruoyi-chat/src/main/java/org/ruoyi/chat/service/chat/impl/DifyServiceImpl.java # ruoyi-modules/ruoyi-generator/src/main/java/org/ruoyi/generator/impl/GenTableServiceImpl.java
This commit is contained in:
@@ -25,8 +25,10 @@ import org.ruoyi.service.IChatSessionService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
import org.ruoyi.chat.support.ChatServiceHelper;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.ruoyi.chat.support.RetryNotifier;
|
||||
|
||||
/**
|
||||
* dify 聊天管理
|
||||
@@ -111,23 +113,25 @@ public class DifyServiceImpl implements IChatService {
|
||||
chatRequestResponse.setUserId(chatRequest.getUserId());
|
||||
chatRequestResponse.setSessionId(chatRequest.getSessionId());
|
||||
chatRequestResponse.setPrompt(respMessage.toString());
|
||||
// 先保存助手消息,再发布异步计费事件
|
||||
chatCostService.saveMessage(chatRequestResponse);
|
||||
chatCostService.publishBillingEvent(chatRequestResponse);
|
||||
chatCostService.deductToken(chatRequestResponse);
|
||||
RetryNotifier.clear(emitter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(ErrorEvent event) {
|
||||
System.err.println("错误: " + event.getMessage());
|
||||
ChatServiceHelper.onStreamError(emitter, event.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(Throwable throwable) {
|
||||
System.err.println("异常: " + throwable.getMessage());
|
||||
ChatServiceHelper.onStreamError(emitter, throwable.getMessage());
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
log.error("dify请求失败:{}", e.getMessage());
|
||||
ChatServiceHelper.onStreamError(emitter, e.getMessage());
|
||||
}
|
||||
|
||||
return emitter;
|
||||
|
||||
Reference in New Issue
Block a user