{"id":19225963,"url":"https://github.com/developer239/llama-chat","last_synced_at":"2025-10-08T21:15:47.608Z","repository":{"id":250462481,"uuid":"834075447","full_name":"developer239/llama-chat","owner":"developer239","description":null,"archived":false,"fork":false,"pushed_at":"2024-09-26T23:56:38.000Z","size":49,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-04T21:33:01.932Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/developer239.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-26T11:12:15.000Z","updated_at":"2024-09-26T23:56:42.000Z","dependencies_parsed_at":"2024-11-09T15:17:01.233Z","dependency_job_id":null,"html_url":"https://github.com/developer239/llama-chat","commit_stats":null,"previous_names":["developer239/llama-wrapped-cmake","developer239/llama-chat"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developer239%2Fllama-chat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developer239%2Fllama-chat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developer239%2Fllama-chat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developer239%2Fllama-chat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/developer239","download_url":"https://codeload.github.com/developer239/llama-chat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240298848,"owners_count":19779346,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T15:16:55.774Z","updated_at":"2025-10-08T21:15:42.563Z","avatar_url":"https://github.com/developer239.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LlamaChat 🦙🦙🦙\n\nLlamaChat is a C++ library designed for running language models using the [llama.cpp](https://github.com/ggerganov/llama.cpp) framework. It provides an easy-to-use interface for loading models, querying them, and streaming responses in C++ applications.\n\n**Supported Systems:**\n\n- MacOS\n- Windows\n- Linux\n\n## Installation\n\n### Add LlamaChat as a Submodule\n\nFirst, add this library as a submodule in your project:\n\n```bash\n$ git submodule add https://github.com/developer239/llama-chat externals/llama-chat\n```\n\nLoad the module's dependencies:\n\n```bash\n$ git submodule update --init --recursive\n```\n\n### Update Your CMake\n\nIn your project's `CMakeLists.txt`, add the following lines to include and link the LlamaChat library:\n\n```cmake\nadd_subdirectory(externals/llama-chat)\ntarget_link_libraries(\u003cyour_target\u003e PRIVATE LlamaChat)\n```\n\n## Usage\n\n### Basic Usage\n\nTo use the LlamaChat library, include the header and create an instance of the `LlamaChat` class. You can initialize the model and context separately, then run queries or stream responses.\n\n```cpp\n#include \"llama-chat.h\"\n#include \u003ciostream\u003e\n\nint main() {\n    LlamaChat llama;\n    \n    ModelParams modelParams;\n    modelParams.nGpuLayers = 32;  // Adjust based on your GPU capabilities\n    \n    if (!llama.InitializeModel(\"path/to/model\", modelParams)) {\n        std::cerr \u003c\u003c \"Failed to initialize the model.\" \u003c\u003c std::endl;\n        return 1;\n    }\n    \n    ContextParams ctxParams;\n    ctxParams.nContext = 2048;\n    \n    if (!llama.InitializeContext(ctxParams)) {\n        std::cerr \u003c\u003c \"Failed to initialize the context.\" \u003c\u003c std::endl;\n        return 1;\n    }\n\n    std::string systemPrompt = \"You are a helpful AI assistant.\";\n    llama.SetSystemPrompt(systemPrompt);\n\n    std::string userMessage = \"How do I write hello world in C++?\";\n\n    llama.Prompt(userMessage, [](const std::string\u0026 piece) {\n        std::cout \u003c\u003c piece \u003c\u003c std::flush;\n    });\n\n    return 0;\n}\n```\n\n### Streaming Responses\n\nThe `Prompt` method implements streaming responses by providing a callback function. This is useful for long outputs.\n\n## API Reference\n\n### LlamaChat Class\n\nThe `LlamaChat` class provides methods to interact with language models loaded through llama.cpp.\n\n#### Public Methods\n\n- `LlamaChat()`: Constructor. Initializes the LlamaChat object.\n- `~LlamaChat()`: Destructor. Cleans up resources.\n- `bool InitializeModel(const std::string\u0026 modelPath, const ModelParams\u0026 params)`: Initializes the model with the specified path and parameters.\n- `bool InitializeContext(const ContextParams\u0026 params)`: Initializes the context with the specified parameters.\n- `void SetSystemPrompt(const std::string\u0026 systemPrompt)`: Sets the system prompt for the conversation.\n- `void ResetConversation()`: Resets the conversation history.\n- `void Prompt(const std::string\u0026 userMessage, const std::function\u003cvoid(const std::string\u0026)\u003e\u0026 callback)`: Processes the user message and streams the response, invoking the callback function with each piece of the response.\n\n#### Structs\n\n- `LlamaToken`: Represents a token in the model's vocabulary.\n    - `tokenId` (int): The unique identifier of the token.\n\n- `ModelParams`: Parameters for model initialization.\n    - `nGpuLayers` (int): Number of layers to offload to GPU. Set to 0 for CPU-only.\n    - `vocabularyOnly` (bool): Only load the vocabulary, no weights.\n    - `useMemoryMapping` (bool): Use memory mapping for faster loading.\n    - `useModelLock` (bool): Force system to keep model in RAM.\n\n- `ContextParams`: Parameters for context initialization.\n    - `nContext` (size_t): Size of the context window (in tokens).\n    - `nThreads` (int): Number of threads to use for computation.\n    - `nBatch` (int): Number of tokens to process in parallel.\n\n- `SamplingParams`: Parameters for text generation sampling.\n    - `maxTokens` (size_t): Maximum number of tokens to generate.\n    - `temperature` (float): Controls randomness in generation.\n    - `topK` (int32_t): Limits sampling to the k most likely tokens.\n    - `topP` (float): Limits sampling to a cumulative probability.\n    - `repeatPenalty` (float): Penalty for repeating tokens.\n    - `frequencyPenalty` (float): Penalty based on token frequency in generated text.\n    - `presencePenalty` (float): Penalty for tokens already present in generated text.\n    - `repeatPenaltyTokens` (std::vector\u003cLlamaToken\u003e): Tokens to consider for repeat penalty.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeveloper239%2Fllama-chat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeveloper239%2Fllama-chat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeveloper239%2Fllama-chat/lists"}