From 216b57a4c7996e925d85c589d01b120b8d9f1a0d Mon Sep 17 00:00:00 2001 From: ccnetcore Date: Sat, 28 Jun 2025 23:07:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0hook=20fetch=20?= =?UTF-8?q?=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AiChat/Impl/AzureRestChatService.cs | 11 ++++++++--- .../Entities/Chat/MessageAggregateRoot.cs | 2 ++ .../Services/AccountService.cs | 2 +- Yi.Ai.Vue3/.env.development | 4 ++-- Yi.Ai.Vue3/package.json | 2 +- Yi.Ai.Vue3/pnpm-lock.yaml | 10 +++++----- Yi.Ai.Vue3/src/api/auth/index.ts | 6 +++--- Yi.Ai.Vue3/src/api/chat/index.ts | 4 ++-- Yi.Ai.Vue3/src/api/model/index.ts | 2 +- Yi.Ai.Vue3/src/api/session/index.ts | 8 ++++---- Yi.Ai.Vue3/src/api/session/types.ts | 2 +- Yi.Ai.Vue3/src/api/user/index.ts | 2 +- Yi.Ai.Vue3/src/components/ModelSelect/index.vue | 2 +- Yi.Ai.Vue3/src/stores/modules/session.ts | 4 ++-- 14 files changed, 34 insertions(+), 27 deletions(-) diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/AiChat/Impl/AzureRestChatService.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/AiChat/Impl/AzureRestChatService.cs index 05a74946..9035569a 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/AiChat/Impl/AzureRestChatService.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/AiChat/Impl/AzureRestChatService.cs @@ -31,8 +31,8 @@ public class AzureRestChatService : IChatService }).ToList(), stream = true, max_tokens = 2048, - temperature = 0.8, - top_p = 0.1, + // temperature = 0.8, + // top_p = 0.1, // presence_penalty = 0, // frequency_penalty = 0, model = aiModelDescribe.ModelId @@ -55,8 +55,13 @@ public class AzureRestChatService : IChatService // 发送POST请求 HttpResponseMessage response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken); + + if (!response.IsSuccessStatusCode) + { + throw new UserFriendlyException($"当前模型不可用:{aiModelDescribe.ModelId},状态码:{response.StatusCode},原因:{response.ReasonPhrase}"); + } // 确认响应成功 - response.EnsureSuccessStatusCode(); + // response.EnsureSuccessStatusCode(); // 读取响应内容 var responseStream = await response.Content.ReadAsStreamAsync(cancellationToken); diff --git a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Entities/Chat/MessageAggregateRoot.cs b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Entities/Chat/MessageAggregateRoot.cs index 2307053d..5edf2f78 100644 --- a/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Entities/Chat/MessageAggregateRoot.cs +++ b/Yi.Abp.Net8/module/ai-hub/Yi.Framework.AiHub.Domain/Entities/Chat/MessageAggregateRoot.cs @@ -43,4 +43,6 @@ public class MessageAggregateRoot : FullAuditedAggregateRoot public string? Remark { get; set; } [SugarColumn(IsOwnsOne = true)] public TokenUsageValueObject TokenUsage { get; set; } + + public override bool IsDeleted { get; set; } } \ No newline at end of file diff --git a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/AccountService.cs b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/AccountService.cs index 9393a96a..777a4452 100644 --- a/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/AccountService.cs +++ b/Yi.Abp.Net8/module/rbac/Yi.Framework.Rbac.Application/Services/AccountService.cs @@ -148,7 +148,7 @@ namespace Yi.Framework.Rbac.Application.Services [Authorize(AuthenticationSchemes = TokenTypeConst.Refresh)] public async Task PostRefreshAsync([FromQuery] string refresh_token) { - var userId = CurrentUser.Id.Value; + var userId = CurrentUser.GetId(); var accessToken = await _accountManager.GetTokenByUserIdAsync(userId); var refreshToken = _accountManager.CreateRefreshToken(userId); return new { Token = accessToken, RefreshToken = refreshToken }; diff --git a/Yi.Ai.Vue3/.env.development b/Yi.Ai.Vue3/.env.development index b32755dd..b38eb0cf 100644 --- a/Yi.Ai.Vue3/.env.development +++ b/Yi.Ai.Vue3/.env.development @@ -12,8 +12,8 @@ VITE_WEB_BASE_API = '/dev-api' # VITE_WEB_BASE_API='/prod-api' # 本地接口 -# VITE_API_URL = http://localhost:19001/api/app -VITE_API_URL=http://ccnetcore.com:19001/api/app +VITE_API_URL = http://localhost:19001/api/app +# VITE_API_URL=http://ccnetcore.com:19001/api/app # SSO单点登录url VITE_SSO_SEVER_URL='http://localhost:18001' diff --git a/Yi.Ai.Vue3/package.json b/Yi.Ai.Vue3/package.json index 9b0ca60d..5047cb8e 100644 --- a/Yi.Ai.Vue3/package.json +++ b/Yi.Ai.Vue3/package.json @@ -39,7 +39,7 @@ "@vueuse/integrations": "^13.3.0", "element-plus": "^2.9.11", "fingerprintjs": "^0.5.3", - "hook-fetch": "^1.1.3", + "hook-fetch": "^2.0.0-beta.1", "nprogress": "^0.2.0", "pinia": "^3.0.3", "pinia-plugin-persistedstate": "^4.3.0", diff --git a/Yi.Ai.Vue3/pnpm-lock.yaml b/Yi.Ai.Vue3/pnpm-lock.yaml index 9a6b12b7..022eff68 100644 --- a/Yi.Ai.Vue3/pnpm-lock.yaml +++ b/Yi.Ai.Vue3/pnpm-lock.yaml @@ -39,8 +39,8 @@ importers: specifier: ^0.5.3 version: 0.5.3 hook-fetch: - specifier: ^1.1.3 - version: 1.1.3(react@19.1.0)(typescript-api-pro@0.0.7)(vue@3.5.16(typescript@5.8.3)) + specifier: ^2.0.0-beta.1 + version: 2.0.0-beta.1(react@19.1.0)(typescript-api-pro@0.0.7)(vue@3.5.16(typescript@5.8.3)) nprogress: specifier: ^0.2.0 version: 0.2.0 @@ -2811,8 +2811,8 @@ packages: resolution: {integrity: sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==} hasBin: true - hook-fetch@1.1.3: - resolution: {integrity: sha512-FkWKUjZWr83gyew0YbRyEc72dlIGCYvNXiRfi4AXlb/hvIiFPQfcvlP3IFaIYKERUeKXmuBS9fuNuK8JPQiOCg==} + hook-fetch@2.0.0-beta.1: + resolution: {integrity: sha512-c1pLT1madA4oL1K0+2PNjrdMtXper1CSLJHcsstzohoKKnqYrUF6TKM45Wrwdam7ZGX74j/5XPjfgPuC7VPs7A==} peerDependencies: react: ^19.1.0 typescript-api-pro: ^0.0.6 @@ -8066,7 +8066,7 @@ snapshots: he@1.2.0: {} - hook-fetch@1.1.3(react@19.1.0)(typescript-api-pro@0.0.7)(vue@3.5.16(typescript@5.8.3)): + hook-fetch@2.0.0-beta.1(react@19.1.0)(typescript-api-pro@0.0.7)(vue@3.5.16(typescript@5.8.3)): dependencies: qs: 6.14.0 radash: 12.1.0 diff --git a/Yi.Ai.Vue3/src/api/auth/index.ts b/Yi.Ai.Vue3/src/api/auth/index.ts index bcfaaf73..c1b21b92 100644 --- a/Yi.Ai.Vue3/src/api/auth/index.ts +++ b/Yi.Ai.Vue3/src/api/auth/index.ts @@ -1,10 +1,10 @@ import type { EmailCodeDTO, LoginDTO, LoginVO, RegisterDTO } from './types'; import { post } from '@/utils/request'; -export const login = (data: LoginDTO) => post('/auth/login', data); +export const login = (data: LoginDTO) => post('/auth/login', data).json(); // 邮箱验证码 -export const emailCode = (data: EmailCodeDTO) => post('/resource/email/code', data); +export const emailCode = (data: EmailCodeDTO) => post('/resource/email/code', data).json(); // 注册账号 -export const register = (data: RegisterDTO) => post('/auth/register', data); +export const register = (data: RegisterDTO) => post('/auth/register', data).json(); diff --git a/Yi.Ai.Vue3/src/api/chat/index.ts b/Yi.Ai.Vue3/src/api/chat/index.ts index ae92da0b..1c74d6ec 100644 --- a/Yi.Ai.Vue3/src/api/chat/index.ts +++ b/Yi.Ai.Vue3/src/api/chat/index.ts @@ -7,11 +7,11 @@ export const send = (data: SendDTO) => post('/ai-chat/send', data); // 新增对应会话聊天记录 export function addChat(data: ChatMessageVo) { - return post('/system/message', data); + return post('/system/message', data).json(); } // 获取当前会话的聊天记录 export function getChatList(params: GetChatListParams) { // return get('/system/message/list', params); - return get('/message', params); + return get('/message', params).json(); } diff --git a/Yi.Ai.Vue3/src/api/model/index.ts b/Yi.Ai.Vue3/src/api/model/index.ts index 68f20748..0a08b5ba 100644 --- a/Yi.Ai.Vue3/src/api/model/index.ts +++ b/Yi.Ai.Vue3/src/api/model/index.ts @@ -4,5 +4,5 @@ import { get } from '@/utils/request'; // 获取当前用户的模型列表 export function getModelList() { // return get('/system/model/modelList'); - return get('/ai-chat/model'); + return get('/ai-chat/model').json(); } diff --git a/Yi.Ai.Vue3/src/api/session/index.ts b/Yi.Ai.Vue3/src/api/session/index.ts index 9f703b94..82e2edf2 100644 --- a/Yi.Ai.Vue3/src/api/session/index.ts +++ b/Yi.Ai.Vue3/src/api/session/index.ts @@ -9,19 +9,19 @@ import { del, get, post, put } from '@/utils/request'; // 获取会话列表 export function get_session_list(params: GetSessionListParams) { // return get('/system/session/list', params); - return get('/session', params); + return get('/session', params).json(); } // 创建会话 export function create_session(data: CreateSessionDTO) { - return post('/session', data); + return post('/session', data).json(); } // 更新会话 export function update_session(data: ChatSessionVo) { - return put(`/session/${data.id}`, data); + return put(`/session/${data.id}`, data).json(); } // 会话详情 export function get_session(id: string) { - return get(`/session/${id}`); + return get(`/session/${id}`).json(); } // 删除会话 export function delete_session(ids: string[]) { diff --git a/Yi.Ai.Vue3/src/api/session/types.ts b/Yi.Ai.Vue3/src/api/session/types.ts index 4a2b11ce..e8af8b63 100644 --- a/Yi.Ai.Vue3/src/api/session/types.ts +++ b/Yi.Ai.Vue3/src/api/session/types.ts @@ -91,7 +91,7 @@ export interface ChatSessionVo { /** * 创建时间 */ - createTime?: Date; + creationTime?: Date; /** * 自定义的消息前缀图标字段 */ diff --git a/Yi.Ai.Vue3/src/api/user/index.ts b/Yi.Ai.Vue3/src/api/user/index.ts index 5e98d50d..8c57dd79 100644 --- a/Yi.Ai.Vue3/src/api/user/index.ts +++ b/Yi.Ai.Vue3/src/api/user/index.ts @@ -2,5 +2,5 @@ import { get } from '@/utils/request'; // 获取用户信息 export function getUserInfo() { - return get('/ai-chat/account'); + return get('/ai-chat/account').json(); } diff --git a/Yi.Ai.Vue3/src/components/ModelSelect/index.vue b/Yi.Ai.Vue3/src/components/ModelSelect/index.vue index 96e2a1c3..c7a7c0e0 100644 --- a/Yi.Ai.Vue3/src/components/ModelSelect/index.vue +++ b/Yi.Ai.Vue3/src/components/ModelSelect/index.vue @@ -122,7 +122,7 @@ function handleClick(item: GetSessionListVO) { display: flex; flex-direction: column; gap: 4px; - height: 500px; + height: 200px; overflow: hidden auto; .popover-content-box-items { :deep() { diff --git a/Yi.Ai.Vue3/src/stores/modules/session.ts b/Yi.Ai.Vue3/src/stores/modules/session.ts index 2416bf65..d0426f49 100644 --- a/Yi.Ai.Vue3/src/stores/modules/session.ts +++ b/Yi.Ai.Vue3/src/stores/modules/session.ts @@ -178,7 +178,7 @@ export const useSessionStore = defineStore('session', () => { // 删除会话(供组件调用) const deleteSessions = async (ids: string[]) => { try { - //todo cc这里删除,返回空的body,结果炸了,报错堆栈都没有 + // todo cc这里删除,返回空的body,结果炸了,报错堆栈都没有 await delete_session(ids); // 1. 先找到被修改会话在 sessionList 中的索引(假设 sessionList 是按服务端排序的完整列表) const targetIndex = sessionList.value.findIndex(session => session.id === ids[0]); @@ -200,7 +200,7 @@ export const useSessionStore = defineStore('session', () => { const currentDate = new Date(); return sessions.map((session) => { - const createDate = new Date(session.createTime!); + const createDate = new Date(session.creationTime!); const diffDays = Math.floor( (currentDate.getTime() - createDate.getTime()) / (1000 * 60 * 60 * 24), );