Skip to content

Commit

Permalink
Merge branch main into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
rockstareast1 committed Nov 19, 2024
2 parents cf971c9 + 93a4b89 commit 2ac8374
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
14 changes: 12 additions & 2 deletions liboai/components/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,11 @@ std::vector<std::string> liboai::Conversation::SplitFullStreamedData(std::string
}

bool liboai::Conversation::ParseStreamData(std::string data, std::string& delta_content, bool& completed){
if (!_last_incomplete_buffer.empty()) {
data = _last_incomplete_buffer + data;
_last_incomplete_buffer.clear();
}

std::vector<std::string> data_lines = SplitFullStreamedData(data);

if (data_lines.empty()){
Expand Down Expand Up @@ -521,8 +526,13 @@ bool liboai::Conversation::ParseStreamData(std::string data, std::string& delta_
*/
this->RemoveStrings(line, "data: ");

// for (auto& json_object : objects) {
nlohmann::json j = nlohmann::json::parse(line);
nlohmann::json j;
try {
j = nlohmann::json::parse(line);
} catch (const std::exception& e) {
_last_incomplete_buffer = line;
continue;
}

if (j.contains("choices")) {
if (j["choices"][0].contains("delta")) {
Expand Down
1 change: 1 addition & 0 deletions liboai/core/netimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,6 +701,7 @@ void liboai::netimpl::Session::ClearContext() {
url_.clear();
response_string_.clear();
header_string_.clear();
write_ = netimpl::components::WriteCallback{};
}

void liboai::netimpl::Session::ParseResponseHeader(const std::string& headers, std::string* status_line, std::string* reason) {
Expand Down
1 change: 1 addition & 0 deletions liboai/include/components/chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,7 @@ namespace liboai {
nlohmann::json _conversation;
std::optional<nlohmann::json> _functions = std::nullopt;
bool _last_resp_is_fc = false;
std::string _last_incomplete_buffer;
};

class ChatCompletion final : private Network {
Expand Down

0 comments on commit 2ac8374

Please sign in to comment.