MCPcopy Create free account
hub / github.com/LagPixelLOL/ChatGPTCLIBot / get_key_from_console

Function get_key_from_console

main/interface/network/APIKey.cpp:14–34  ·  view source on GitHub ↗

* Get the API key from console. * @return The API key. */

Source from the content-addressed store, hash-verified

12 * @return The API key.
13 */
14 std::string get_key_from_console(const std::string& api_base_url) {
15 std::string api_key;
16 while (true) {
17 std::cout << "Please enter your OpenAI API key: ";
18 getline(std::cin, api_key);
19 APIKeyStatus status = check_key(api_key, api_base_url);
20 if (status == APIKeyStatus::VALID) {
21 util::println_info("API key is valid.");
22 break;
23 } else if (status == APIKeyStatus::EMPTY) {
24 util::println_warn("API key cannot be empty, please try again.");
25 } else if (status == APIKeyStatus::QUOTA_EXCEEDED) {
26 util::println_warn("This API key has exceeded its quota, please try again.");
27 } else if (status == APIKeyStatus::INVALID_KEY) {
28 util::println_warn("API key is invalid, please try again.");
29 } else if (status == APIKeyStatus::API_REQUEST_FAILED) {
30 util::println_warn("API request failed, please try again.");
31 }
32 }
33 return api_key;
34 }
35
36 size_t get_key_count() {
37 return api_keys_.size();

Callers 1

p_check_set_api_keyFunction · 0.85

Calls 3

check_keyFunction · 0.85
println_infoFunction · 0.85
println_warnFunction · 0.85

Tested by

no test coverage detected