SHA256
58 lines
1.1 KiB
C++
58 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace r1_voice {
|
|
|
|
struct ChatMessage {
|
|
std::string role;
|
|
std::string content;
|
|
};
|
|
|
|
struct LlmConfig {
|
|
std::string url =
|
|
"http://127.0.0.1:8080/v1/chat/completions";
|
|
|
|
std::string model = "local";
|
|
|
|
float temperature = 0.7f;
|
|
|
|
int max_tokens = 256;
|
|
|
|
std::string system_prompt =
|
|
"You are R1, a humanoid robot conversational assistant. "
|
|
"Talk naturally with the person in front of you. "
|
|
"Keep answers reasonably short because they will be spoken aloud. "
|
|
"Answer in the same language as the user. "
|
|
"Do not use markdown unless necessary.";
|
|
};
|
|
|
|
class LLM {
|
|
public:
|
|
explicit LLM(LlmConfig config);
|
|
|
|
std::string chat(
|
|
const std::string& user
|
|
);
|
|
|
|
private:
|
|
LlmConfig config_;
|
|
|
|
std::vector<ChatMessage> history_;
|
|
|
|
std::string escapeJson(
|
|
const std::string& text
|
|
) const;
|
|
|
|
std::string parseContent(
|
|
const std::string& json
|
|
) const;
|
|
|
|
std::string httpPost(
|
|
const std::string& body
|
|
) const;
|
|
};
|
|
|
|
} // namespace r1_voice
|