-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase_chat.cpp
45 lines (36 loc) · 1.29 KB
/
base_chat.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "openai.hpp"
#include <iostream>
std::string api_key = "your_api_key";
std::string base_url = "base_url";
int main() {
OpenAI client(api_key, base_url);
std::vector<ChatCompletion::Message> messages = {
ChatCompletion::Message::system("You are a helpful assistant")
};
std::string user_input;
while (true) {
// Get user input
std::cout << "\nYou: ";
std::getline(std::cin, user_input);
// Check for exit condition
if (user_input == "exit" || user_input == "quit") {
break;
}
// Add user message to history
messages.push_back(ChatCompletion::Message::user(user_input));
// Updated API call
auto response = client.chat.completions.create(
ChatCompletion::CreateParams()
.model("deepseek-chat")
.messages(messages)
.max_tokens(1024)
.temperature(0.7)
);
// Print AI response
std::string ai_response = response.choices[0].message.content;
std::cout << "\nAssistant: " << ai_response << std::endl;
// Add AI response to history
messages.push_back(ChatCompletion::Message::assistant(ai_response));
}
return 0;
}