Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more parameters to server api #1754

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions examples/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,13 @@ std::string output_str(struct whisper_context * ctx, const whisper_params & para
return result.str();
}

bool parse_str_to_bool(const std::string & s) {
if (s == "true" || s == "1" || s == "yes" || s == "y") {
return true;
}
return false;
}

void get_req_parameters(const Request & req, whisper_params & params)
{
if (req.has_file("offset_t"))
Expand All @@ -415,6 +422,62 @@ void get_req_parameters(const Request & req, whisper_params & params)
{
params.max_context = std::stoi(req.get_file_value("max_context").content);
}
if (req.has_file("max_len"))
{
params.max_len = std::stoi(req.get_file_value("max_len").content);
}
if (req.has_file("best_of"))
{
params.best_of = std::stoi(req.get_file_value("best_of").content);
}
if (req.has_file("beam_size"))
{
params.beam_size = std::stoi(req.get_file_value("beam_size").content);
}
if (req.has_file("word_thold"))
{
params.word_thold = std::stof(req.get_file_value("word_thold").content);
}
if (req.has_file("entropy_thold"))
{
params.entropy_thold = std::stof(req.get_file_value("entropy_thold").content);
}
if (req.has_file("logprob_thold"))
{
params.logprob_thold = std::stof(req.get_file_value("logprob_thold").content);
}
if (req.has_file("debug_mode"))
{
params.debug_mode = parse_str_to_bool(req.get_file_value("debug_mode").content);
}
if (req.has_file("translate"))
{
params.translate = parse_str_to_bool(req.get_file_value("translate").content);
}
if (req.has_file("diarize"))
{
params.diarize = parse_str_to_bool(req.get_file_value("diarize").content);
}
if (req.has_file("tinydiarize"))
{
params.tinydiarize = parse_str_to_bool(req.get_file_value("tinydiarize").content);
}
if (req.has_file("split_on_word"))
{
params.split_on_word = parse_str_to_bool(req.get_file_value("split_on_word").content);
}
if (req.has_file("no_timestamps"))
{
params.no_timestamps = parse_str_to_bool(req.get_file_value("no_timestamps").content);
}
if (req.has_file("language"))
{
params.language = req.get_file_value("language").content;
}
if (req.has_file("detect_language"))
{
params.detect_language = parse_str_to_bool(req.get_file_value("detect_language").content);
}
if (req.has_file("prompt"))
{
params.prompt = req.get_file_value("prompt").content;
Expand Down Expand Up @@ -482,6 +545,9 @@ int main(int argc, char ** argv) {

std::string const default_content = "<html>hello</html>";

// store default params so we can reset after each inference request
whisper_params default_params = params;

// this is only called if no index.html is found in the public --path
svr.Get(sparams.request_path + "/", [&default_content](const Request &, Response &res){
res.set_content(default_content, "text/html");
Expand Down Expand Up @@ -722,6 +788,9 @@ int main(int argc, char ** argv) {
"application/json");
}

// reset params to thier defaults
params = default_params;

// return whisper model mutex lock
whisper_mutex.unlock();
});
Expand Down
Loading