forked from olrea/openai-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
06-file.cpp
37 lines (28 loc) · 1.05 KB
/
06-file.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "openai.hpp"
#include <iostream>
int main() {
openai::start();
// Upload file
auto upload = openai::file().upload({
{"file", "finetune1.jsonl"},
{"purpose", "fine-tune"}
});
std::cout << upload.dump(2) << "\n\n";
std::string uploaded_file_id = upload["id"].get<std::string>(); // retrieve file id of uploaded file file-....
// List files
auto files = openai::file().list();
std::cout << files.dump(2) << "\n\n";
// Retrieve file
auto retrieve = openai::file().retrieve(uploaded_file_id); // file-....
std::cout << retrieve.dump(2) << "\n\n";
// Retrieve file content
try {
auto content = openai::file().content(uploaded_file_id); // file-....
std::cout << content.dump(2) << "\n\n";
} catch(std::exception const& e) {
std::cerr << "You might have this exception because you have a free account " << e.what() << "\n\n";
}
// Delete file
auto deletion = openai::file().del(uploaded_file_id);
std::cout << deletion.dump(2) << "\n\n";
}