remove:删除一个无用文件。
This commit is contained in:
parent
7806473762
commit
9bcf36cd90
@ -24,7 +24,5 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin/${CMAKE_BUILD_TYPE}
|
|||||||
include_directories(3rd)
|
include_directories(3rd)
|
||||||
find_package(CURL REQUIRED)
|
find_package(CURL REQUIRED)
|
||||||
|
|
||||||
#add_executable(deepseek-use1 main.cpp)
|
|
||||||
add_executable(deepseek-use main.cxx zapi.h zapi.cxx jsondata.h jsondata.cxx)
|
add_executable(deepseek-use main.cxx zapi.h zapi.cxx jsondata.h jsondata.cxx)
|
||||||
#target_link_libraries(deepseek-use1 PRIVATE CURL::libcurl)
|
|
||||||
target_link_libraries(deepseek-use PRIVATE CURL::libcurl)
|
target_link_libraries(deepseek-use PRIVATE CURL::libcurl)
|
||||||
|
90
main.cpp
90
main.cpp
@ -1,90 +0,0 @@
|
|||||||
#include <curl/curl.h>
|
|
||||||
#include <iostream>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#include <windows.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// 回调函数,用于接收API响应
|
|
||||||
size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::string* s)
|
|
||||||
{
|
|
||||||
size_t newLength = size * nmemb;
|
|
||||||
try {
|
|
||||||
s->append((char*)contents, newLength);
|
|
||||||
} catch (std::bad_alloc& e) {
|
|
||||||
// 处理内存不足的情况
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return newLength;
|
|
||||||
}
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
SetConsoleOutputCP(CP_UTF8);
|
|
||||||
SetConsoleCP(CP_UTF8);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// DeepSeek API endpoint
|
|
||||||
std::string url = "https://api.deepseek.com/v1/extract";
|
|
||||||
|
|
||||||
// 你的API密钥
|
|
||||||
std::string api_key = "your_api_key_here";
|
|
||||||
|
|
||||||
// 要上传的文件路径
|
|
||||||
std::string file_path = "path/to/your/project.zip";
|
|
||||||
|
|
||||||
// 初始化libcurl
|
|
||||||
CURL* curl;
|
|
||||||
CURLcode res;
|
|
||||||
std::string response_string;
|
|
||||||
|
|
||||||
curl_global_init(CURL_GLOBAL_DEFAULT);
|
|
||||||
curl = curl_easy_init();
|
|
||||||
|
|
||||||
if (curl) {
|
|
||||||
// 设置API URL
|
|
||||||
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
|
||||||
|
|
||||||
// 设置HTTP头
|
|
||||||
struct curl_slist* headers = nullptr;
|
|
||||||
headers = curl_slist_append(headers, ("Authorization: Bearer " + api_key).c_str());
|
|
||||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
|
||||||
|
|
||||||
// 设置POST请求
|
|
||||||
curl_easy_setopt(curl, CURLOPT_POST, 1L);
|
|
||||||
|
|
||||||
// 设置文件上传
|
|
||||||
curl_mime* mime;
|
|
||||||
curl_mimepart* part;
|
|
||||||
mime = curl_mime_init(curl);
|
|
||||||
part = curl_mime_addpart(mime);
|
|
||||||
curl_mime_name(part, "file");
|
|
||||||
curl_mime_filedata(part, file_path.c_str());
|
|
||||||
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
|
|
||||||
|
|
||||||
// 设置回调函数以接收响应
|
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
|
|
||||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response_string);
|
|
||||||
|
|
||||||
// 执行请求
|
|
||||||
res = curl_easy_perform(curl);
|
|
||||||
|
|
||||||
// 检查请求是否成功
|
|
||||||
if (res != CURLE_OK) {
|
|
||||||
std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << std::endl;
|
|
||||||
} else {
|
|
||||||
std::cout << "API Response: " << response_string << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 清理
|
|
||||||
curl_mime_free(mime);
|
|
||||||
curl_easy_cleanup(curl);
|
|
||||||
curl_slist_free_all(headers);
|
|
||||||
}
|
|
||||||
|
|
||||||
curl_global_cleanup();
|
|
||||||
return 0;
|
|
||||||
}
|
|
4
main.cxx
4
main.cxx
@ -27,13 +27,13 @@ int main()
|
|||||||
api->set_base("https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions", api_key);
|
api->set_base("https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions", api_key);
|
||||||
|
|
||||||
// 请求的 JSON 数据
|
// 请求的 JSON 数据
|
||||||
std::string question("DeepSeek R1 API提交附件,如果不支持zip,拿我有多个文件的话,需要一个一个上传吗?");
|
std::string question("对于DeepSeek API,既然对话交互使用的是json格式,那我是否可以把所有的文本内容合并到json中post给deepseek,deepseek有没有说明json格式的数据大小上限值?");
|
||||||
std::string q = json_oper->format_request(question);
|
std::string q = json_oper->format_request(question);
|
||||||
|
|
||||||
std::string recv;
|
std::string recv;
|
||||||
if (api->post(q, recv)) {
|
if (api->post(q, recv)) {
|
||||||
auto re = json_oper->parse(recv);
|
auto re = json_oper->parse(recv);
|
||||||
CJsonOper::save_md(re.message_content + "\n" + re.reasoning_content, re.id);
|
CJsonOper::save_md("**最终结果:**\n\n" + re.message_content + "\n\n **思考过程:** \n" + re.reasoning_content, re.id);
|
||||||
std::cout << "success." << std::endl;
|
std::cout << "success." << std::endl;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user