Skip to content

Commit 5df154e

Browse files
committed
fixed:reply error not handle for ai chat module
1 parent 64bbd47 commit 5df154e

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

XEngine_Example/AIApi_APPExample/AIApi_APPExample.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,13 @@ int Test_Chat()
153153
//LPCXSTR lpszAPIKey = _X("sk-1");
154154
//LPCXSTR lpszAPIModel = _X("gpt-4o");
155155

156-
LPCXSTR lpszAPIUrl = _X("https://api.hunyuan.cloud.tencent.com/v1/chat/completions");
157-
LPCXSTR lpszAPIKey = _X("sk-1");
158-
LPCXSTR lpszAPIModel = _X("hunyuan-turbos-latest");
156+
//LPCXSTR lpszAPIUrl = _X("https://api.hunyuan.cloud.tencent.com/v1/chat/completions");
157+
//LPCXSTR lpszAPIKey = _X("sk-1");
158+
//LPCXSTR lpszAPIModel = _X("hunyuan-turbos-latest");
159+
160+
LPCXSTR lpszAPIUrl = _X("https://ark.cn-beijing.volces.com/api/v3/chat/completions");
161+
LPCXSTR lpszAPIKey = _X("d68056c1-1");
162+
LPCXSTR lpszAPIModel = _X("doubao-seed-1-6-flash-250828");
159163

160164
if (!AIApi_Chat_Create(&xhToken, lpszAPIUrl, lpszAPIKey, XEngine_AIApi_CBRecv))
161165
{
@@ -197,9 +201,9 @@ int Test_Chat()
197201
}
198202
int main()
199203
{
200-
Test_CreateImage();
201-
Test_ParseImage();
202-
Test_Think();
204+
//Test_CreateImage();
205+
//Test_ParseImage();
206+
//Test_Think();
203207
Test_Chat();
204208
return 0;
205209
}

XEngine_Module/XEngine_AIApi/AIApi_Chat/AIApi_Chat.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,16 +353,22 @@ bool CAIApi_Chat::AIApi_Chat_GetStatus(XNETHANDLE xhToken, bool* pbComplete, int
353353
st_Locker.unlock_shared();
354354
return false;
355355
}
356-
357-
if (!APIClient_Http_GetResult(xhToken, pbComplete, pInt_HTTPCode, bWaitExist))
356+
int nHTTPCode = 0;
357+
if (!APIClient_Http_GetResult(xhToken, pbComplete, &nHTTPCode, bWaitExist))
358358
{
359359
AIApi_IsErrorOccur = true;
360360
AIApi_dwErrorCode = APIClient_GetLastError();
361361
st_Locker.unlock_shared();
362362
return false;
363363
}
364-
365364
st_Locker.unlock_shared();
365+
366+
if (200 != nHTTPCode)
367+
{
368+
AIApi_IsErrorOccur = true;
369+
AIApi_dwErrorCode = ERROR_XENGINE_MODULE_AIAPI_CHAT_HTTPCODE;
370+
return false;
371+
}
366372
return true;
367373
}
368374
/********************************************************************
@@ -415,6 +421,11 @@ bool CAIApi_Chat::AIApi_Chat_Parse(AICLIENT_CHAT* pSt_AIClient, LPCXSTR lpszMSGB
415421
Json::Value st_JsonChoices = st_JsonRoot["choices"];
416422
if (st_JsonChoices.isNull())
417423
{
424+
Json::Value st_JsonError = st_JsonRoot["error"];
425+
if (!st_JsonError.isNull())
426+
{
427+
pSt_AIClient->lpCall_Chat(pSt_AIClient->xhToken, st_JsonError["type"].asCString(), st_JsonError["message"].asCString(), st_JsonError["message"].size(), false, pSt_AIClient->lParam);
428+
}
418429
return false;
419430
}
420431

XEngine_Module/XEngine_AIApi/AIApi_Error.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define ERROR_XENGINE_MODULE_AIAPI_CHAT_PARAMENT 0x01D0001 //参数错误,无法继续
1717
#define ERROR_XENGINE_MODULE_AIAPI_CHAT_MALLOC 0x01D0002 //申请内存失败
1818
#define ERROR_XENGINE_MODULE_AIAPI_CHAT_NOTFOUND 0x01D0003 //没有找到
19+
#define ERROR_XENGINE_MODULE_AIAPI_CHAT_HTTPCODE 0x01D0004 //HTTPCODE错误
1920
/************************************************************************/
2021
/* AI视觉图像模型接口错误 */
2122
/************************************************************************/

0 commit comments

Comments
 (0)