Skip to content

Commit 49351b2

Browse files
committed
added:ai api example
1 parent 463eeae commit 49351b2

File tree

5 files changed

+311
-2
lines changed

5 files changed

+311
-2
lines changed

XEngine.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ Global
221221
{DE495AB3-201F-4288-9A3A-41DFA146AD30}.Release|x64.Build.0 = Release|x64
222222
{DE495AB3-201F-4288-9A3A-41DFA146AD30}.Release|x86.ActiveCfg = Release|Win32
223223
{DE495AB3-201F-4288-9A3A-41DFA146AD30}.Release|x86.Build.0 = Release|Win32
224-
{C0792082-058B-4BF1-894F-D4D5D7124022}.Debug|ARM64.ActiveCfg = Debug|x64
225-
{C0792082-058B-4BF1-894F-D4D5D7124022}.Debug|ARM64.Build.0 = Debug|x64
224+
{C0792082-058B-4BF1-894F-D4D5D7124022}.Debug|ARM64.ActiveCfg = Debug|ARM64
225+
{C0792082-058B-4BF1-894F-D4D5D7124022}.Debug|ARM64.Build.0 = Debug|ARM64
226226
{C0792082-058B-4BF1-894F-D4D5D7124022}.Debug|x64.ActiveCfg = Debug|x64
227227
{C0792082-058B-4BF1-894F-D4D5D7124022}.Debug|x64.Build.0 = Debug|x64
228228
{C0792082-058B-4BF1-894F-D4D5D7124022}.Debug|x86.ActiveCfg = Debug|Win32
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#ifdef _MSC_BUILD
2+
#include <Windows.h>
3+
#include <tchar.h>
4+
#endif
5+
#include <stdio.h>
6+
#include <stdlib.h>
7+
#include <string.h>
8+
#include <thread>
9+
using namespace std;
10+
#include <XEngine_Include/XEngine_CommHdr.h>
11+
#include "../../XEngine_Module/XEngine_AIApi/AIApi_Define.h"
12+
#include "../../XEngine_Module/XEngine_AIApi/AIApi_Error.h"
13+
14+
#ifdef _MSC_BUILD
15+
#ifdef _DEBUG
16+
#ifdef _M_X64
17+
#pragma comment(lib,"../../x64/Debug/XEngine_AIApi.lib")
18+
#elif _M_ARM64
19+
#pragma comment(lib,"../../ARM64/Debug/XEngine_AIApi.lib")
20+
#elif _M_IX86
21+
#pragma comment(lib,"../../Debug/XEngine_AIApi.lib")
22+
#endif
23+
#else
24+
#ifdef _M_X64
25+
#pragma comment(lib,"../../x64/Release/XEngine_AIApi.lib")
26+
#elif _M_ARM64
27+
#pragma comment(lib,"../../ARM64/Release/XEngine_AIApi.lib")
28+
#elif _M_IX86
29+
#pragma comment(lib,"../../Release/XEngine_AIApi.lib")
30+
#endif
31+
#endif
32+
#endif
33+
34+
//Linux Macos::g++ -std=c++17 -Wall -g AIApi_APPExample.cpp -o AIApi_APPExample.exe -L ../../XEngine_Module/XEngine_AIApi -lXEngine_AIApi
35+
36+
void XCALLBACK XEngine_AIApi_CBRecv(XNETHANDLE xhToken, LPCXSTR lpszModelName, LPCXSTR lpszMsgBuffer, int nMsgLen, XPVOID lParam)
37+
{
38+
printf("%lld,Name:%s:%d=%s\n", xhToken, lpszModelName, nMsgLen, lpszMsgBuffer);
39+
}
40+
int main()
41+
{
42+
XNETHANDLE xhToken = 0;
43+
44+
LPCXSTR lpszAPIUrl = _X("https://api.zhizengzeng.com/v1/chat/completions");
45+
LPCXSTR lpszAPIKey = _X("sk-zk29d91bb8d095c79c32a2a7edaca603137678e1b2a9316a");
46+
LPCXSTR lpszAPIModel = _X("gpt-4o");
47+
48+
//LPCXSTR lpszAPIUrl = _X("https://api.hunyuan.cloud.tencent.com/v1/chat/completions");
49+
//LPCXSTR lpszAPIKey = _X("sk-kguobQDvmlzonvUXFBgYyMEZjZZjjcNp17bME2Si6SjrGNKp");
50+
//LPCXSTR lpszAPIModel = _X("hunyuan-turbos-latest");
51+
52+
if (!AIApi_Chat_Create(&xhToken, lpszAPIUrl, lpszAPIKey, XEngine_AIApi_CBRecv))
53+
{
54+
printf("AIApi_Chat_Create:%lX\n", AIApi_GetLastError());
55+
return 0;
56+
}
57+
AIApi_Chat_SetRole(xhToken, _X("You are a helpful assistant."));
58+
LPCXSTR lpszMSGBuffer = _X("hello");
59+
int nMSGLen = strlen(lpszMSGBuffer);
60+
if (!AIApi_Chat_Excute(xhToken, lpszAPIModel, lpszMSGBuffer, nMSGLen))
61+
{
62+
printf("AIApi_Chat_Excute:%lX\n", AIApi_GetLastError());
63+
return 0;
64+
}
65+
66+
bool bCompleted = false;
67+
AIApi_Chat_GetStatus(xhToken, &bCompleted);
68+
lpszMSGBuffer = _X("what can you do for me?");
69+
nMSGLen = strlen(lpszMSGBuffer);
70+
if (!AIApi_Chat_Excute(xhToken, lpszAPIModel, lpszMSGBuffer, nMSGLen, false))
71+
{
72+
printf("AIApi_Chat_Excute:%lX\n", AIApi_GetLastError());
73+
return 0;
74+
}
75+
76+
bCompleted = false;
77+
AIApi_Chat_GetStatus(xhToken, &bCompleted);
78+
AIApi_Chat_Destory(xhToken);
79+
return 1;
80+
}
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|ARM64">
5+
<Configuration>Debug</Configuration>
6+
<Platform>ARM64</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Debug|Win32">
9+
<Configuration>Debug</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Release|ARM64">
13+
<Configuration>Release</Configuration>
14+
<Platform>ARM64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|Win32">
17+
<Configuration>Release</Configuration>
18+
<Platform>Win32</Platform>
19+
</ProjectConfiguration>
20+
<ProjectConfiguration Include="Debug|x64">
21+
<Configuration>Debug</Configuration>
22+
<Platform>x64</Platform>
23+
</ProjectConfiguration>
24+
<ProjectConfiguration Include="Release|x64">
25+
<Configuration>Release</Configuration>
26+
<Platform>x64</Platform>
27+
</ProjectConfiguration>
28+
</ItemGroup>
29+
<PropertyGroup Label="Globals">
30+
<VCProjectVersion>17.0</VCProjectVersion>
31+
<Keyword>Win32Proj</Keyword>
32+
<ProjectGuid>{c0792082-058b-4bf1-894f-d4d5d7124022}</ProjectGuid>
33+
<RootNamespace>AIApiAPPExample</RootNamespace>
34+
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
35+
</PropertyGroup>
36+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
37+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
38+
<ConfigurationType>Application</ConfigurationType>
39+
<UseDebugLibraries>true</UseDebugLibraries>
40+
<PlatformToolset>v143</PlatformToolset>
41+
<CharacterSet>Unicode</CharacterSet>
42+
</PropertyGroup>
43+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
44+
<ConfigurationType>Application</ConfigurationType>
45+
<UseDebugLibraries>false</UseDebugLibraries>
46+
<PlatformToolset>v143</PlatformToolset>
47+
<WholeProgramOptimization>true</WholeProgramOptimization>
48+
<CharacterSet>Unicode</CharacterSet>
49+
</PropertyGroup>
50+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
51+
<ConfigurationType>Application</ConfigurationType>
52+
<UseDebugLibraries>true</UseDebugLibraries>
53+
<PlatformToolset>v143</PlatformToolset>
54+
<CharacterSet>Unicode</CharacterSet>
55+
</PropertyGroup>
56+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="Configuration">
57+
<ConfigurationType>Application</ConfigurationType>
58+
<UseDebugLibraries>true</UseDebugLibraries>
59+
<PlatformToolset>v143</PlatformToolset>
60+
<CharacterSet>Unicode</CharacterSet>
61+
</PropertyGroup>
62+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
63+
<ConfigurationType>Application</ConfigurationType>
64+
<UseDebugLibraries>false</UseDebugLibraries>
65+
<PlatformToolset>v143</PlatformToolset>
66+
<WholeProgramOptimization>true</WholeProgramOptimization>
67+
<CharacterSet>Unicode</CharacterSet>
68+
</PropertyGroup>
69+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="Configuration">
70+
<ConfigurationType>Application</ConfigurationType>
71+
<UseDebugLibraries>false</UseDebugLibraries>
72+
<PlatformToolset>v143</PlatformToolset>
73+
<WholeProgramOptimization>true</WholeProgramOptimization>
74+
<CharacterSet>Unicode</CharacterSet>
75+
</PropertyGroup>
76+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
77+
<ImportGroup Label="ExtensionSettings">
78+
</ImportGroup>
79+
<ImportGroup Label="Shared">
80+
</ImportGroup>
81+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
82+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
83+
</ImportGroup>
84+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
85+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
86+
</ImportGroup>
87+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
88+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
89+
</ImportGroup>
90+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'" Label="PropertySheets">
91+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
92+
</ImportGroup>
93+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
94+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
95+
</ImportGroup>
96+
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'" Label="PropertySheets">
97+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
98+
</ImportGroup>
99+
<PropertyGroup Label="UserMacros" />
100+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
101+
<IncludePath>$(XEngine_Include);../../XEngine_Module/jsoncpp;$(IncludePath)</IncludePath>
102+
</PropertyGroup>
103+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
104+
<IncludePath>$(XEngine_Include);$(IncludePath)</IncludePath>
105+
</PropertyGroup>
106+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
107+
<IncludePath>$(XEngine_Include);$(IncludePath)</IncludePath>
108+
</PropertyGroup>
109+
<PropertyGroup Label="Vcpkg" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
110+
<VcpkgUseStatic>true</VcpkgUseStatic>
111+
<VcpkgUseMD>true</VcpkgUseMD>
112+
</PropertyGroup>
113+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
114+
<ClCompile>
115+
<WarningLevel>Level3</WarningLevel>
116+
<SDLCheck>true</SDLCheck>
117+
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
118+
<ConformanceMode>true</ConformanceMode>
119+
</ClCompile>
120+
<Link>
121+
<SubSystem>Console</SubSystem>
122+
<GenerateDebugInformation>true</GenerateDebugInformation>
123+
</Link>
124+
</ItemDefinitionGroup>
125+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
126+
<ClCompile>
127+
<WarningLevel>Level3</WarningLevel>
128+
<FunctionLevelLinking>true</FunctionLevelLinking>
129+
<IntrinsicFunctions>true</IntrinsicFunctions>
130+
<SDLCheck>true</SDLCheck>
131+
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
132+
<ConformanceMode>true</ConformanceMode>
133+
</ClCompile>
134+
<Link>
135+
<SubSystem>Console</SubSystem>
136+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
137+
<OptimizeReferences>true</OptimizeReferences>
138+
<GenerateDebugInformation>true</GenerateDebugInformation>
139+
</Link>
140+
</ItemDefinitionGroup>
141+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
142+
<ClCompile>
143+
<WarningLevel>Level3</WarningLevel>
144+
<SDLCheck>true</SDLCheck>
145+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
146+
<ConformanceMode>true</ConformanceMode>
147+
</ClCompile>
148+
<Link>
149+
<SubSystem>Console</SubSystem>
150+
<GenerateDebugInformation>true</GenerateDebugInformation>
151+
</Link>
152+
</ItemDefinitionGroup>
153+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">
154+
<ClCompile>
155+
<WarningLevel>Level3</WarningLevel>
156+
<SDLCheck>true</SDLCheck>
157+
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
158+
<ConformanceMode>true</ConformanceMode>
159+
</ClCompile>
160+
<Link>
161+
<SubSystem>Console</SubSystem>
162+
<GenerateDebugInformation>true</GenerateDebugInformation>
163+
</Link>
164+
</ItemDefinitionGroup>
165+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
166+
<ClCompile>
167+
<WarningLevel>Level3</WarningLevel>
168+
<FunctionLevelLinking>true</FunctionLevelLinking>
169+
<IntrinsicFunctions>true</IntrinsicFunctions>
170+
<SDLCheck>true</SDLCheck>
171+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
172+
<ConformanceMode>true</ConformanceMode>
173+
</ClCompile>
174+
<Link>
175+
<SubSystem>Console</SubSystem>
176+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
177+
<OptimizeReferences>true</OptimizeReferences>
178+
<GenerateDebugInformation>true</GenerateDebugInformation>
179+
</Link>
180+
</ItemDefinitionGroup>
181+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">
182+
<ClCompile>
183+
<WarningLevel>Level3</WarningLevel>
184+
<FunctionLevelLinking>true</FunctionLevelLinking>
185+
<IntrinsicFunctions>true</IntrinsicFunctions>
186+
<SDLCheck>true</SDLCheck>
187+
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
188+
<ConformanceMode>true</ConformanceMode>
189+
</ClCompile>
190+
<Link>
191+
<SubSystem>Console</SubSystem>
192+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
193+
<OptimizeReferences>true</OptimizeReferences>
194+
<GenerateDebugInformation>true</GenerateDebugInformation>
195+
</Link>
196+
</ItemDefinitionGroup>
197+
<ItemGroup>
198+
<ClCompile Include="AIApi_APPExample.cpp" />
199+
</ItemGroup>
200+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
201+
<ImportGroup Label="ExtensionTargets">
202+
</ImportGroup>
203+
</Project>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="源文件">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="头文件">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="资源文件">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClCompile Include="AIApi_APPExample.cpp">
19+
<Filter>源文件</Filter>
20+
</ClCompile>
21+
</ItemGroup>
22+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup />
4+
</Project>

0 commit comments

Comments
 (0)