41 lines
1.0 KiB
C++
41 lines
1.0 KiB
C++
|
|
#include "zapi.h"
|
|
#include <iostream>
|
|
#include <memory>
|
|
#include <string>
|
|
#include "jsondata.h"
|
|
|
|
std::string get_key()
|
|
{
|
|
char* v = getenv("DASHSCOPE_API_KEY");
|
|
if (v) {
|
|
return std::string(v);
|
|
}
|
|
return "";
|
|
}
|
|
|
|
int main()
|
|
{
|
|
std::string api_key = get_key();
|
|
if (api_key.empty()) {
|
|
std::cerr << "api key not found." << std::endl;
|
|
return -1;
|
|
}
|
|
|
|
auto api = std::make_shared<COpenAI>();
|
|
auto json_oper = std::make_shared<CJsonOper>();
|
|
api->set_base("https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions", api_key);
|
|
|
|
// 请求的 JSON 数据
|
|
std::string question("DeepSeek R1 API提交附件,如果不支持zip,拿我有多个文件的话,需要一个一个上传吗?");
|
|
std::string q = json_oper->format_request(question);
|
|
|
|
std::string recv;
|
|
if (api->post(q, recv)) {
|
|
auto re = json_oper->parse(recv);
|
|
CJsonOper::save_md(re.message_content + "\n" + re.reasoning_content, re.id);
|
|
std::cout << "success." << std::endl;
|
|
}
|
|
return 0;
|
|
}
|