Skip to content

Commit d513090

Browse files
committed
fixed:recv json data Incomplete for ai api
1 parent 210a257 commit d513090

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

XEngine_Module/XEngine_AIApi/AIApi_Chat/AIApi_Chat.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ bool CAIApi_Chat::AIApi_Chat_Create(XNETHANDLE* pxhToken, LPCXSTR lpszAPIUrl, LP
9191
AIApi_dwErrorCode = ERROR_XENGINE_MODULE_AIAPI_CHAT_MALLOC;
9292
return false;
9393
}
94+
pSt_AIClient->ptszMSGBuffer = (XCHAR*)malloc(XENGINE_MEMORY_SIZE_MAX);
95+
if (NULL == pSt_AIClient->ptszMSGBuffer)
96+
{
97+
AIApi_IsErrorOccur = true;
98+
AIApi_dwErrorCode = ERROR_XENGINE_MODULE_AIAPI_CHAT_MALLOC;
99+
return false;
100+
}
101+
memset(pSt_AIClient->ptszMSGBuffer, '\0', XENGINE_MEMORY_SIZE_MAX);
102+
94103
if (!APIClient_Http_Create(&pSt_AIClient->xhToken, AIApi_Chat_CBRecv, pSt_AIClient))
95104
{
96105
AIApi_IsErrorOccur = true;
@@ -489,5 +498,11 @@ void CAIApi_Chat::AIApi_Chat_CBRecv(XNETHANDLE xhToken, XPVOID lpszMsgBuffer, in
489498
}
490499
}
491500

492-
pClass_This->AIApi_Chat_Parse(pSt_AIClient, (LPCXSTR)lpszMsgBuffer + nPos, nMsgLen - nPos, bSSEReply);
501+
memcpy(pSt_AIClient->ptszMSGBuffer + pSt_AIClient->nMSGLen, lpszMsgBuffer, nMsgLen);
502+
pSt_AIClient->nMSGLen += nMsgLen;
503+
if (pClass_This->AIApi_Chat_Parse(pSt_AIClient, (LPCXSTR)pSt_AIClient->ptszMSGBuffer + nPos, pSt_AIClient->nMSGLen - nPos, bSSEReply))
504+
{
505+
memset(pSt_AIClient->ptszMSGBuffer, '\0', XENGINE_MEMORY_SIZE_MAX);
506+
pSt_AIClient->nMSGLen = 0;
507+
}
493508
}

XEngine_Module/XEngine_AIApi/AIApi_Chat/AIApi_Chat.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ typedef struct
2222
XCHAR tszAPIRole[XPATH_MAX];
2323
XNETHANDLE xhToken;
2424
time_t nTimeStart;
25+
int nMSGLen;
2526

2627
bool bStream;
2728
bool bHistory;
2829
std::unique_ptr<std::list<AICLIENT_HISTORY>> pStl_ListHistory;
2930

31+
XCHAR* ptszMSGBuffer;
3032
XPVOID lClass;
3133
XPVOID lParam;
3234
CALLBACK_XENGINE_MODULE_AIAPI_CHAT lpCall_Chat;

0 commit comments

Comments
 (0)