-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: responses from /chat/completions endpoint contain a leading spac…
…e in the content (#488) Co-authored-by: vansangpfiev <sang@jan.ai>
- Loading branch information
1 parent
4419a4d
commit f64a90f
Showing
10 changed files
with
183 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
add_subdirectory(components) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
file(GLOB SRCS *.cc) | ||
project(test-components) | ||
|
||
enable_testing() | ||
|
||
add_executable(${PROJECT_NAME} ${SRCS}) | ||
|
||
find_package(Drogon CONFIG REQUIRED) | ||
find_package(GTest CONFIG REQUIRED) | ||
|
||
target_link_libraries(${PROJECT_NAME} PRIVATE Drogon::Drogon GTest::gtest GTest::gmock | ||
${CMAKE_THREAD_LIBS_INIT}) | ||
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../) | ||
|
||
add_test(NAME ${PROJECT_NAME} | ||
COMMAND ${PROJECT_NAME}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include "gtest/gtest.h" | ||
#include <drogon/HttpAppFramework.h> | ||
#include <drogon/drogon.h> | ||
|
||
int main(int argc, char **argv) { | ||
::testing::InitGoogleTest(&argc, argv); | ||
int ret = RUN_ALL_TESTS(); | ||
return ret; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "gtest/gtest.h" | ||
#include "models/chat_completion_request.h" | ||
|
||
using inferences::ChatCompletionRequest; | ||
|
||
class ModelTest : public ::testing::Test { | ||
}; | ||
|
||
|
||
TEST_F(ModelTest, should_parse_request) { | ||
{ | ||
Json::Value data; | ||
auto req = drogon::HttpRequest::newHttpJsonRequest(data); | ||
|
||
auto res = | ||
drogon::fromRequest<inferences::ChatCompletionRequest>(*req.get()); | ||
|
||
EXPECT_EQ(res.stream, false); | ||
EXPECT_EQ(res.max_tokens, 500); | ||
EXPECT_EQ(res.top_p, 0.95f); | ||
EXPECT_EQ(res.temperature, 0.8f); | ||
EXPECT_EQ(res.frequency_penalty, 0); | ||
EXPECT_EQ(res.presence_penalty, 0); | ||
EXPECT_EQ(res.stop, Json::Value{}); | ||
EXPECT_EQ(res.messages, Json::Value{}); | ||
} | ||
|
||
{ | ||
Json::Value data; | ||
data["stream"] = true; | ||
data["max_tokens"] = 400; | ||
data["top_p"] = 0.8; | ||
data["temperature"] = 0.7; | ||
data["frequency_penalty"] = 0.1; | ||
data["presence_penalty"] = 0.2; | ||
data["messages"] = "message"; | ||
data["stop"] = "stop"; | ||
|
||
auto req = drogon::HttpRequest::newHttpJsonRequest(data); | ||
|
||
auto res = | ||
drogon::fromRequest<inferences::ChatCompletionRequest>(*req.get()); | ||
|
||
EXPECT_EQ(res.stream, true); | ||
EXPECT_EQ(res.max_tokens, 400); | ||
EXPECT_EQ(res.top_p, 0.8f); | ||
EXPECT_EQ(res.temperature, 0.7f); | ||
EXPECT_EQ(res.frequency_penalty, 0.1f); | ||
EXPECT_EQ(res.presence_penalty, 0.2f); | ||
EXPECT_EQ(res.stop, Json::Value{"stop"}); | ||
EXPECT_EQ(res.messages, Json::Value{"message"}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "gtest/gtest.h" | ||
#include "utils/nitro_utils.h" | ||
|
||
class NitroUtilTest : public ::testing::Test { | ||
}; | ||
|
||
TEST_F(NitroUtilTest, left_trim) { | ||
{ | ||
std::string empty; | ||
nitro_utils::ltrim(empty); | ||
EXPECT_EQ(empty, ""); | ||
} | ||
|
||
{ | ||
std::string s = "abc"; | ||
std::string expected = "abc"; | ||
nitro_utils::ltrim(s); | ||
EXPECT_EQ(s, expected); | ||
} | ||
|
||
{ | ||
std::string s = " abc"; | ||
std::string expected = "abc"; | ||
nitro_utils::ltrim(s); | ||
EXPECT_EQ(s, expected); | ||
} | ||
|
||
{ | ||
std::string s = "1 abc 2 "; | ||
std::string expected = "1 abc 2 "; | ||
nitro_utils::ltrim(s); | ||
EXPECT_EQ(s, expected); | ||
} | ||
|
||
{ | ||
std::string s = " |abc"; | ||
std::string expected = "|abc"; | ||
nitro_utils::ltrim(s); | ||
EXPECT_EQ(s, expected); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters