--- title: "8. Making It Your Own" order: 8 --- Through Chapter 7, we've built a translation desktop app and studied how production-quality code differs. In this chapter, let's go over the key points for **turning this app into something entirely your own**. The translation app was just a vehicle. Replace llama.cpp with your own library, and the same architecture works for any application. ## 8.1 Swapping Out the Build Configuration First, replace the llama.cpp-related `FetchContent` entries in `CMakeLists.txt` with your own library. ```cmake # Remove: llama.cpp and cpp-llamalib FetchContent # Add: your own library FetchContent_Declare(my_lib GIT_REPOSITORY https://github.com/yourname/my-lib GIT_TAG main ) FetchContent_MakeAvailable(my_lib) target_link_libraries(my-app PRIVATE httplib::httplib nlohmann_json::nlohmann_json my_lib # Your library instead of cpp-llamalib # ... ) ``` If your library doesn't support CMake, you can place the header and source files directly in `src/` and add them to `add_executable`. Keep cpp-httplib, nlohmann/json, and webview as they are. ## 8.2 Adapting the API to Your Task Change the translation API's endpoints and parameters to match your task. | Translation app | Your app (e.g., image processing) | |---|---| | `POST /translate` | `POST /process` | | `{"text": "...", "target_lang": "ja"}` | `{"image": "base64...", "filter": "blur"}` | | `POST /translate/stream` | `POST /process/stream` | | `GET /models` | `GET /filters` or `GET /presets` | Then update each handler's implementation. For example, just replace the `llm.chat()` calls with your own library's API. ```cpp // Before: LLM translation auto translation = llm.chat(prompt); res.set_content(json{{"translation", translation}}.dump(), "application/json"); // After: e.g., an image processing library auto result = my_lib::process(input_image, options); res.set_content(json{{"result", result}}.dump(), "application/json"); ``` The same goes for SSE streaming. If your library has a function that reports progress via a callback, you can use the exact same pattern from Chapter 3 to send incremental responses. SSE isn't limited to LLMs — it's useful for any time-consuming task: image processing progress, data conversion steps, long-running computations. ## 8.3 Design Considerations ### Libraries with Expensive Initialization In this book, we load the LLM model at the top of `main()` and keep it in a variable. This is intentional. Loading the model on every request would take several seconds, so we load it once at startup and reuse it. If your library has expensive initialization (loading large data files, acquiring GPU resources, etc.), the same approach works well. ### Thread Safety cpp-httplib processes requests concurrently using a thread pool. In Chapter 4 we protected the `llm` object with a `std::mutex` to prevent crashes during model switching. The same pattern applies when integrating your own library. If your library isn't thread-safe or you need to swap objects at runtime, protect access with a `std::mutex`. ## 8.4 Customizing the UI Edit the three files in `public/`. - **`index.html`** — Change the input form layout. Swap `