Felipe97/llama-cpp-compiled
01.1k
1#pragma once2 3#include "common.h"4 5#include "cli-client.h"6#include "cli-server.h"7 8#include <atomic>9#include <memory>10#include <optional>11#include <string>12#include <fstream>13 14struct cli_timings {15 double prompt_per_second = 0.0;16 double predicted_per_second = 0.0;17};18 19struct cli_context_impl;20 21struct cli_context {22 common_params params;23 24 cli_client client; // always initialized25 std::optional<cli_server> server; // only set when no --server-base is given26 27 // properties of the connected server28 // will be populated by fetch_server_props()29 std::string model_name;30 std::string model_ftype;31 std::string build_info;32 bool has_vision = false;33 bool has_audio = false;34 bool has_video = false;35 36 std::optional<std::ofstream> output_file;37 38 cli_context(const common_params & params);39 ~cli_context();40 41 // connect to --server-base or spawn a local llama-server child;42 // argc/argv are needed to forward the server-relevant args to the child43 bool init();44 45 // run the interactive chat loop, returns the process exit code46 int run();47 48 // stop the local server child (if any)49 void shutdown();50 51 // set by the SIGINT handler; cleared once the interrupt has been handled52 static std::atomic<bool> & interrupted();53 54private:55 struct generated_content {56 std::string reasoning;57 std::string content;58 };59 bool generate_completion(generated_content & content_out, cli_timings & timings);60 void fetch_server_props();61 void add_system_prompt();62 void push_user_message(const std::string & text);63 64 // check if server have multiple models (router mode)65 // if yes, list them then ask; do nothing otherwise66 bool list_and_ask_models();67 68 // read a file and stage it as a multimodal content part; type is one of69 // "image", "audio", "video"; returns false if the file cannot be read70 bool stage_media_file(const std::string & fname, const std::string & type);71 72 // no-op if output file is not set73 void write_output_file(const std::string & content);74 75 std::unique_ptr<cli_context_impl> impl;76};77 