Skip to content

Commit b967840

Browse files
modify
1 parent 00aeab4 commit b967840

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

include/openai/openai.hpp

+37-2
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ class OpenAI {
507507
std::cerr << "Response is not a valid JSON\n";
508508
std::cout << "<< " << response.text<< "\n";
509509
#endif
510+
json = Json{{"Result", response.text}};
510511
}
511512
return json;
512513
}
@@ -888,8 +889,25 @@ inline Json CategoryChat::create(Json input) {
888889
// POST https://api.openai.com/v1/audio/transcriptions
889890
// Transcribes audio into the input language.
890891
inline Json CategoryAudio::transcribe(Json input) {
892+
auto lambda = [input]() -> std::map<std::string, std::string> {
893+
std::map<std::string, std::string> temp;
894+
temp.insert({"model", input["model"].get<std::string>()});
895+
if (input.contains("language")) {
896+
temp.insert({"language", input["language"].get<std::string>()});
897+
}
898+
if (input.contains("prompt")) {
899+
temp.insert({"prompt", input["prompt"].get<std::string>()});
900+
}
901+
if (input.contains("response_format")) {
902+
temp.insert({"response_format", input["response_format"].get<std::string>()});
903+
}
904+
if (input.contains("temperature")) {
905+
temp.insert({"temperature", std::to_string(input["temperature"].get<float>())});
906+
}
907+
return temp;
908+
};
891909
openai_.setMultiformPart({"file", input["file"].get<std::string>()},
892-
std::map<std::string, std::string>{{"model", input["model"].get<std::string>()}}
910+
lambda()
893911
);
894912

895913
return openai_.post("audio/transcriptions", std::string{""}, "multipart/form-data");
@@ -898,8 +916,25 @@ inline Json CategoryAudio::transcribe(Json input) {
898916
// POST https://api.openai.com/v1/audio/translations
899917
// Translates audio into into English..
900918
inline Json CategoryAudio::translate(Json input) {
919+
auto lambda = [input]() -> std::map<std::string, std::string> {
920+
std::map<std::string, std::string> temp;
921+
temp.insert({"model", input["model"].get<std::string>()});
922+
if (input.contains("language")) {
923+
temp.insert({"language", input["language"].get<std::string>()});
924+
}
925+
if (input.contains("prompt")) {
926+
temp.insert({"prompt", input["prompt"].get<std::string>()});
927+
}
928+
if (input.contains("response_format")) {
929+
temp.insert({"response_format", input["response_format"].get<std::string>()});
930+
}
931+
if (input.contains("temperature")) {
932+
temp.insert({"temperature", std::to_string(input["temperature"].get<float>())});
933+
}
934+
return temp;
935+
};
901936
openai_.setMultiformPart({"file", input["file"].get<std::string>()},
902-
std::map<std::string, std::string>{{"model", input["model"].get<std::string>()}}
937+
lambda()
903938
);
904939

905940
return openai_.post("audio/translations", std::string{""}, "multipart/form-data");

0 commit comments

Comments
 (0)