Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

refactor: move context struct out of controllers #454

@louis-jan

Description

@louis-jan

Problem
These context structs are not relevant to the controllers.

struct whisper_server_context {
  whisper_params params;
  whisper_params default_params;
  std::mutex whisper_mutex;
  std::string model_id;

  struct whisper_context_params cparams;
  struct whisper_context* ctx = nullptr;

  whisper_server_context() = default;  // add this line

  // Constructor
  whisper_server_context(const std::string& model_id) {
    this->model_id = model_id;
    this->cparams = whisper_context_params();
    this->ctx = nullptr;
    // store default params so we can reset after each inference request
    this->default_params = whisper_params();
    this->params = whisper_params();
  }

  // Move constructor
  whisper_server_context(whisper_server_context&& other) noexcept
      : params(std::move(other.params)),
        default_params(std::move(other.default_params)),
        whisper_mutex()  // std::mutex is not movable, so we initialize a new one
        ,
        model_id(std::move(other.model_id)),
        cparams(std::move(other.cparams)),
        ctx(std::exchange(
            other.ctx,
            nullptr))  // ctx is a raw pointer, so we use std::exchange
  {}

  bool load_model(std::string& model_path);

  std::string inference(std::string& input_file_path, std::string languague,
                        std::string prompt, std::string response_format,
                        float temperature, bool translate);

  ~whisper_server_context();
};

using namespace drogon;

namespace audio {
class whisperCPP : public drogon::HttpController<whisperCPP>,
                   public BaseModel,
                   public BaseAudio {

Success Criteria
Move to /context folder

Additional context
Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions