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

Conversation

@louis-jan
Copy link
Contributor

@louis-jan louis-jan commented Feb 29, 2024

Descriptions

Should not handle request body from controller's handler otherwise it bloats the controller implementation
#453

#pragma once
#include <drogon/HttpController.h>

namespace inferences {
struct ChatCompletionRequest {
  bool stream = false;
  int max_tokens = 500;
  float top_p = 0.95;
  float temperature = 0.8;
  float frequency_penalty = 0;
  float presence_penalty = 0;
  Json::Value stop = Json::Value(Json::arrayValue);
  Json::Value messages = Json::Value(Json::arrayValue);
};
}  // namespace inferences

namespace drogon {
template <>
inline inferences::ChatCompletionRequest fromRequest(const HttpRequest& req) {
  auto jsonBody = req.getJsonObject();
  inferences::ChatCompletionRequest completion;
  if (jsonBody) {
    completion.stream = (*jsonBody).get("stream", false).asBool();
    completion.max_tokens = (*jsonBody).get("max_tokens", 500).asInt();
    completion.top_p = (*jsonBody).get("top_p", 0.95).asFloat();
    completion.temperature = (*jsonBody).get("temperature", 0.8).asFloat();
    completion.frequency_penalty =
        (*jsonBody).get("frequency_penalty", 0).asFloat();
    completion.presence_penalty =
        (*jsonBody).get("presence_penalty", 0).asFloat();
    completion.messages = (*jsonBody)["messages"];
    completion.stop = (*jsonBody)["stop"];
  }
  return completion;
}
}  // namespace inferences 
  // There is no longer HttpRequestPtr presented from handler, just the model
  void ChatCompletion(
      inferences::ChatCompletionRequest &&completion,
      std::function<void(const HttpResponsePtr&)>&& callback) override;

@louis-jan louis-jan force-pushed the refactor/parameters-mapping-entity branch from 48e7011 to 73b3a75 Compare February 29, 2024 02:36
@louis-jan louis-jan requested a review from tikikun February 29, 2024 02:38
@louis-jan louis-jan changed the base branch from refactor/llama-server-context-should-not-be-in-controller to main February 29, 2024 02:40
Copy link
Contributor

@tikikun tikikun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tikikun tikikun merged commit 4cc64f3 into main Feb 29, 2024
@louis-jan louis-jan deleted the refactor/parameters-mapping-entity branch May 24, 2024 03:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants