我们使用轻量开发环境aardio,体积只有几MB,下载就可以编程,不需要任何复杂的配置。调用ChatGPT接口 打开aardio,点左上角新建控制台按钮: 创建一个控制台程序: 输入下面的代码调用OpenAI接口:importconsole。int;importweb。rest。jsonClient;创建API客户端varhttpweb。rest。jsonClient();设置Key或者获取Key的网址。http。setAuthToken(http:api。aardio。comdemoopenaitoken);引入OpenAI接口varaihttp。api(https:api。openai。comv1);调用APIvarretai。completions({prompt:现在几点了,发送问题model:textdavinci003,模型temperature:0。8,热度,01之间。maxtokens:2048,最大允许的字符数量})显示回复console。log(ret。choices〔1〕。text) aardio调用WebAPI接口的代码非常简单,甚至不需要封装OpenAI扩展库。实现ChatGPT桌面智能助理 为了生成体积更小的独立EXE程序,我们调用系统自带的WebView2,并且用ReactChatUI实现界面,几句代码就可以搞定。 首先在aardio中创建WebView2工程: 然后在main。aardio中输入下面源代码:importwin。ui;DSG{{varwinformwin。form(textChatGPT桌面助理)}}importweb。view;varwbweb。view(winform);importweb。rest。jsonClient;varhttpweb。rest。jsonClient();http。setAuthToken(http:api。aardio。comdemoopenaitoken);varaihttp。api(https:api。openai。comv1);wb。external{askfunction(prompt){varretai。completions({prompt:prompt,发送问题model:textdavinci003,模型temperature:0。8,热度,01之间。maxtokens:2048,最大允许的字符数量})if(ret)returnret。choices〔1〕。text;};}wb。html!DOCTYPEhtmlhtmlheadmetacharsetutf8titleWebView2titlelinkrelstylesheethrefhttps:lib。baomitu。comchatuicore2。4。2index。min。cssstyletypetextcsshtml,body,app{height:100}styleheadbodywinform。show();win。loopMessage(); 点击发布就可以生成独立EXE程序了。 程序运行界面如下: 请注意上面源码中的key仅供测试(网址返回的key是临时性的),请替换为自己申请的key。网上有很多ChatGPI注册教程,注册非常简单,参考教程注册以后可以申请免费key。