Skip to content

Commit 315b4c1

Browse files
committed
modify:unused history code and unified error code
1 parent 5992fe1 commit 315b4c1

File tree

6 files changed

+32
-28
lines changed

6 files changed

+32
-28
lines changed

XEngine_Module/XEngine_AIApi/AIApi_Error.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,10 @@
1515
/************************************************************************/
1616
#define ERROR_XENGINE_MODULE_AIAPI_CHAT_PARAMENT 0x01D0001 //参数错误,无法继续
1717
#define ERROR_XENGINE_MODULE_AIAPI_CHAT_MALLOC 0x01D0002 //申请内存失败
18-
#define ERROR_XENGINE_MODULE_AIAPI_CHAT_NOTFOUND 0x01D0003 //没有找到
18+
#define ERROR_XENGINE_MODULE_AIAPI_CHAT_NOTFOUND 0x01D0003 //没有找到
19+
/************************************************************************/
20+
/* AI图像模型接口错误 */
21+
/************************************************************************/
22+
#define ERROR_XENGINE_MODULE_AIAPI_IMAGE_PARAMENT 0x01D1001 //参数错误,无法继续
23+
#define ERROR_XENGINE_MODULE_AIAPI_IMAGE_MALLOC 0x01D1002 //申请内存失败
24+
#define ERROR_XENGINE_MODULE_AIAPI_IMAGE_NOTFOUND 0x01D1003 //没有找到

