Skip to content

Commit

Permalink
add seed for chat completion
Browse files Browse the repository at this point in the history
  • Loading branch information
pkusunjy committed Aug 6, 2024
1 parent 5703cc7 commit a8101f1
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions liboai/components/chat.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include <ctime>
#include <random>

#include "../include/components/chat.h"

liboai::Conversation::Conversation() {
Expand Down Expand Up @@ -602,6 +605,11 @@ liboai::Response liboai::ChatCompletion::create(const std::string& model, Conver
jcon.push_back("logit_bias", std::move(logit_bias));
jcon.push_back("user", std::move(user));

// generate seed
std::mt19937 rng(static_cast<uint32_t>(std::time(nullptr)));
std::uniform_int_distribution<int32_t> dist(1, 10000);
jcon.push_back("seed", dist(rng));

if (function_call) {
if (function_call.value() == "none" || function_call.value() == "auto") {
nlohmann::json j; j["function_call"] = function_call.value();
Expand Down Expand Up @@ -660,6 +668,11 @@ liboai::FutureResponse liboai::ChatCompletion::create_async(const std::string& m
jcon.push_back("logit_bias", std::move(logit_bias));
jcon.push_back("user", std::move(user));

// generate seed
std::mt19937 rng(static_cast<uint32_t>(std::time(nullptr)));
std::uniform_int_distribution<int32_t> dist(1, 10000);
jcon.push_back("seed", dist(rng));

if (function_call) {
if (function_call.value() == "none" || function_call.value() == "auto") {
nlohmann::json j; j["function_call"] = function_call.value();
Expand Down

0 comments on commit a8101f1

Please sign in to comment.