Skip to content

Commit 182f53b

Browse files
committed
update:ai example
1 parent a6adfb0 commit 182f53b

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

XEngine_Example/AIApi_APPExample/AIApi_APPExample.cpp

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,86 @@ void XCALLBACK XEngine_AIApi_CBRecv(XNETHANDLE xhToken, LPCXSTR lpszModelName, L
4545
}
4646
}
4747

48+
int Test_CreateImage()
49+
{
50+
XNETHANDLE xhToken = 0;
51+
52+
LPCXSTR lpszAPIUrl = _X("https://ark.cn-beijing.volces.com/api/v3/images/generations");
53+
LPCXSTR lpszAPIKey = _X("d68056c1-1faa-438e-8476-1");
54+
LPCXSTR lpszAPIModel = _X("doubao-seedream-3-0-t2i-250415");
55+
56+
if (!AIApi_Vision_Create(&xhToken, lpszAPIUrl, lpszAPIKey, XEngine_AIApi_CBRecv))
57+
{
58+
printf("AIApi_Vision_Create:%lX\n", AIApi_GetLastError());
59+
return 0;
60+
}
61+
62+
LPCXSTR lpszMSGBuffer = _X("生成一张图片:鱼眼镜头,一只猫咪的头部,画面呈现出猫咪的五官因为拍摄方式扭曲的效果。");
63+
int nMSGLen = strlen(lpszMSGBuffer);
64+
65+
int nImageSize = 0;
66+
XCHAR* ptszMSGBuffer = NULL;
67+
if (!AIApi_Vision_ExcuteCrete(xhToken, lpszAPIModel, _X("1024x1024"), lpszMSGBuffer, nMSGLen, &ptszMSGBuffer, &nImageSize, false))
68+
{
69+
printf("AIApi_Vision_ExcuteCrete:%lX\n", AIApi_GetLastError());
70+
return 0;
71+
}
72+
AIApi_Help_Base64DecodecFile(ptszMSGBuffer, nImageSize, _X("D:\\ai_create.png"));
73+
AIApi_Vision_Destory(xhToken);
74+
return 1;
75+
}
76+
int Test_ParseImage()
77+
{
78+
XNETHANDLE xhToken = 0;
79+
80+
LPCXSTR lpszAPIUrl = _X("https://ark.cn-beijing.volces.com/api/v3/chat/completions");
81+
LPCXSTR lpszAPIKey = _X("d68056c1-1faa-438e-8476-1");
82+
LPCXSTR lpszAPIModel = _X("doubao-1-5-vision-pro-32k-250115");
83+
84+
if (!AIApi_Vision_Create(&xhToken, lpszAPIUrl, lpszAPIKey, XEngine_AIApi_CBRecv))
85+
{
86+
printf("AIApi_Vision_Create:%lX\n", AIApi_GetLastError());
87+
return 0;
88+
}
89+
90+
LPCXSTR lpszMSGBuffer = _X("请描述下这个图片内容?");
91+
int nMSGLen = strlen(lpszMSGBuffer);
92+
93+
if (true)
94+
{
95+
LPCXSTR lpszFileName = _X("D:\\20240419102308.png");
96+
97+
int nMSGLen = 0;
98+
XCHAR* ptszMSGBuffer = NULL;
99+
AIApi_Help_Base64EncodecFile(lpszFileName, &ptszMSGBuffer, &nMSGLen);
100+
if (!AIApi_Vision_ExcuteParse(xhToken, lpszAPIModel, ptszMSGBuffer, lpszMSGBuffer, nMSGLen, true))
101+
{
102+
printf("AIApi_Vision_ExcuteParse:%lX\n", AIApi_GetLastError());
103+
return 0;
104+
}
105+
free(ptszMSGBuffer);
106+
}
107+
else
108+
{
109+
LPCXSTR lpszUrlBuffer = _X("https://www.xyry.org/XEngine_StructPic/EngineFrameWork.png");
110+
if (!AIApi_Vision_ExcuteParse(xhToken, lpszAPIModel, lpszUrlBuffer, lpszMSGBuffer, nMSGLen, true))
111+
{
112+
printf("AIApi_Vision_ExcuteParse:%lX\n", AIApi_GetLastError());
113+
return 0;
114+
}
115+
}
116+
117+
bool bCompleted = false;
118+
AIApi_Vision_GetStatus(xhToken, &bCompleted);
119+
AIApi_Vision_Destory(xhToken);
120+
return 1;
121+
}
48122
int Test_Think()
49123
{
50124
XNETHANDLE xhToken = 0;
51125

52126
LPCXSTR lpszAPIUrl = _X("https://ark.cn-beijing.volces.com/api/v3/chat/completions");
53-
LPCXSTR lpszAPIKey = _X("1");
127+
LPCXSTR lpszAPIKey = _X("d68056c1-1faa-438e-8476-1");
54128
LPCXSTR lpszAPIModel = _X("doubao-seed-1-6-thinking-250615");
55129

56130
if (!AIApi_Chat_Create(&xhToken, lpszAPIUrl, lpszAPIKey, XEngine_AIApi_CBRecv))
@@ -123,6 +197,8 @@ int Test_Chat()
123197
}
124198
int main()
125199
{
200+
Test_CreateImage();
201+
Test_ParseImage();
126202
Test_Think();
127203
Test_Chat();
128204
return 0;

0 commit comments

Comments
 (0)