XEngine_Module/XEngine_AIApi/AIApi_Image/AIApi_Image.cpp

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ bool CAIApi_Image::AIApi_Image_Create(XNETHANDLE* pxhToken, LPCXSTR lpszAPIUrl,
6565
if (NULL == pxhToken || NULL == lpszAPIUrl || NULL == lpszAPIKey)
6666
{
6767
AIApi_IsErrorOccur = true;
68-
AIApi_dwErrorCode = ERROR_XENGINE_MODULE_AIAPI_CHAT_PARAMENT;
68+
AIApi_dwErrorCode = ERROR_XENGINE_MODULE_AIAPI_IMAGE_PARAMENT;
6969
return false;
7070
}
7171
AICLIENT_IMAGE *pSt_AIClient = new AICLIENT_IMAGE;
7272
if (NULL == pSt_AIClient)
7373
{
7474
AIApi_IsErrorOccur = true;
75-
AIApi_dwErrorCode = ERROR_XENGINE_MODULE_AIAPI_CHAT_MALLOC;
75+
AIApi_dwErrorCode = ERROR_XENGINE_MODULE_AIAPI_IMAGE_MALLOC;
7676
return false;
7777
}
7878
*pSt_AIClient = {};
@@ -83,14 +83,14 @@ bool CAIApi_Image::AIApi_Image_Create(XNETHANDLE* pxhToken, LPCXSTR lpszAPIUrl,
8383
_xstrcpy(pSt_AIClient->tszAPIUrl, lpszAPIUrl, sizeof(pSt_AIClient->tszAPIUrl));
8484
_xsntprintf(pSt_AIClient->tszAPIHdr, sizeof(pSt_AIClient->tszAPIHdr), _X("Content-Type: application/json\r\nAuthorization: Bearer %s"), lpszAPIKey);
8585

86-
pSt_AIClient->ptszMSGBuffer = (XCHAR*)malloc(XENGINE_MEMORY_SIZE_MAX);
86+
pSt_AIClient->ptszMSGBuffer = (XCHAR*)malloc(XENGINE_MEMORY_SIZE_LARGE);
8787
if (NULL == pSt_AIClient->ptszMSGBuffer)
8888
{
8989
AIApi_IsErrorOccur = true;
90-
AIApi_dwErrorCode = ERROR_XENGINE_MODULE_AIAPI_CHAT_MALLOC;
90+
AIApi_dwErrorCode = ERROR_XENGINE_MODULE_AIAPI_IMAGE_MALLOC;
9191
return false;
9292
}
93-
memset(pSt_AIClient->ptszMSGBuffer, '\0', XENGINE_MEMORY_SIZE_MAX);
93+
memset(pSt_AIClient->ptszMSGBuffer, '\0', XENGINE_MEMORY_SIZE_LARGE);
9494

9595
if (!APIClient_Http_Create(&pSt_AIClient->xhToken, AIApi_Image_CBRecv, pSt_AIClient))
9696
{
@@ -162,7 +162,7 @@ bool CAIApi_Image::AIApi_Image_Excute(XNETHANDLE xhToken, LPCXSTR lpszModelName,
162162
if (stl_MapIterator == stl_MapAIClient.end())
163163
{
164164
AIApi_IsErrorOccur = true;
165-
AIApi_dwErrorCode = ERROR_XENGINE_MODULE_AIAPI_CHAT_NOTFOUND;
165+
AIApi_dwErrorCode = ERROR_XENGINE_MODULE_AIAPI_IMAGE_NOTFOUND;
166166
st_Locker.unlock_shared();
167167
return false;
168168
}
@@ -204,7 +204,6 @@ bool CAIApi_Image::AIApi_Image_Excute(XNETHANDLE xhToken, LPCXSTR lpszModelName,
204204
st_JsonRoot["messages"] = st_JsonArray;
205205

206206
xstring m_StrBody = Json::writeString(st_JsonBuilder, st_JsonRoot);
207-
printf("%s\n", m_StrBody.c_str());
208207
if (!APIClient_Http_Excute(xhToken, m_StrBody.c_str(), m_StrBody.length(), stl_MapIterator->second->tszAPIHdr))
209208
{
210209
AIApi_IsErrorOccur = true;
@@ -252,7 +251,7 @@ bool CAIApi_Image::AIApi_Image_GetStatus(XNETHANDLE xhToken, bool* pbComplete, i
252251
if (stl_MapIterator == stl_MapAIClient.end())
253252
{
254253
AIApi_IsErrorOccur = true;
255-
AIApi_dwErrorCode = ERROR_XENGINE_MODULE_AIAPI_CHAT_NOTFOUND;
254+
AIApi_dwErrorCode = ERROR_XENGINE_MODULE_AIAPI_IMAGE_NOTFOUND;
256255
st_Locker.unlock_shared();
257256
return false;
258257
}
@@ -351,19 +350,8 @@ bool CAIApi_Image::AIApi_Image_Parse(AICLIENT_IMAGE* pSt_AIClient, LPCXSTR lpszM
351350
XCHAR tszGBKBuffer[8192] = {};
352351
BaseLib_Charset_UTFToAnsi(st_JsonMessage["content"].asString().c_str(), tszGBKBuffer, &nGBKLen);
353352
pSt_AIClient->lpCall_Chat(pSt_AIClient->xhToken, st_JsonRoot["model"].asCString(), tszGBKBuffer, nGBKLen, false, pSt_AIClient->lParam);
354-
if (bSSEReply)
355-
{
356-
//流式数据需要单独处理保存
357-
memcpy(pSt_AIClient->st_HisStream.tszRoleContent + pSt_AIClient->st_HisStream.nCLen, tszGBKBuffer, nGBKLen);
358-
pSt_AIClient->st_HisStream.nCLen += nGBKLen;
359-
}
360353
#else
361354
pSt_AIClient->lpCall_Chat(pSt_AIClient->xhToken, st_JsonRoot["model"].asCString(), st_JsonMessage["content"].asString().c_str(), st_JsonMessage["content"].asString().length(), false, pSt_AIClient->lParam);
362-
if (bSSEReply)
363-
{
364-
memcpy(pSt_AIClient->st_HisStream.tszRoleContent + pSt_AIClient->st_HisStream.nCLen, st_JsonMessage["content"].asString().c_str(), st_JsonMessage["content"].asString().length());
365-
pSt_AIClient->st_HisStream.nCLen += st_JsonMessage["content"].asString().length();
366-
}
367355
#endif
368356
}
369357
}

XEngine_Module/XEngine_AIApi/AIApi_Image/AIApi_Image.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@
1212
*********************************************************************/
1313
typedef struct
1414
{
15-
int nCLen;
16-
XCHAR tszThinkContent[8192];
17-
XCHAR tszRoleContent[8192];
18-
XCHAR tszRoleName[128];
19-
}AICLIENT_IMAGEHISTORY;
20-
typedef struct
21-
{
22-
AICLIENT_IMAGEHISTORY st_HisStream; //流式有用
2315
XCHAR tszAPIUrl[XPATH_MAX];
2416
XCHAR tszAPIHdr[XPATH_MAX];
2517
XNETHANDLE xhToken;

XEngine_Module/XEngine_AIApi/XEngine_AIApi.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,14 @@
239239
<ClInclude Include="AIApi_Chat\AIApi_Chat.h" />
240240
<ClInclude Include="AIApi_Define.h" />
241241
<ClInclude Include="AIApi_Error.h" />
242+
<ClInclude Include="AIApi_Help\AIApi_Help.h" />
242243
<ClInclude Include="AIApi_Image\AIApi_Image.h" />
243244
<ClInclude Include="framework.h" />
244245
<ClInclude Include="pch.h" />
245246
</ItemGroup>
246247
<ItemGroup>
247248
<ClCompile Include="AIApi_Chat\AIApi_Chat.cpp" />
249+
<ClCompile Include="AIApi_Help\AIApi_Help.cpp" />
248250
<ClCompile Include="AIApi_Image\AIApi_Image.cpp" />
249251
<ClCompile Include="dllmain.cpp" />
250252
<ClCompile Include="pch.cpp">

XEngine_Module/XEngine_AIApi/XEngine_AIApi.vcxproj.filters

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
<Filter Include="源文件\AIApi_Image">
2626
<UniqueIdentifier>{a13fcb1c-0028-48b8-8412-889d070db132}</UniqueIdentifier>
2727
</Filter>
28+
<Filter Include="头文件\AIApi_Help">
29+
<UniqueIdentifier>{90ea5304-7076-452a-b6ad-890b625b0d58}</UniqueIdentifier>
30+
</Filter>
31+
<Filter Include="源文件\AIApi_Help">
32+
<UniqueIdentifier>{d612c628-9e84-4ba6-8612-f261a6952c73}</UniqueIdentifier>
33+
</Filter>
2834
</ItemGroup>
2935
<ItemGroup>
3036
<ClInclude Include="framework.h">
@@ -45,6 +51,9 @@
4551
<ClInclude Include="AIApi_Image\AIApi_Image.h">
4652
<Filter>头文件\AIApi_Image</Filter>
4753
</ClInclude>
54+
<ClInclude Include="AIApi_Help\AIApi_Help.h">
55+
<Filter>头文件\AIApi_Help</Filter>
56+
</ClInclude>
4857
</ItemGroup>
4958
<ItemGroup>
5059
<ClCompile Include="dllmain.cpp">
@@ -59,6 +68,9 @@
5968
<ClCompile Include="AIApi_Image\AIApi_Image.cpp">
6069
<Filter>源文件\AIApi_Image</Filter>
6170
</ClCompile>
71+
<ClCompile Include="AIApi_Help\AIApi_Help.cpp">
72+
<Filter>源文件\AIApi_Help</Filter>
73+
</ClCompile>
6274
</ItemGroup>
6375
<ItemGroup>
6476
<None Include="XEngine_AIApi.def">

XEngine_Module/XEngine_AIApi/pch.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define PCH_H
99
#ifdef _MSC_BUILD
1010
// 添加要在此处预编译的标头
11+
#define _CRT_SECURE_NO_WARNINGS
1112
#include "framework.h"
1213
#endif
1314
#endif //PCH_H
@@ -29,6 +30,8 @@
2930
#include <XEngine_Include/XEngine_BaseLib/BaseSafe_Error.h>
3031
#include <XEngine_Include/XEngine_Client/APIClient_Define.h>
3132
#include <XEngine_Include/XEngine_Client/APIClient_Error.h>
33+
#include <XEngine_Include/XEngine_Core/Cryption_Define.h>
34+
#include <XEngine_Include/XEngine_Core/Cryption_Error.h>
3235
#include "AIApi_Define.h"
3336
#include "AIApi_Error.h"
3437
/********************************************************************
@@ -49,6 +52,7 @@ extern XLONG AIApi_dwErrorCode;
4952
#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseLib")
5053
#pragma comment(lib,"XEngine_BaseLib/XEngine_BaseSafe")
5154
#pragma comment(lib,"XEngine_Client/XClient_APIHelp")
55+
#pragma comment(lib,"XEngine_Core/XEngine_Cryption")
5256
#ifdef _DEBUG
5357
#ifdef _M_X64
5458
#pragma comment(lib,"x64/Debug/jsoncpp")

0 commit comments

Comments
 (0)