Skip to content

Commit

Permalink
Resolve git-clang
Browse files Browse the repository at this point in the history
  • Loading branch information
tharun571 committed Jul 29, 2024
1 parent 6514175 commit 0e90e61
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/xmagics/xassist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ namespace xcpp
class ChatHistory
{
public:

static std::string chat(const std::string& model, const std::string& user, const std::string& cell)
{
return appendAndReadBack(model, user, "\"" + cell + "\"");
Expand All @@ -80,8 +81,9 @@ namespace xcpp

private:

static std::string appendAndReadBack(const std::string& model, const std::string& user, const std::string& serializedCell)
{
static std::string
appendAndReadBack(const std::string& model, const std::string& user, const std::string& serializedCell)
{
std::string chatHistoryFilePath = model + "_chat_history.txt";
std::ofstream out;
bool isEmpty = isFileEmpty(chatHistoryFilePath);
Expand All @@ -98,7 +100,7 @@ namespace xcpp
out << ", ";
}

if(model == "gemini")
if (model == "gemini")
{
out << "{ \"role\": \"" << user << R"(", "parts": [ { "text": )" << serializedCell << "}]}\n";
}
Expand All @@ -115,9 +117,9 @@ namespace xcpp
static bool isFileEmpty(const std::string& filePath)
{
std::ifstream file(filePath, std::ios::ate); // Open the file at the end
if (!file) // If the file cannot be opened, it might not exist
if (!file) // If the file cannot be opened, it might not exist
{
return true; // Consider non-existent files as empty
return true; // Consider non-existent files as empty
}
return file.tellg() == 0;
}
Expand Down Expand Up @@ -219,7 +221,11 @@ namespace xcpp
return "";
}

const std::string chat = xcpp::ChatHistory::chat("gemini", "model", j["candidates"][0]["content"]["parts"][0]["text"]);
const std::string chat = xcpp::ChatHistory::chat(
"gemini",
"model",
j["candidates"][0]["content"]["parts"][0]["text"]
);

return j["candidates"][0]["content"]["parts"][0]["text"];
}
Expand All @@ -231,7 +237,8 @@ namespace xcpp
const std::string chatMessage = xcpp::ChatHistory::chat("openai", "user", cell);
const std::string postData = R"({
"model": "gpt-3.5-turbo-16k",
"messages": [)" + chatMessage + R"(],
"messages": [)" + chatMessage
+ R"(],
"temperature": 0.7
})";
std::string authHeader = "Authorization: Bearer " + key;
Expand All @@ -246,7 +253,11 @@ namespace xcpp
return "";
}

const std::string chat = xcpp::ChatHistory::chat("openai", "assistant", j["choices"][0]["message"]["content"]);
const std::string chat = xcpp::ChatHistory::chat(
"openai",
"assistant",
j["choices"][0]["message"]["content"]
);

return j["choices"][0]["message"]["content"];
}
Expand Down Expand Up @@ -274,8 +285,8 @@ namespace xcpp
{
xcpp::APIKeyManager::saveApiKey(model, cell);
return;
}
}

if (tokens[2] == "--refresh")
{
xcpp::ChatHistory::refresh(model);
Expand Down

0 comments on commit 0e90e61

Please sign in to comment.