├── .github └── FUNDING.yml ├── .gitignore ├── LICENSE ├── README.md ├── VIRUSTOTAL.txt ├── bin ├── OllamaBox.ini.Template.txt ├── OllamaBox64.dll └── Prompts.txt ├── examples └── testbed │ ├── Testbed.dpr │ ├── Testbed.dproj │ ├── Testbed.res │ ├── Testbed_Icon.ico │ └── UTestbed.pas ├── media ├── delphi.png └── ollamabox.png ├── src ├── DLL │ ├── OllamaBox64.dpr │ ├── OllamaBox64.dproj │ ├── OllamaBox64.res │ └── UOllamaBox64.pas ├── Dlluminator.pas ├── EasyJson.pas ├── OllamaBox - Embed & Control Ollama In Your Delphi App.groupproj ├── OllamaBox.Defines.inc ├── OllamaBox.Utils.pas ├── OllamaBox.pas ├── OllamaBox64.h ├── OllamaBox64.lib └── OllamaBox64.pas └── tools ├── README.txt ├── dump.cmd ├── lib.cmd └── polib.exe /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: tinyBigGAMES # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 12 | polar: # Replace with a single Polar username 13 | buy_me_a_coffee: # Replace with a single Buy Me a Coffee username 14 | thanks_dev: # Replace with a single thanks.dev username 15 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Uncomment these types if you want even more clean repository. But be careful. 2 | # It can make harm to an existing project source. Read explanations below. 3 | # 4 | # Resource files are binaries containing manifest, project icon and version info. 5 | # They can not be viewed as text or compared by diff-tools. Consider replacing them with .rc files. 6 | #*.res 7 | # 8 | # Type library file (binary). In old Delphi versions it should be stored. 9 | # Since Delphi 2009 it is produced from .ridl file and can safely be ignored. 10 | #*.tlb 11 | # 12 | # Diagram Portfolio file. Used by the diagram editor up to Delphi 7. 13 | # Uncomment this if you are not using diagrams or use newer Delphi version. 14 | #*.ddp 15 | # 16 | # Visual LiveBindings file. Added in Delphi XE2. 17 | # Uncomment this if you are not using LiveBindings Designer. 18 | #*.vlb 19 | # 20 | # Deployment Manager configuration file for your project. Added in Delphi XE2. 21 | # Uncomment this if it is not mobile development and you do not use remote debug feature. 22 | #*.deployproj 23 | # 24 | # C++ object files produced when C/C++ Output file generation is configured. 25 | # Uncomment this if you are not using external objects (zlib library for example). 26 | #*.obj 27 | # 28 | 29 | # Default Delphi compiler directories 30 | # Content of this directories are generated with each Compile/Construct of a project. 31 | # Most of the time, files here have not there place in a code repository. 32 | #Win32/ 33 | #Win64/ 34 | #OSX64/ 35 | #OSXARM64/ 36 | #Android/ 37 | #Android64/ 38 | #iOSDevice64/ 39 | #Linux64/ 40 | 41 | # Delphi compiler-generated binaries (safe to delete) 42 | *.exe 43 | *.dll 44 | *.bpl 45 | *.bpi 46 | *.dcp 47 | *.so 48 | *.apk 49 | *.drc 50 | *.map 51 | *.dres 52 | *.rsm 53 | *.tds 54 | *.dcu 55 | *.lib 56 | *.a 57 | *.o 58 | *.ocx 59 | 60 | # Delphi autogenerated files (duplicated info) 61 | *.cfg 62 | *.hpp 63 | *Resource.rc 64 | 65 | # Delphi local files (user-specific info) 66 | *.local 67 | *.identcache 68 | *.projdata 69 | *.tvsconfig 70 | *.dsk 71 | 72 | # Delphi history and backups 73 | __history/ 74 | __recovery/ 75 | *.~* 76 | 77 | # Castalia statistics file (since XE7 Castalia is distributed with Delphi) 78 | *.stat 79 | 80 | # Boss dependency manager vendor folder https://github.com/HashLoad/boss 81 | modules/ 82 | zip_latest_commit.cmd 83 | bin/OllamaBox.ini 84 | /bin/res/download 85 | /bin/res/models 86 | bin/session.json 87 | *.dsv 88 | OllamaBox-main.zip 89 | !tools/** 90 | !src/*.lib 91 | !bin/OllamaBox64.dll 92 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2025-present, tinyBigGAMES LLC 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | 3. Neither the name of the copyright holder nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![OllamaBox](media/ollamabox.png) 2 | [![Chat on Discord](https://img.shields.io/discord/754884471324672040?style=for-the-badge)](https://discord.gg/tPWjMwK) 3 | [![Follow on Bluesky](https://img.shields.io/badge/Bluesky-tinyBigGAMES-blue?style=for-the-badge&logo=bluesky)](https://bsky.app/profile/tinybiggames.com) 4 | 5 | **OllamaBox** is a powerful Delphi wrapper for [Ollama](https://ollama.com) that allows developers to seamlessly download, extract, run, and interface with the Ollama runtime entirely within their application’s process. Unlike traditional setups that require background services or separate daemon processes, OllamaBox runs Ollama as a fully embedded, self-managed component—giving you complete control over inference, API access, and model management without leaving your app. 6 | 7 | ### :sparkles: Features 8 | 9 | - :package: Download and unzip the latest Ollama release 10 | - :rocket: Run Ollama directly in your app process (no background daemon) 11 | - :electric_plug: Full access to Ollama's local REST API 12 | - :brain: Stream results from models like LLaMA 3, Gemma, Phi, and more 13 | - :file_folder: Custom model/data paths supported 14 | - :white_check_mark: Simple setup, no dependencies outside of Delphi RTL 15 | 16 | > 🚧️ **This repository is currently under construction.** 17 | > 18 | > OllamaBox is actively being developed. Features, APIs, and internal structure are subject to change. 19 | > 20 | > Contributions, feedback, and issue reports are welcome as the project evolves. 21 | 22 | 23 | ## 🛠️ Support and Resources 24 | 25 | - 🐞 **Report issues** via the [Issue Tracker](https://github.com/tinyBigGAMES/OllamaBox/issues). 26 | - 💬 **Engage in discussions** on the [Forum](https://github.com/tinyBigGAMES/OllamaBox/discussions) and [Discord](https://discord.gg/tPWjMwK). 27 | - 📚 **Learn more** at [Learn Delphi](https://learndelphi.org). 28 | 29 | ## 🤝 Contributing 30 | 31 | Contributions to **✨ OllamaBox** are highly encouraged! 🌟 32 | - 🐛 **Report Issues:** Submit issues if you encounter bugs or need help. 33 | - 💡 **Suggest Features:** Share your ideas to make **OllamaBox** even better. 34 | - 🔧 **Create Pull Requests:** Help expand the capabilities and robustness of the library. 35 | 36 | Your contributions make a difference! 🙌✨ 37 | 38 | #### Contributors 👥🤝 39 |
40 | 41 | 42 | 43 | 44 | 45 | ## 📜 Licensing 46 | 47 | **OllamaBox** is distributed under the **🆓 BSD-3-Clause License**, allowing for redistribution and use in both source and binary forms, with or without modification, under specific conditions. 48 | See the [📜 LICENSE](https://github.com/tinyBigGAMES/OllamaBox?tab=BSD-3-Clause-1-ov-file#BSD-3-Clause-1-ov-file) file for more details. 49 | 50 | --- 51 | 52 | 🦙📦 OllamaBox – Embed and control Ollama directly from your Delphi app. 53 | 54 |

55 | Delphi 56 |

57 |
58 | 59 | Made with ❤️ in Delphi -------------------------------------------------------------------------------- /VIRUSTOTAL.txt: -------------------------------------------------------------------------------- 1 | VirtusTotal report for OllamaBox Project 2 | ============================================================================= 3 | 4 | We are pleased to include a VirusTotal report for this project to ensure 5 | transparency and trust. Every effort is made to deliver software that is both 6 | safe and free of viruses. However, despite our rigorous testing and security 7 | measures, there is always a possibility that virus scanners may flag the 8 | files as a false positive. We appreciate your understanding and encourage you 9 | to review the VirusTotal report for your assurance. Should you have any 10 | concerns or reservations, please do not hesitate to reach out to us. 11 | 12 | OllamaBox64.dll - https://www.virustotal.com/gui/file/842a730874701fec000b51b70c59e234ac57da43662cd6b8d8b7188e83719143?nocache=1 13 | polib.exe - https://www.virustotal.com/gui/file/a9a71e9f103e0a43bc51c5820bcfb0703ac9d07b9943a9d5c30e3c44810d9e7c?nocache=1 14 | -------------------------------------------------------------------------------- /bin/OllamaBox.ini.Template.txt: -------------------------------------------------------------------------------- 1 | ;============================================================================== 2 | ; ___ _ _ ___ 3 | ; / _ \| | |__ _ _ __ __ _| _ ) _____ __™ 4 | ; | (_) | | / _` | ' \/ _` | _ \/ _ \ \ / 5 | ; \___/|_|_\__,_|_|_|_\__,_|___/\___/_\_\ 6 | ; Embed & Control Ollama In Your Delphi App 7 | ; 8 | ; Copyright © 2025-present tinyBigGAMES™ LLC 9 | ; All Rights Reserved. 10 | ; 11 | ; https://github.com/tinyBigGAMES/OllamaBox 12 | ; 13 | ; See LICENSE file for license information 14 | ;============================================================================== 15 | 16 | # 1. Rename to OllamaBox.ini, place in the same folder as your EXE 17 | # 2. Get your search API key from tavily.com and and update the Tavily entry 18 | 19 | [APIKEY] 20 | Tavily= 21 | LemonFox= 22 | -------------------------------------------------------------------------------- /bin/OllamaBox64.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinyBigGAMES/OllamaBox/a99f30e598493e224de5bcb5f230048239ebe08a/bin/OllamaBox64.dll -------------------------------------------------------------------------------- /bin/Prompts.txt: -------------------------------------------------------------------------------- 1 | #BEGIN_PROMPT AsciiLogo 2 | ___ _ _ ___ 3 | / _ \| | |__ _ _ __ __ _| _ ) _____ __™ 4 | | (_) | | / _` | ' \/ _` | _ \/ _ \ \ / 5 | \___/|_|_\__,_|_|_|_\__,_|___/\___/_\_\ 6 | Embed & Control Ollama In Your Delphi App 7 | #END_PROMPT 8 | 9 | #BEGIN_PROMPT IdPrompt 10 | Information about you: You are OllamaBox, a helpful AI assistant built by tinyBigGAMES LLC, designed to bring the full power of Ollama into your Delphi applications. I handle everything—from downloading and launching Ollama to managing API calls and streaming results—all embedded directly within your app. No external services, just pure local intelligence. 11 | #END_PROMPT 12 | 13 | #BEGIN_PROMPT AwarenessPrompt 14 | Today is %s and the current time is %s. 15 | #END_PROMPT 16 | 17 | #BEGIN_PROMPT DeepThinkPrompt 18 | You are a deep thinking AI, you may use extremely long chains of thought to deeply consider the problem and deliberate with yourself via systematic reasoning processes to help come to a correct solution prior to answering. You should enclose your thoughts and internal monologue inside tags, and then provide your solution or response to the problem. You should enclose your response inside tags. 19 | #END_PROMPT 20 | 21 | #BEGIN_PROMPT SystemPrompt 22 | You are a helpful assistant with the ability to call tools **only when absolutely necessary**—such as when up-to-date or external information is required to provide an accurate response. 23 | - If you already know the answer or have enough context, respond directly without using any tools. 24 | - YOU MUST USE A TOOL for ANY question about: 25 | - Events, news, or developments from after October 2024 26 | - Real-time information (weather, stock prices, sports results, etc.) 27 | - Current statistics, prices, or metrics that change frequently 28 | - Public figures' recent activities or statements 29 | - Questions containing terms like "recently," "latest," "current," "today," "this week" 30 | - Questions where an accurate answer requires data newer than October 2024 31 | - Even if you think you know the answer, if it relates to changeable information, YOU MUST USE THE TOOL instead of answering from memory. 32 | - For ANY uncertainty about whether information is current, default to using the tool rather than guessing or providing outdated information. 33 | - IMPORANT: If tool use is needed, respond ONLY with this exact format (no additional text before or after): 34 | {"tool": "", "parameters": {"": "...", "": "..."}} 35 | Available tool: 36 | [ 37 | %s 38 | ] 39 | #END_PROMPT 40 | 41 | #BEGIN_PROMPT ToolsPrompt 42 | { 43 | "name": "web_search", 44 | "description": "Searches the web for real-time, up-to-date information about the query string", 45 | "parameters": { 46 | "query": { 47 | "description": "The search query string that will be used to look up.", 48 | "type": "str" 49 | } 50 | } 51 | } 52 | #END_PROMPT 53 | 54 | #BEGIN_PROMPT ToolResponsePrompt 55 | Based on the available information, write a clear and comprehensive response that: 56 | - Transforms the tool response data into high-quality, well-structured output 57 | - DO NOT OUTPUT THE RAW JSON DATA FROM THE TOOL RESPONSE 58 | - NEVER return search results in JSON format 59 | - Address the user's query directly using the information from the tool response 60 | - Organize the information in a logical, easy-to-understand format 61 | - Present complete information while avoiding unnecessary details 62 | - Use proper citations to attribute information sources 63 | * Include specific citations for each claim using the citation format 64 | * For multiple contiguous sentences, use the appropriate citation format 65 | * For multiple sections, use comma-separated indices 66 | * Ensure every specific claim from search results is properly cited 67 | - Maintain factual accuracy while presenting information in your own words 68 | - Properly format and cite the sources using the citation format described above 69 | - Convert any HTML to corresponding MARKDOWN 70 | 71 | Remember, your task is to process and transform the data into a human-readable format, not to return the raw JSON data. Under no circumstances should you output the search results in JSON format. 72 | 73 | Tool response: %s 74 | #END_PROMPT -------------------------------------------------------------------------------- /examples/testbed/Testbed.dpr: -------------------------------------------------------------------------------- 1 | {=============================================================================== 2 | ___ _ _ ___ 3 | / _ \| | |__ _ _ __ __ _| _ ) _____ __™ 4 | | (_) | | / _` | ' \/ _` | _ \/ _ \ \ / 5 | \___/|_|_\__,_|_|_|_\__,_|___/\___/_\_\ 6 | Embed & Control Ollama In Your Delphi App 7 | 8 | Copyright © 2025-present tinyBigGAMES™ LLC 9 | All Rights Reserved. 10 | 11 | https://github.com/tinyBigGAMES/OllamaBox 12 | 13 | See LICENSE file for license information 14 | ===============================================================================} 15 | 16 | program Testbed; 17 | 18 | {$APPTYPE CONSOLE} 19 | 20 | {$R *.res} 21 | 22 | uses 23 | System.SysUtils, 24 | OllamaBox in '..\..\src\OllamaBox.pas', 25 | OllamaBox.Utils in '..\..\src\OllamaBox.Utils.pas', 26 | UTestbed in 'UTestbed.pas', 27 | OllamaBox64 in '..\..\src\OllamaBox64.pas'; 28 | 29 | begin 30 | try 31 | RunTests(); 32 | except 33 | on E: Exception do 34 | Writeln(E.ClassName, ': ', E.Message); 35 | end; 36 | end. 37 | -------------------------------------------------------------------------------- /examples/testbed/Testbed.dproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | {1784B513-83B3-4236-8CCA-E1C3898EA5AD} 4 | 20.3 5 | None 6 | True 7 | Release 8 | Win64 9 | Testbed 10 | 2 11 | Console 12 | Testbed.dpr 13 | 14 | 15 | true 16 | 17 | 18 | true 19 | Base 20 | true 21 | 22 | 23 | true 24 | Base 25 | true 26 | 27 | 28 | true 29 | Base 30 | true 31 | 32 | 33 | true 34 | Cfg_1 35 | true 36 | true 37 | 38 | 39 | true 40 | Cfg_1 41 | true 42 | true 43 | 44 | 45 | true 46 | Base 47 | true 48 | 49 | 50 | true 51 | Cfg_2 52 | true 53 | true 54 | 55 | 56 | .\$(Platform)\$(Config) 57 | .\$(Platform)\$(Config) 58 | false 59 | false 60 | false 61 | false 62 | false 63 | System;Xml;Data;Datasnap;Web;Soap;$(DCC_Namespace) 64 | Testbed 65 | 66 | 67 | vclwinx;DataSnapServer;fmx;emshosting;vclie;DbxCommonDriver;bindengine;IndyIPCommon;VCLRESTComponents;DBXMSSQLDriver;FireDACCommonODBC;emsclient;FireDACCommonDriver;appanalytics;IndyProtocols;vclx;Skia.Package.RTL;IndyIPClient;dbxcds;vcledge;bindcompvclwinx;emsedge;bindcompfmx;DBXFirebirdDriver;inetdb;FireDACSqliteDriver;DbxClientDriver;FireDACASADriver;JclVcl;soapmidas;vclactnband;fmxFireDAC;dbexpress;Jcl;FireDACInfxDriver;DBXMySQLDriver;VclSmp;inet;DataSnapCommon;vcltouch;fmxase;DBXOdbcDriver;dbrtl;FireDACDBXDriver;Skia.Package.FMX;FireDACOracleDriver;fmxdae;FireDACMSAccDriver;CustomIPTransport;FireDACMSSQLDriver;DataSnapIndy10ServerTransport;JclDeveloperTools;DataSnapConnectors;vcldsnap;DBXInterBaseDriver;FireDACMongoDBDriver;IndySystem;FireDACTDataDriver;Skia.Package.VCL;vcldb;JclContainers;vclFireDAC;bindcomp;FireDACCommon;DataSnapServerMidas;FireDACODBCDriver;emsserverresource;inetstn;IndyCore;RESTBackendComponents;bindcompdbx;rtl;FireDACMySQLDriver;FireDACADSDriver;RESTComponents;DBXSqliteDriver;vcl;IndyIPServer;dsnapxml;dsnapcon;DataSnapClient;DataSnapProviderClient;adortl;DBXSybaseASEDriver;DBXDb2Driver;vclimg;DataSnapFireDAC;emsclientfiredac;FireDACPgDriver;FireDAC;FireDACDSDriver;inetdbxpress;xmlrtl;tethering;bindcompvcl;dsnap;CloudService;DBXSybaseASADriver;DBXOracleDriver;FireDACDb2Driver;DBXInformixDriver;fmxobj;bindcompvclsmp;DataSnapNativeClient;DatasnapConnectorsFreePascal;soaprtl;soapserver;FireDACIBDriver;$(DCC_UsePackage) 68 | Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace) 69 | Debug 70 | CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= 71 | 1033 72 | true 73 | $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png 74 | $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png 75 | 76 | 77 | vclwinx;DataSnapServer;fmx;emshosting;vclie;DbxCommonDriver;bindengine;IndyIPCommon;VCLRESTComponents;DBXMSSQLDriver;FireDACCommonODBC;emsclient;FireDACCommonDriver;appanalytics;IndyProtocols;vclx;IndyIPClient;dbxcds;vcledge;bindcompvclwinx;emsedge;bindcompfmx;DBXFirebirdDriver;inetdb;FireDACSqliteDriver;DbxClientDriver;FireDACASADriver;soapmidas;vclactnband;fmxFireDAC;dbexpress;FireDACInfxDriver;DBXMySQLDriver;VclSmp;inet;DataSnapCommon;vcltouch;fmxase;DBXOdbcDriver;dbrtl;FireDACDBXDriver;FireDACOracleDriver;fmxdae;FireDACMSAccDriver;CustomIPTransport;FireDACMSSQLDriver;DataSnapIndy10ServerTransport;DataSnapConnectors;vcldsnap;DBXInterBaseDriver;FireDACMongoDBDriver;IndySystem;FireDACTDataDriver;Skia.Package.VCL;vcldb;vclFireDAC;bindcomp;FireDACCommon;DataSnapServerMidas;FireDACODBCDriver;emsserverresource;inetstn;IndyCore;RESTBackendComponents;bindcompdbx;rtl;FireDACMySQLDriver;FireDACADSDriver;RESTComponents;DBXSqliteDriver;vcl;IndyIPServer;dsnapxml;dsnapcon;DataSnapClient;DataSnapProviderClient;adortl;DBXSybaseASEDriver;DBXDb2Driver;vclimg;DataSnapFireDAC;emsclientfiredac;FireDACPgDriver;FireDAC;FireDACDSDriver;inetdbxpress;xmlrtl;tethering;bindcompvcl;dsnap;CloudService;DBXSybaseASADriver;DBXOracleDriver;FireDACDb2Driver;DBXInformixDriver;fmxobj;bindcompvclsmp;DataSnapNativeClient;DatasnapConnectorsFreePascal;soaprtl;soapserver;FireDACIBDriver;$(DCC_UsePackage) 78 | true 79 | $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_44.png 80 | $(BDS)\bin\Artwork\Windows\UWP\delphi_UwpDefault_150.png 81 | Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;$(DCC_Namespace) 82 | Debug 83 | CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments= 84 | 1033 85 | ..\..\bin 86 | Testbed_Icon.ico 87 | $(BDS)\bin\default_app.manifest 88 | ..\..\src;$(DCC_UnitSearchPath) 89 | PerMonitorV2 90 | 91 | 92 | DEBUG;$(DCC_Define) 93 | true 94 | false 95 | true 96 | true 97 | true 98 | true 99 | true 100 | 101 | 102 | false 103 | 104 | 105 | 1033 106 | true 107 | 108 | 109 | false 110 | RELEASE;$(DCC_Define) 111 | 0 112 | 0 113 | 114 | 115 | true 116 | 1033 117 | 118 | 119 | 120 | MainSource 121 | 122 | 123 | 124 | 125 | 126 | 127 | Base 128 | 129 | 130 | Cfg_1 131 | Base 132 | 133 | 134 | Cfg_2 135 | Base 136 | 137 | 138 | 139 | Delphi.Personality.12 140 | Application 141 | 142 | 143 | 144 | Testbed.dpr 145 | 146 | 147 | Embarcadero C++Builder Office 2000 Servers Package 148 | Embarcadero C++Builder Office XP Servers Package 149 | Microsoft Office 2000 Sample Automation Server Wrapper Components 150 | Microsoft Office XP Sample Automation Server Wrapper Components 151 | 152 | 153 | 154 | 155 | 156 | true 157 | 158 | 159 | 160 | 161 | true 162 | 163 | 164 | 165 | 166 | true 167 | 168 | 169 | 170 | 171 | Testbed.exe 172 | true 173 | 174 | 175 | 176 | 177 | Testbed.rsm 178 | true 179 | 180 | 181 | 182 | 183 | Testbed.exe 184 | true 185 | 186 | 187 | 188 | 189 | 1 190 | 191 | 192 | Contents\MacOS 193 | 1 194 | 195 | 196 | 0 197 | 198 | 199 | 200 | 201 | res\xml 202 | 1 203 | 204 | 205 | res\xml 206 | 1 207 | 208 | 209 | 210 | 211 | library\lib\armeabi 212 | 1 213 | 214 | 215 | library\lib\armeabi 216 | 1 217 | 218 | 219 | 220 | 221 | library\lib\armeabi-v7a 222 | 1 223 | 224 | 225 | 226 | 227 | library\lib\mips 228 | 1 229 | 230 | 231 | library\lib\mips 232 | 1 233 | 234 | 235 | 236 | 237 | library\lib\armeabi-v7a 238 | 1 239 | 240 | 241 | library\lib\arm64-v8a 242 | 1 243 | 244 | 245 | 246 | 247 | library\lib\armeabi-v7a 248 | 1 249 | 250 | 251 | 252 | 253 | res\drawable 254 | 1 255 | 256 | 257 | res\drawable 258 | 1 259 | 260 | 261 | 262 | 263 | res\drawable-anydpi-v21 264 | 1 265 | 266 | 267 | res\drawable-anydpi-v21 268 | 1 269 | 270 | 271 | 272 | 273 | res\values 274 | 1 275 | 276 | 277 | res\values 278 | 1 279 | 280 | 281 | 282 | 283 | res\values-v21 284 | 1 285 | 286 | 287 | res\values-v21 288 | 1 289 | 290 | 291 | 292 | 293 | res\values-v31 294 | 1 295 | 296 | 297 | res\values-v31 298 | 1 299 | 300 | 301 | 302 | 303 | res\values-v35 304 | 1 305 | 306 | 307 | res\values-v35 308 | 1 309 | 310 | 311 | 312 | 313 | res\drawable-anydpi-v26 314 | 1 315 | 316 | 317 | res\drawable-anydpi-v26 318 | 1 319 | 320 | 321 | 322 | 323 | res\drawable 324 | 1 325 | 326 | 327 | res\drawable 328 | 1 329 | 330 | 331 | 332 | 333 | res\drawable 334 | 1 335 | 336 | 337 | res\drawable 338 | 1 339 | 340 | 341 | 342 | 343 | res\drawable 344 | 1 345 | 346 | 347 | res\drawable 348 | 1 349 | 350 | 351 | 352 | 353 | res\drawable-anydpi-v33 354 | 1 355 | 356 | 357 | res\drawable-anydpi-v33 358 | 1 359 | 360 | 361 | 362 | 363 | res\values 364 | 1 365 | 366 | 367 | res\values 368 | 1 369 | 370 | 371 | 372 | 373 | res\values-night-v21 374 | 1 375 | 376 | 377 | res\values-night-v21 378 | 1 379 | 380 | 381 | 382 | 383 | res\drawable 384 | 1 385 | 386 | 387 | res\drawable 388 | 1 389 | 390 | 391 | 392 | 393 | res\drawable-xxhdpi 394 | 1 395 | 396 | 397 | res\drawable-xxhdpi 398 | 1 399 | 400 | 401 | 402 | 403 | res\drawable-xxxhdpi 404 | 1 405 | 406 | 407 | res\drawable-xxxhdpi 408 | 1 409 | 410 | 411 | 412 | 413 | res\drawable-ldpi 414 | 1 415 | 416 | 417 | res\drawable-ldpi 418 | 1 419 | 420 | 421 | 422 | 423 | res\drawable-mdpi 424 | 1 425 | 426 | 427 | res\drawable-mdpi 428 | 1 429 | 430 | 431 | 432 | 433 | res\drawable-hdpi 434 | 1 435 | 436 | 437 | res\drawable-hdpi 438 | 1 439 | 440 | 441 | 442 | 443 | res\drawable-xhdpi 444 | 1 445 | 446 | 447 | res\drawable-xhdpi 448 | 1 449 | 450 | 451 | 452 | 453 | res\drawable-mdpi 454 | 1 455 | 456 | 457 | res\drawable-mdpi 458 | 1 459 | 460 | 461 | 462 | 463 | res\drawable-hdpi 464 | 1 465 | 466 | 467 | res\drawable-hdpi 468 | 1 469 | 470 | 471 | 472 | 473 | res\drawable-xhdpi 474 | 1 475 | 476 | 477 | res\drawable-xhdpi 478 | 1 479 | 480 | 481 | 482 | 483 | res\drawable-xxhdpi 484 | 1 485 | 486 | 487 | res\drawable-xxhdpi 488 | 1 489 | 490 | 491 | 492 | 493 | res\drawable-xxxhdpi 494 | 1 495 | 496 | 497 | res\drawable-xxxhdpi 498 | 1 499 | 500 | 501 | 502 | 503 | res\drawable-small 504 | 1 505 | 506 | 507 | res\drawable-small 508 | 1 509 | 510 | 511 | 512 | 513 | res\drawable-normal 514 | 1 515 | 516 | 517 | res\drawable-normal 518 | 1 519 | 520 | 521 | 522 | 523 | res\drawable-large 524 | 1 525 | 526 | 527 | res\drawable-large 528 | 1 529 | 530 | 531 | 532 | 533 | res\drawable-xlarge 534 | 1 535 | 536 | 537 | res\drawable-xlarge 538 | 1 539 | 540 | 541 | 542 | 543 | res\values 544 | 1 545 | 546 | 547 | res\values 548 | 1 549 | 550 | 551 | 552 | 553 | res\drawable-anydpi-v24 554 | 1 555 | 556 | 557 | res\drawable-anydpi-v24 558 | 1 559 | 560 | 561 | 562 | 563 | res\drawable 564 | 1 565 | 566 | 567 | res\drawable 568 | 1 569 | 570 | 571 | 572 | 573 | res\drawable-night-anydpi-v21 574 | 1 575 | 576 | 577 | res\drawable-night-anydpi-v21 578 | 1 579 | 580 | 581 | 582 | 583 | res\drawable-anydpi-v31 584 | 1 585 | 586 | 587 | res\drawable-anydpi-v31 588 | 1 589 | 590 | 591 | 592 | 593 | res\drawable-night-anydpi-v31 594 | 1 595 | 596 | 597 | res\drawable-night-anydpi-v31 598 | 1 599 | 600 | 601 | 602 | 603 | 1 604 | 605 | 606 | Contents\MacOS 607 | 1 608 | 609 | 610 | 0 611 | 612 | 613 | 614 | 615 | Contents\MacOS 616 | 1 617 | .framework 618 | 619 | 620 | Contents\MacOS 621 | 1 622 | .framework 623 | 624 | 625 | Contents\MacOS 626 | 1 627 | .framework 628 | 629 | 630 | 0 631 | 632 | 633 | 634 | 635 | 1 636 | .dylib 637 | 638 | 639 | 1 640 | .dylib 641 | 642 | 643 | 1 644 | .dylib 645 | 646 | 647 | Contents\MacOS 648 | 1 649 | .dylib 650 | 651 | 652 | Contents\MacOS 653 | 1 654 | .dylib 655 | 656 | 657 | Contents\MacOS 658 | 1 659 | .dylib 660 | 661 | 662 | 0 663 | .dll;.bpl 664 | 665 | 666 | 667 | 668 | 1 669 | .dylib 670 | 671 | 672 | 1 673 | .dylib 674 | 675 | 676 | 1 677 | .dylib 678 | 679 | 680 | Contents\MacOS 681 | 1 682 | .dylib 683 | 684 | 685 | Contents\MacOS 686 | 1 687 | .dylib 688 | 689 | 690 | Contents\MacOS 691 | 1 692 | .dylib 693 | 694 | 695 | 0 696 | .bpl 697 | 698 | 699 | 700 | 701 | 0 702 | 703 | 704 | 0 705 | 706 | 707 | 0 708 | 709 | 710 | 0 711 | 712 | 713 | 0 714 | 715 | 716 | Contents\Resources\StartUp\ 717 | 0 718 | 719 | 720 | Contents\Resources\StartUp\ 721 | 0 722 | 723 | 724 | Contents\Resources\StartUp\ 725 | 0 726 | 727 | 728 | 0 729 | 730 | 731 | 732 | 733 | 1 734 | 735 | 736 | 1 737 | 738 | 739 | 740 | 741 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 742 | 1 743 | 744 | 745 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 746 | 1 747 | 748 | 749 | 750 | 751 | ..\ 752 | 1 753 | 754 | 755 | ..\ 756 | 1 757 | 758 | 759 | ..\ 760 | 1 761 | 762 | 763 | 764 | 765 | Contents 766 | 1 767 | 768 | 769 | Contents 770 | 1 771 | 772 | 773 | Contents 774 | 1 775 | 776 | 777 | 778 | 779 | Contents\Resources 780 | 1 781 | 782 | 783 | Contents\Resources 784 | 1 785 | 786 | 787 | Contents\Resources 788 | 1 789 | 790 | 791 | 792 | 793 | library\lib\armeabi-v7a 794 | 1 795 | 796 | 797 | library\lib\arm64-v8a 798 | 1 799 | 800 | 801 | 1 802 | 803 | 804 | 1 805 | 806 | 807 | 1 808 | 809 | 810 | 1 811 | 812 | 813 | Contents\MacOS 814 | 1 815 | 816 | 817 | Contents\MacOS 818 | 1 819 | 820 | 821 | Contents\MacOS 822 | 1 823 | 824 | 825 | 0 826 | 827 | 828 | 829 | 830 | library\lib\armeabi-v7a 831 | 1 832 | 833 | 834 | 835 | 836 | 1 837 | 838 | 839 | 1 840 | 841 | 842 | 1 843 | 844 | 845 | 846 | 847 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 848 | 1 849 | 850 | 851 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 852 | 1 853 | 854 | 855 | ..\$(PROJECTNAME).app.dSYM\Contents\Resources\DWARF 856 | 1 857 | 858 | 859 | 860 | 861 | ..\ 862 | 1 863 | 864 | 865 | ..\ 866 | 1 867 | 868 | 869 | ..\ 870 | 1 871 | 872 | 873 | 874 | 875 | 1 876 | 877 | 878 | 1 879 | 880 | 881 | 1 882 | 883 | 884 | 885 | 886 | ..\$(PROJECTNAME).launchscreen 887 | 64 888 | 889 | 890 | ..\$(PROJECTNAME).launchscreen 891 | 64 892 | 893 | 894 | 895 | 896 | 1 897 | 898 | 899 | 1 900 | 901 | 902 | 1 903 | 904 | 905 | 906 | 907 | Assets 908 | 1 909 | 910 | 911 | Assets 912 | 1 913 | 914 | 915 | 916 | 917 | Assets 918 | 1 919 | 920 | 921 | Assets 922 | 1 923 | 924 | 925 | 926 | 927 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 928 | 1 929 | 930 | 931 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 932 | 1 933 | 934 | 935 | 936 | 937 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 938 | 1 939 | 940 | 941 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 942 | 1 943 | 944 | 945 | 946 | 947 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 948 | 1 949 | 950 | 951 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 952 | 1 953 | 954 | 955 | 956 | 957 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 958 | 1 959 | 960 | 961 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 962 | 1 963 | 964 | 965 | 966 | 967 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 968 | 1 969 | 970 | 971 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 972 | 1 973 | 974 | 975 | 976 | 977 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 978 | 1 979 | 980 | 981 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 982 | 1 983 | 984 | 985 | 986 | 987 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 988 | 1 989 | 990 | 991 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 992 | 1 993 | 994 | 995 | 996 | 997 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 998 | 1 999 | 1000 | 1001 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 1002 | 1 1003 | 1004 | 1005 | 1006 | 1007 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 1008 | 1 1009 | 1010 | 1011 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 1012 | 1 1013 | 1014 | 1015 | 1016 | 1017 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 1018 | 1 1019 | 1020 | 1021 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 1022 | 1 1023 | 1024 | 1025 | 1026 | 1027 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 1028 | 1 1029 | 1030 | 1031 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 1032 | 1 1033 | 1034 | 1035 | 1036 | 1037 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 1038 | 1 1039 | 1040 | 1041 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 1042 | 1 1043 | 1044 | 1045 | 1046 | 1047 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 1048 | 1 1049 | 1050 | 1051 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 1052 | 1 1053 | 1054 | 1055 | 1056 | 1057 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 1058 | 1 1059 | 1060 | 1061 | ..\$(PROJECTNAME).launchscreen\Assets\LaunchScreenImage.imageset 1062 | 1 1063 | 1064 | 1065 | 1066 | 1067 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 1068 | 1 1069 | 1070 | 1071 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 1072 | 1 1073 | 1074 | 1075 | 1076 | 1077 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 1078 | 1 1079 | 1080 | 1081 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 1082 | 1 1083 | 1084 | 1085 | 1086 | 1087 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 1088 | 1 1089 | 1090 | 1091 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 1092 | 1 1093 | 1094 | 1095 | 1096 | 1097 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 1098 | 1 1099 | 1100 | 1101 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 1102 | 1 1103 | 1104 | 1105 | 1106 | 1107 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 1108 | 1 1109 | 1110 | 1111 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 1112 | 1 1113 | 1114 | 1115 | 1116 | 1117 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 1118 | 1 1119 | 1120 | 1121 | ..\$(PROJECTNAME).launchscreen\Assets\AppIcon.appiconset 1122 | 1 1123 | 1124 | 1125 | 1126 | 1127 | 1128 | 1129 | 1130 | 1131 | 1132 | 1133 | 1134 | 1135 | 1136 | 1137 | 1138 | 1139 | False 1140 | True 1141 | 1142 | 1143 | 12 1144 | 1145 | 1146 | 1147 | 1148 | 1149 | -------------------------------------------------------------------------------- /examples/testbed/Testbed.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinyBigGAMES/OllamaBox/a99f30e598493e224de5bcb5f230048239ebe08a/examples/testbed/Testbed.res -------------------------------------------------------------------------------- /examples/testbed/Testbed_Icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinyBigGAMES/OllamaBox/a99f30e598493e224de5bcb5f230048239ebe08a/examples/testbed/Testbed_Icon.ico -------------------------------------------------------------------------------- /examples/testbed/UTestbed.pas: -------------------------------------------------------------------------------- 1 | {=============================================================================== 2 | ___ _ _ ___ 3 | / _ \| | |__ _ _ __ __ _| _ ) _____ __™ 4 | | (_) | | / _` | ' \/ _` | _ \/ _ \ \ / 5 | \___/|_|_\__,_|_|_|_\__,_|___/\___/_\_\ 6 | Embed & Control Ollama In Your Delphi App 7 | 8 | Copyright © 2025-present tinyBigGAMES™ LLC 9 | All Rights Reserved. 10 | 11 | https://github.com/tinyBigGAMES/OllamaBox 12 | 13 | See LICENSE file for license information 14 | ===============================================================================} 15 | 16 | unit UTestbed; 17 | 18 | interface 19 | 20 | { 21 | ===== USAGE NOTES ===== 22 | * GPU Settings: 23 | - Setting `MainGPU` to `-1` will automatically select the best GPU 24 | available on your system. 25 | - Alternatively, you can specify a GPU by setting `MainGPU` to `0 - N` 26 | (where `N` is the GPU index). 27 | - For `MaxGPULayers`: 28 | - Setting it to `-1` will use all available layers on the GPU. 29 | - Setting it to `0` will use the CPU only. 30 | - Setting it to `1 - N` will offload a specific number of layers to the 31 | GPU. 32 | 33 | * Customizing Output: 34 | - You can configure various callbacks to control the model's output 35 | according to your needs. 36 | 37 | * Optimized for Local Inference: 38 | - Designed for efficient local inference on consumer-grade 39 | hardware. Using a 4-bit quantized model ensures fast loading and 40 | performance on modern consumer GPUs. 41 | 42 | * Get search api key from: 43 | - https://tavily.com/ 44 | - You get 1000 free searches per month. 45 | - Add the API key to the [APIKEY] section of OllamaBox.ini under the Tavily 46 | entry. 47 | 48 | * See comments in `OllamaBox.ini.Template.txt` file 49 | } 50 | 51 | uses 52 | System.SysUtils, 53 | OllamaBox64, 54 | OllamaBox.Utils, 55 | OllamaBox; 56 | 57 | procedure RunTests(); 58 | 59 | implementation 60 | 61 | { ----------------------------------------------------------------------------- 62 | Test01: OllamaBox Interactive Chat 63 | This procedure demonstrates an interactive command-line chat session using 64 | the TOllamaBox class. It performs the following actions: 65 | - Downloads and starts the Ollama server 66 | - Pulls the default model 67 | - Displays a splash screen and handles response events 68 | - Supports command input (/help, /clear, /bye) 69 | - Streams responses with real-time token feedback and performance stats 70 | - Saves and loads context from a "session" file 71 | 72 | The OnNextToken and OnResponseStart events are used to handle token streaming 73 | and UI state updates. This is a complete CLI chat loop using OllamaBox. 74 | ------------------------------------------------------------------------------ } 75 | procedure Test01(); 76 | var 77 | LOllamaBox: TOllamaBox; 78 | LPrompt: string; 79 | LDone: Boolean; 80 | LCmd: string; 81 | begin 82 | // Create an instance of TOllamaBox 83 | LOllamaBox := TOllamaBox.Create(); 84 | try 85 | // Setup token streaming callback 86 | LOllamaBox.OnNextToken := 87 | procedure (const AToken: string) 88 | begin 89 | if LOllamaBox.Thinking then 90 | obConsole.Print(obCSIDim+obCSIFGWhite+AToken) // dim output if "thinking" 91 | else 92 | obConsole.Print(obCSIFGGreen+AToken); // green output for normal stream 93 | end; 94 | 95 | // Setup initial console state 96 | obConsole.SetTitle('OllamaBox - Chat'); 97 | obConsole.ClearScreen(); 98 | obConsole.PrintLn('One moment...'); 99 | 100 | // Download and start the Ollama server 101 | LOllamaBox.DownloadServer(); 102 | LOllamaBox.StartServer(); 103 | 104 | // Check if Ollam server is running 105 | if not LOllamaBox.ServerRunning() then 106 | begin 107 | obConsole.PrintLn(LOllamaBox.Error); 108 | Exit; 109 | end; 110 | 111 | // Pull the default model 112 | LOllamaBox.Pull(); 113 | 114 | // Set initial inference parameters 115 | LOllamaBox.Temperature := 1.0; 116 | LOllamaBox.Seed := -1; 117 | LOllamaBox.ShowThinking := False; 118 | LOllamaBox.Prompt := 'Hello.'; 119 | 120 | // Setup splash screen callback for first response 121 | LOllamaBox.OnResponseStart := 122 | procedure 123 | begin 124 | obConsole.ClearScreen(); 125 | obConsole.PrintLn(); 126 | LOllamaBox.DisplayLogo(obCSIFGMagenta); 127 | obConsole.PrintLn(obCSIFGCyan+' OllamaBox v%s | Ollama v%s', [LOllamaBox.GetVersion(), LOllamaBox.GetOllamaVersion()]); 128 | obConsole.PrintLn(obCRLF+obCSIDim+obCSIFGWhite+'Type your question and press ENTER or type'); 129 | obConsole.PrintLn(obCSIDim+obCSIFGWhite+'"/help" for available commands.'+obCRLF); 130 | end; 131 | 132 | // Run the initial model generation (greeting) 133 | if not LOllamaBox.Generate() then Exit; 134 | 135 | // Enable live thinking display 136 | LOllamaBox.ShowThinking := True; 137 | 138 | // Disable splash for future generations 139 | LOllamaBox.OnResponseStart := nil; 140 | 141 | // Update inference params for deterministic output 142 | LOllamaBox.Temperature := 0.0; 143 | LOllamaBox.Seed := 42; 144 | 145 | // Load conversation context from file 146 | LOllamaBox.LoadContext('session'); 147 | 148 | // Print a blank line for spacing 149 | obConsole.PrintLn(obCRLF); 150 | 151 | // Initialize session loop 152 | LDone := False; 153 | while not LDone do 154 | begin 155 | // Let the message queue process events 156 | obUtils.ProcessMessages(); 157 | 158 | // Prompt the user 159 | obConsole.PrintLn('Question:'); 160 | obConsole.Print('>'); 161 | ReadLn(LPrompt); 162 | 163 | // Skip empty input 164 | if LPrompt.Trim.IsEmpty then 165 | continue; 166 | 167 | // Handle slash commands 168 | LCmd := LPrompt.Trim; 169 | if LCmd.StartsWith('/') then 170 | begin 171 | if SameText(LCmd, '/bye') then 172 | begin 173 | LDone := True; 174 | continue; 175 | end 176 | else if SameText(LCmd, '/clear') then 177 | begin 178 | LOllamaBox.ClearContext(); 179 | obConsole.PrintLn(obCSIFGBrightYellow+obCRLF+'Cleared context.'+obCRLF); 180 | continue; 181 | end 182 | else if SameText(LCmd, '/help') then 183 | begin 184 | obConsole.PrintLn(obCSIFGBrightYellow+obCRLF+'Available commands:'); 185 | obConsole.PrintLn(obCSIFGBrightYellow+'/bye - quit'); 186 | obConsole.PrintLn(obCSIFGBrightYellow+'/clear - clear session'); 187 | obConsole.PrintLn(obCSIFGBrightYellow+'/help - show this help'); 188 | obConsole.PrintLn(); 189 | continue; 190 | end 191 | else 192 | begin 193 | obConsole.PrintLn(obCSIFGRed+'Invalid command.'+obCRLF); 194 | continue; 195 | end; 196 | end; 197 | 198 | // Assign prompt and generate response 199 | LOllamaBox.Prompt := LPrompt; 200 | obConsole.PrintLn(obCRLF+'Response:'); 201 | 202 | // Run inference and show results 203 | if LOllamaBox.Generate() then 204 | begin 205 | obConsole.PrintLn(obCRLF+obCRLF+obCSIFGBrightYellow+ 206 | 'Tokens in: %d, out: %d, total: %d | time: %.2f secs, speed: %.2f t/s', 207 | [LOllamaBox.InputTokens, LOllamaBox.OutputTokens, 208 | LOllamaBox.TotalTokens, LOllamaBox.Time, LOllamaBox.Speed]); 209 | obConsole.PrintLn(); 210 | end 211 | else 212 | begin 213 | obConsole.PrintLn(obCRLF+obCRLF+obCSIFGRed+'%s', [LOllamaBox.Error]); 214 | obConsole.PrintLn(); 215 | end; 216 | end; 217 | 218 | // Save context before exiting 219 | LOllamaBox.SaveContext('session'); 220 | 221 | // Final "goodbye" message 222 | LOllamaBox.Temperature := 1.0; 223 | LOllamaBox.Seed := -1; 224 | LOllamaBox.ShowThinking := False; 225 | LOllamaBox.Prompt := 'Bye.'; 226 | LOllamaBox.Generate(); 227 | 228 | obConsole.PrintLn(); 229 | 230 | finally 231 | // Free OllamaBox instance 232 | LOllamaBox.Free(); 233 | end; 234 | end; 235 | 236 | { ----------------------------------------------------------------------------- 237 | Test02_NextToken: Token Stream Callback 238 | This callback is used by `Test02` to handle token-by-token streaming output 239 | from the Ollama model. It receives each token as it is generated and writes it 240 | directly to the console using `write`. 241 | 242 | Parameters: 243 | AToken - Pointer to the wide-character string containing the token. 244 | AUserData - Optional user-defined pointer (unused in this example). 245 | 246 | This callback is passed to `obSetOnNextToken` and is invoked automatically 247 | during inference when new tokens are available. 248 | ------------------------------------------------------------------------------ } 249 | procedure Test02_NextToken(const AToken: PWideChar; const AUserData: Pointer); stdcall; 250 | begin 251 | // Write the token to the console 252 | write(string(AToken)); 253 | end; 254 | 255 | { ----------------------------------------------------------------------------- 256 | Test02: Procedural API Demo 257 | This procedure demonstrates how to use the OllamaBox procedural API to perform 258 | a basic prompt and response exchange. It does the following: 259 | - Creates a new OllamaBox instance using `obCreate` 260 | - Downloads and starts the embedded Ollama server 261 | - Verifies the server is running 262 | - Sets a callback for streaming tokens (`Test02_NextToken`) 263 | - Sends a prompt and streams the response 264 | - Frees the OllamaBox instance on exit 265 | 266 | This example uses only the procedural functions, making it ideal for simpler 267 | integrations or language bindings that do not support Delphi-style classes. 268 | ------------------------------------------------------------------------------ } 269 | procedure Test02(); 270 | var 271 | LOllamaBox: OllamaBox64.TOllamaBox; 272 | begin 273 | // Create a new instance of TOllamaBox using the procedural API 274 | LOllamaBox := obCreate(); 275 | try 276 | // Display OllamaBox ascii logo 277 | obDisplayLogo(LOllamaBox, nil); 278 | WriteLn; 279 | 280 | // Download the Ollama server if not already present 281 | obDownloadServer(LOllamaBox); 282 | 283 | // Start the Ollama server and exit if it fails 284 | if not obStartServer(LOllamaBox) then Exit; 285 | 286 | // Confirm the server is running before continuing 287 | if not obServerRunning(LOllamaBox) then Exit; 288 | 289 | // Pull the default model 290 | obPull(LOllamaBox); 291 | 292 | // Set a token streaming callback 293 | obSetOnNextToken(LOllamaBox, Test02_NextToken, nil); 294 | 295 | // Provide a prompt to the model 296 | obSetPrompt(LOllamaBox, 'who are you?'); 297 | 298 | // Generate a response and stream the output 299 | obGenerate(LOllamaBox); 300 | 301 | finally 302 | // Free the instance and clean up 303 | obFree(LOllamaBox); 304 | end; 305 | end; 306 | 307 | 308 | { ----------------------------------------------------------------------------- 309 | RunTests: Entry Point for Example Execution 310 | This procedure serves as the main test runner for the OllamaBox examples. It 311 | selects and executes a specific test routine based on the value of LNum. This 312 | structure allows for easy expansion by adding new cases as more tests are 313 | created. After running the selected test, the console is paused for review. 314 | ------------------------------------------------------------------------------ } 315 | procedure RunTests(); 316 | var 317 | LNum: Integer; 318 | begin 319 | // Set the test number to run 320 | LNum := 02; 321 | 322 | // Select and execute the corresponding test 323 | case LNum of 324 | 01: Test01(); 325 | 02: Test02(); 326 | end; 327 | 328 | // Pause the console so results can be reviewed before closing 329 | obConsole.Pause(); 330 | end; 331 | 332 | end. 333 | -------------------------------------------------------------------------------- /media/delphi.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinyBigGAMES/OllamaBox/a99f30e598493e224de5bcb5f230048239ebe08a/media/delphi.png -------------------------------------------------------------------------------- /media/ollamabox.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinyBigGAMES/OllamaBox/a99f30e598493e224de5bcb5f230048239ebe08a/media/ollamabox.png -------------------------------------------------------------------------------- /src/DLL/OllamaBox64.dpr: -------------------------------------------------------------------------------- 1 | library OllamaBox64; 2 | 3 | { Important note about DLL memory management: ShareMem must be the 4 | first unit in your library's USES clause AND your project's (select 5 | Project-View Source) USES clause if your DLL exports any procedures or 6 | functions that pass strings as parameters or function results. This 7 | applies to all strings passed to and from your DLL--even those that 8 | are nested in records and classes. ShareMem is the interface unit to 9 | the BORLNDMM.DLL shared memory manager, which must be deployed along 10 | with your DLL. To avoid using BORLNDMM.DLL, pass string information 11 | using PChar or ShortString parameters. 12 | 13 | Important note about VCL usage: when this DLL will be implicitly 14 | loaded and this DLL uses TWicImage / TImageCollection created in 15 | any unit initialization section, then Vcl.WicImageInit must be 16 | included into your library's USES clause. } 17 | 18 | uses 19 | System.SysUtils, 20 | System.Classes, 21 | EasyJson in '..\EasyJson.pas', 22 | OllamaBox in '..\OllamaBox.pas', 23 | OllamaBox.Utils in '..\OllamaBox.Utils.pas', 24 | UOllamaBox64 in 'UOllamaBox64.pas'; 25 | 26 | {$R *.res} 27 | 28 | begin 29 | end. 30 | -------------------------------------------------------------------------------- /src/DLL/OllamaBox64.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinyBigGAMES/OllamaBox/a99f30e598493e224de5bcb5f230048239ebe08a/src/DLL/OllamaBox64.res -------------------------------------------------------------------------------- /src/DLL/UOllamaBox64.pas: -------------------------------------------------------------------------------- 1 | {=============================================================================== 2 | ___ _ _ ___ 3 | / _ \| | |__ _ _ __ __ _| _ ) _____ __™ 4 | | (_) | | / _` | ' \/ _` | _ \/ _ \ \ / 5 | \___/|_|_\__,_|_|_|_\__,_|___/\___/_\_\ 6 | Embed & Control Ollama In Your Delphi App 7 | 8 | Copyright © 2025-present tinyBigGAMES™ LLC 9 | All Rights Reserved. 10 | 11 | https://github.com/tinyBigGAMES/OllamaBox 12 | 13 | See LICENSE file for license information 14 | ===============================================================================} 15 | 16 | unit UOllamaBox64; 17 | 18 | {$I OllamaBox.Defines.inc} 19 | 20 | interface 21 | 22 | uses 23 | OllamaBox.Utils, 24 | OllamaBox; 25 | 26 | function obCreate(): TOllamaBox; stdcall; exports obCreate; 27 | procedure obFree(var AOllamaBox: TOllamaBox); stdcall; exports obFree; 28 | function obGetVersion(const AOllamaBox: TOllamaBox): PWideChar; stdcall; exports obGetVersion; 29 | function obGetOllamaVersion(const AOllamaBox: TOllamaBox): PWideChar; stdcall; exports obGetOllamaVersion; 30 | procedure obDisplayLogo(const AOllamaBox: TOllamaBox; const AColor: PWideChar); stdcall; exports obDisplayLogo; 31 | procedure obDownloadServer(const AOllamaBox: TOllamaBox); stdcall; exports obDownloadServer; 32 | function obStartServer(const AOllamaBox: TOllamaBox): Boolean; stdcall; exports obStartServer; 33 | function obServerStarted(const AOllamaBox: TOllamaBox): Boolean; stdcall; exports obStartServer; 34 | procedure obStopServer(const AOllamaBox: TOllamaBox); stdcall; exports obStopServer; 35 | function obServerRunning(const AOllamaBox: TOllamaBox): Boolean; stdcall; exports obServerRunning; 36 | function obGetServerBaseAPIUrl(const AOllamaBox: TOllamaBox): PWideChar; stdcall; exports obGetServerBaseAPIUrl; 37 | procedure obClearSystem(const AOllamaBox: TOllamaBox); stdcall; exports obClearSystem; 38 | function obAddSystem(const AOllamaBox: TOllamaBox; const AText: PWideChar): UInt32; stdcall; exports obAddSystem; 39 | function obSystemCount(const AOllamaBox: TOllamaBox): UInt32; stdcall; exports obSystemCount; 40 | procedure obRemoveSystem(const AOllamaBox: TOllamaBox; const AIndex: UInt32); stdcall; exports obRemoveSystem; 41 | procedure obClearContext(const AOllamaBox: TOllamaBox); stdcall; exports obClearContext; 42 | function obSaveContext(const AOllamaBox: TOllamaBox; const AFilename: PWideChar): Boolean; stdcall; exports obSaveContext; 43 | function obLoadContext(const AOllamaBox: TOllamaBox; const AFilename: PWideChar): Boolean; stdcall; exports obLoadContext; 44 | procedure obClearImages(const AOllamaBox: TOllamaBox); stdcall; exports obClearImages; 45 | function obAddImage(const AOllamaBox: TOllamaBox; const AFilename: PWideChar): Boolean; stdcall; exports obAddImage; 46 | function obPull(const AOllamaBox: TOllamaBox): Boolean; stdcall; exports obPull; 47 | function obGenerate(const AOllamaBox: TOllamaBox): Boolean; stdcall; exports obGenerate; 48 | function obWebSearch(const AOllamaBox: TOllamaBox; const AQuery: PWideChar): PWideChar; stdcall; exports obWebSearch; 49 | function obGetServerPort(const AOllamaBox: TOllamaBox): UInt32; stdcall; exports obGetServerPort; 50 | procedure obSetServerPort(const AOllamaBox: TOllamaBox; const APort: UInt32); stdcall; exports obSetServerPort; 51 | function obGetModelPath(const AOllamaBox: TOllamaBox): PWideChar; stdcall; exports obGetModelPath; 52 | procedure obSetModelPath(const AOllamaBox: TOllamaBox; const APath: PWideChar); stdcall; exports obSetModelPath; 53 | function obGetServerPath(const AOllamaBox: TOllamaBox): PWideChar; stdcall; exports obGetServerPath; 54 | procedure obSetServerPath(const AOllamaBox: TOllamaBox; const APath: PWideChar); stdcall; exports obSetServerPath; 55 | function obGetServerDownloadPath(const AOllamaBox: TOllamaBox): PWideChar; stdcall; exports obGetServerDownloadPath; 56 | procedure obSetServerDownloadPath(const AOllamaBox: TOllamaBox; const APath: PWideChar); stdcall; exports obSetServerDownloadPath; 57 | function obGetModel(const AOllamaBox: TOllamaBox): PWideChar; stdcall; exports obGetModel; 58 | procedure obSetModel(const AOllamaBox: TOllamaBox; const AModel: PWideChar); stdcall; exports obSetModel; 59 | function obGetPrompt(const AOllamaBox: TOllamaBox): PWideChar; stdcall; exports obGetPrompt; 60 | procedure obSetPrompt(const AOllamaBox: TOllamaBox; const APrompt: PWideChar); stdcall; exports obSetPrompt; 61 | function obGetKeepAlive(const AOllamaBox: TOllamaBox): Int32; stdcall; exports obGetKeepAlive; 62 | procedure obSetKeepAlive(const AOllamaBox: TOllamaBox; const AKeepAlive: Int32); stdcall; exports obSetKeepAlive; 63 | function obGetMainGPU(const AOllamaBox: TOllamaBox): Int32; stdcall; exports obGetMainGPU; 64 | procedure obSetMainGPU(const AOllamaBox: TOllamaBox; const AMainGPU: Int32); stdcall; exports obSetMainGPU; 65 | function obGetGPULayers(const AOllamaBox: TOllamaBox): Int32; stdcall; exports obGetGPULayers; 66 | procedure obSetGPULayer(const AOllamaBox: TOllamaBox; const AGPULayers: Int32); stdcall; exports obSetGPULayer; 67 | function obGetMaxContext(const AOllamaBox: TOllamaBox): UInt32; stdcall; exports obGetMaxContext; 68 | procedure obSetMaxContext(const AOllamaBox: TOllamaBox; const AMaxContext: UInt32); stdcall; exports obSetMaxContext; 69 | function obGetSuffix(const AOllamaBox: TOllamaBox): PWideChar; stdcall; exports obGetSuffix; 70 | procedure obSetSuffix(const AOllamaBox: TOllamaBox; const ASuffix: PWideChar); stdcall; exports obSetSuffix; 71 | function obGetTemperature(const AOllamaBox: TOllamaBox): Single; stdcall; exports obGetTemperature; 72 | procedure obSetTemperature(const AOllamaBox: TOllamaBox; const ATemperature: Single); stdcall; exports obSetTemperature; 73 | function obGetSeed(const AOllamaBox: TOllamaBox): Int32; stdcall; exports obGetSeed; 74 | procedure obSetSeed(const AOllamaBox: TOllamaBox; const ASeed: Int32); stdcall; exports obSetSeed; 75 | function obGetThreads(const AOllamaBox: TOllamaBox): Int32; stdcall; exports obGetThreads; 76 | procedure obSetThreads(const AOllamaBox: TOllamaBox; const AThreads: Int32); stdcall; exports obSetThreads; 77 | function obGetResponse(const AOllamaBox: TOllamaBox): PWideChar; stdcall; exports obGetResponse; 78 | function obGetSystem(const AOllamaBox: TOllamaBox): PWideChar; stdcall; exports obGetSystem; 79 | function obGetInputTokens(const AOllamaBox: TOllamaBox): UInt32; stdcall; exports obGetInputTokens; 80 | function obGetOutputTokens(const AOllamaBox: TOllamaBox): UInt32; stdcall; exports obGetOutputTokens; 81 | function obGetTotalTokens(const AOllamaBox: TOllamaBox): UInt32; stdcall; exports obGetTotalTokens; 82 | function obGetSpeed(const AOllamaBox: TOllamaBox): Double; stdcall; exports obGetSpeed; 83 | function obGetTime(const AOllamaBox: TOllamaBox): Double; stdcall; exports obGetTime; 84 | function obGetWasCancelled(const AOllamaBox: TOllamaBox): Boolean; stdcall; exports obGetWasCancelled; 85 | function obGetShowThinking(const AOllamaBox: TOllamaBox): Boolean; stdcall; exports obGetShowThinking; 86 | procedure obSetShowThinking(const AOllamaBox: TOllamaBox; const AShowThinking: Boolean); stdcall; exports obSetShowThinking; 87 | function obThinking(const AOllamaBox: TOllamaBox): Boolean; stdcall; exports obThinking; 88 | function obGetShowResponding(const AOllamaBox: TOllamaBox): Boolean; stdcall; exports obGetShowResponding; 89 | procedure obSetShowResponding(const AOllamaBox: TOllamaBox; const AShowResponding: Boolean); stdcall; exports obSetShowResponding; 90 | function obResponding(const AOllamaBox: TOllamaBox): Boolean; stdcall; exports obResponding; 91 | function obHttpStatusCode(const AOllamaBox: TOllamaBox): Int32; stdcall; exports obHttpStatusCode; 92 | function obHttpStatusText(const AOllamaBox: TOllamaBox): PWideChar; stdcall; exports obHttpStatusText; 93 | 94 | const 95 | CobStart = 0; 96 | CobInProgress = 1; 97 | CobEnd = 2; 98 | 99 | type 100 | TobCallback = procedure(const AUserData: Pointer); stdcall; 101 | TobCancelCallback = function(const AUserData: Pointer): Boolean; stdcall; 102 | TobNextTokenCallback = procedure(const AToken: PWideChar; const AUserData: Pointer); stdcall; 103 | TobPullModelCallback = procedure(const AMessage: PWideChar; const APercent: Double; const AStatus: UInt32; const AUserData: Pointer); stdcall; 104 | 105 | (* 106 | 107 | TobStatus = (obStart, obInProgress, obEnd); 108 | TobCallback = reference to procedure(); 109 | TobCancelCallback = reference to function(): Boolean; 110 | TobNextTokenCallback = reference to procedure(const AToken: string); 111 | TobPullModelCallback = reference to procedure(const AMessage: string; const APercent: Double; const AStatus: TobStatus); 112 | 113 | property Context: TArray read GetContext; 114 | property OnCancel: TobCancelCallback read FOnCancel write FOnCancel; 115 | property OnNextToken: TobNextTokenCallback read FOnNextToken write FOnNextToken; 116 | property OnThinkStart: TobCallback read FOnThinkStart write FOnThinkStart; 117 | property OnThinkEnd: TobCallback read FOnThinkEnd write FOnThinkEnd; 118 | property OnResponseStart: TobCallback read FOnResponseStart write FOnResponseStart; 119 | property OnResponseEnd: TobCallback read FOnResponseEnd write FOnResponseEnd; 120 | property OnPullModel: TobPullModelCallback read FOnPullModel write FOnPullModel; 121 | property Tool: TobToolStreamProcessor read FTool; 122 | property Prompts: TobPromptDatabase read FPrompts; 123 | 124 | function obGetCancel(): TobCancelCallback; 125 | procedure obSetChancel(const AOllamaBox: TOllamaBox; const ACallback: TobCancelCallback); 126 | 127 | *) 128 | 129 | procedure obSetOnCancel(const AOllamaBox: TOllamaBox; const AHandler: TobCancelCallback; const AUserData: Pointer); stdcall; exports obSetOnCancel; 130 | procedure obSetOnNextToken(const AOllamaBox: TOllamaBox; const AHandler: TobNextTokenCallback; const AUserData: Pointer); stdcall; exports obSetOnNextToken; 131 | procedure obSetOnThinkStart(const AOllamaBox: TOllamaBox; const AHandler: TobCallback; const AUserData: Pointer); stdcall; exports obSetOnThinkStart; 132 | procedure obSetOnThinkEnd(const AOllamaBox: TOllamaBox; const AHandler: TobCallback; const AUserData: Pointer); stdcall; exports obSetOnThinkEnd; 133 | procedure obSetOnResponseStart(const AOllamaBox: TOllamaBox; const AHandler: TobCallback; const AUserData: Pointer); stdcall; exports obSetOnResponseStart; 134 | procedure obSetOnResponseEnd(const AOllamaBox: TOllamaBox; const AHandler: TobCallback; const AUserData: Pointer); stdcall; exports obSetOnResponseEnd; 135 | procedure obSetOnPullModel(const AOllamaBox: TOllamaBox; const AHandler: TobPullModelCallback; const AUserData: Pointer); stdcall; exports obSetOnPullModel; 136 | 137 | 138 | implementation 139 | 140 | procedure obSetOnCancel(const AOllamaBox: TOllamaBox; const AHandler: TobCancelCallback; const AUserData: Pointer); 141 | begin 142 | end; 143 | 144 | procedure obSetOnNextToken(const AOllamaBox: TOllamaBox; const AHandler: TobNextTokenCallback; const AUserData: Pointer); 145 | begin 146 | if not Assigned(AOllamaBox) then Exit; 147 | 148 | if not Assigned(AHandler) then 149 | AOllamaBox.OnNextToken := nil 150 | else 151 | AOllamaBox.OnNextToken := 152 | procedure (const AToken: string) 153 | begin 154 | AHandler(PWideChar(AToken), AUserData); 155 | end; 156 | end; 157 | 158 | procedure obSetOnThinkStart(const AOllamaBox: TOllamaBox; const AHandler: TobCallback; const AUserData: Pointer); 159 | begin 160 | if not Assigned(AOllamaBox) then Exit; 161 | 162 | if not Assigned(AHandler) then 163 | AOllamaBox.OnThinkStart := nil 164 | else 165 | AOllamaBox.OnThinkStart := 166 | procedure () 167 | begin 168 | AHandler(AUserData); 169 | end; 170 | end; 171 | 172 | procedure obSetOnThinkEnd(const AOllamaBox: TOllamaBox; const AHandler: TobCallback; const AUserData: Pointer); 173 | begin 174 | if not Assigned(AOllamaBox) then Exit; 175 | 176 | if not Assigned(AHandler) then 177 | AOllamaBox.OnThinkEnd := nil 178 | else 179 | AOllamaBox.OnThinkEnd := 180 | procedure () 181 | begin 182 | AHandler(AUserData); 183 | end; 184 | end; 185 | 186 | procedure obSetOnResponseStart(const AOllamaBox: TOllamaBox; const AHandler: TobCallback; const AUserData: Pointer); 187 | begin 188 | if not Assigned(AOllamaBox) then Exit; 189 | 190 | if not Assigned(AHandler) then 191 | AOllamaBox.OnResponseStart := nil 192 | else 193 | AOllamaBox.OnResponseStart := 194 | procedure () 195 | begin 196 | AHandler(AUserData); 197 | end; 198 | end; 199 | 200 | procedure obSetOnResponseEnd(const AOllamaBox: TOllamaBox; const AHandler: TobCallback; const AUserData: Pointer); 201 | begin 202 | if not Assigned(AOllamaBox) then Exit; 203 | 204 | if not Assigned(AHandler) then 205 | AOllamaBox.OnResponseEnd := nil 206 | else 207 | AOllamaBox.OnResponseEnd := 208 | procedure () 209 | begin 210 | AHandler(AUserData); 211 | end; 212 | end; 213 | 214 | procedure obSetOnPullModel(const AOllamaBox: TOllamaBox; const AHandler: TobPullModelCallback; const AUserData: Pointer); 215 | begin 216 | if not Assigned(AOllamaBox) then Exit; 217 | 218 | if not Assigned(AHandler) then 219 | AOllamaBox.OnPullModel := nil 220 | else 221 | AOllamaBox.OnPullModel := 222 | procedure (const AMessage: string; const APercent: Double; const AStatus: TobStatus) 223 | begin 224 | AHandler(PWideChar(AMessage), APercent, Ord(AStatus), AUserData); 225 | end; 226 | end; 227 | 228 | function obCreate(): TOllamaBox; 229 | begin 230 | Result := TOllamaBox.Create(); 231 | end; 232 | 233 | procedure obFree(var AOllamaBox: TOllamaBox); 234 | begin 235 | if Assigned(AOllamaBox) then 236 | begin 237 | AOllamaBox.Free(); 238 | AOllamaBox := nil; 239 | end; 240 | end; 241 | 242 | function obGetVersion(const AOllamaBox: TOllamaBox): PWideChar; 243 | begin 244 | Result := nil; 245 | if not Assigned(AOllamaBox) then Exit; 246 | Result := PWideChar(AOllamaBox.GetVersion()); 247 | end; 248 | 249 | function obGetOllamaVersion(const AOllamaBox: TOllamaBox): PWideChar; 250 | begin 251 | Result := nil; 252 | if not Assigned(AOllamaBox) then Exit; 253 | 254 | Result := PWideChar(AOllamaBox.GetOllamaVersion()); 255 | end; 256 | 257 | procedure obDisplayLogo(const AOllamaBox: TOllamaBox; const AColor: PWideChar); 258 | begin 259 | if not Assigned(AOllamaBox) then Exit; 260 | 261 | AOllamaBox.DisplayLogo(AColor); 262 | end; 263 | 264 | procedure obDownloadServer(const AOllamaBox: TOllamaBox); 265 | begin 266 | if not Assigned(AOllamaBox) then Exit; 267 | 268 | AOllamaBox.DownloadServer(); 269 | end; 270 | 271 | function obStartServer(const AOllamaBox: TOllamaBox): Boolean; 272 | begin 273 | Result := False; 274 | if not Assigned(AOllamaBox) then Exit; 275 | 276 | Result := AOllamaBox.StartServer(); 277 | end; 278 | 279 | function obServerStarted(const AOllamaBox: TOllamaBox): Boolean; 280 | begin 281 | Result := False; 282 | if not Assigned(AOllamaBox) then Exit; 283 | 284 | Result := AOllamaBox.ServerStarted(); 285 | end; 286 | 287 | procedure obStopServer(const AOllamaBox: TOllamaBox); 288 | begin 289 | if not Assigned(AOllamaBox) then Exit; 290 | 291 | AOllamaBox.StopServer(); 292 | end; 293 | 294 | function obServerRunning(const AOllamaBox: TOllamaBox): Boolean; 295 | begin 296 | Result := False; 297 | if not Assigned(AOllamaBox) then Exit; 298 | 299 | Result := AOllamaBox.ServerRunning(); 300 | end; 301 | 302 | function obGetServerBaseAPIUrl(const AOllamaBox: TOllamaBox): PWideChar; 303 | begin 304 | Result := nil; 305 | if not Assigned(AOllamaBox) then Exit; 306 | 307 | Result := PWideChar(AOllamaBox.GetServerBaseAPIUrl()); 308 | end; 309 | 310 | procedure obClearSystem(const AOllamaBox: TOllamaBox); 311 | begin 312 | if not Assigned(AOllamaBox) then Exit; 313 | 314 | AOllamaBox.ClearSystem(); 315 | end; 316 | 317 | function obAddSystem(const AOllamaBox: TOllamaBox; const AText: PWideChar): UInt32; 318 | begin 319 | Result := 0; 320 | if not Assigned(AOllamaBox) then Exit; 321 | 322 | Result := AOllamaBox.AddSystem(string(AText), []) 323 | end; 324 | 325 | function obSystemCount(const AOllamaBox: TOllamaBox): UInt32; 326 | begin 327 | Result := 0; 328 | if not Assigned(AOllamaBox) then Exit; 329 | 330 | Result := AOllamaBox.SystemCount(); 331 | end; 332 | 333 | procedure obRemoveSystem(const AOllamaBox: TOllamaBox; const AIndex: UInt32); 334 | begin 335 | if not Assigned(AOllamaBox) then Exit; 336 | 337 | AOllamaBox.RemoveSystem(AIndex); 338 | end; 339 | 340 | procedure obClearContext(const AOllamaBox: TOllamaBox); 341 | begin 342 | if not Assigned(AOllamaBox) then Exit; 343 | 344 | AOllamaBox.ClearContext(); 345 | end; 346 | 347 | function obSaveContext(const AOllamaBox: TOllamaBox; const AFilename: PWideChar): Boolean; 348 | begin 349 | Result := False; 350 | if not Assigned(AOllamaBox) then Exit; 351 | 352 | Result := AOllamaBox.SaveContext(string(AFilename)); 353 | end; 354 | 355 | function obLoadContext(const AOllamaBox: TOllamaBox; const AFilename: PWideChar): Boolean; 356 | begin 357 | Result := False; 358 | if not Assigned(AOllamaBox) then Exit; 359 | 360 | Result := AOllamaBox.LoadContext(string(AFilename)); 361 | end; 362 | 363 | procedure obClearImages(const AOllamaBox: TOllamaBox); 364 | begin 365 | if not Assigned(AOllamaBox) then Exit; 366 | 367 | AOllamaBox.ClearImages(); 368 | end; 369 | 370 | function obAddImage(const AOllamaBox: TOllamaBox; const AFilename: PWideChar): Boolean; 371 | begin 372 | Result := False; 373 | if not Assigned(AOllamaBox) then Exit; 374 | 375 | Result := AOllamaBox.AddImage(string(AFilename)); 376 | end; 377 | 378 | function obPull(const AOllamaBox: TOllamaBox): Boolean; 379 | begin 380 | Result := False; 381 | if not Assigned(AOllamaBox) then Exit; 382 | 383 | Result := AOllamaBox.Pull(); 384 | end; 385 | 386 | function obGenerate(const AOllamaBox: TOllamaBox): Boolean; 387 | begin 388 | Result := False; 389 | if not Assigned(AOllamaBox) then Exit; 390 | 391 | Result := AOllamaBox.Generate(); 392 | end; 393 | 394 | function obWebSearch(const AOllamaBox: TOllamaBox; const AQuery: PWideChar): PWideChar; 395 | begin 396 | Result := nil; 397 | if not Assigned(AOllamaBox) then Exit; 398 | 399 | Result := PWideChar(AOllamaBox.WebSearch(string(AQuery))); 400 | end; 401 | 402 | function obGetServerPort(const AOllamaBox: TOllamaBox): UInt32; 403 | begin 404 | Result := 0; 405 | if not Assigned(AOllamaBox) then Exit; 406 | 407 | Result := AOllamaBox.ServerPort; 408 | end; 409 | 410 | procedure obSetServerPort(const AOllamaBox: TOllamaBox; const APort: UInt32); 411 | begin 412 | if not Assigned(AOllamaBox) then Exit; 413 | 414 | AOllamaBox.ServerPort := APort; 415 | end; 416 | 417 | function obGetModelPath(const AOllamaBox: TOllamaBox): PWideChar; 418 | begin 419 | Result := nil; 420 | if not Assigned(AOllamaBox) then Exit; 421 | 422 | Result := PWideChar(AOllamaBox.ModelPath); 423 | end; 424 | 425 | procedure obSetModelPath(const AOllamaBox: TOllamaBox; const APath: PWideChar); 426 | begin 427 | if not Assigned(AOllamaBox) then Exit; 428 | 429 | AOllamaBox.ModelPath := string(APath); 430 | end; 431 | 432 | function obGetServerPath(const AOllamaBox: TOllamaBox): PWideChar; 433 | begin 434 | Result := nil; 435 | if not Assigned(AOllamaBox) then Exit; 436 | 437 | Result := PWideChar(AOllamaBox.ServerPath); 438 | end; 439 | 440 | procedure obSetServerPath(const AOllamaBox: TOllamaBox; const APath: PWideChar); 441 | begin 442 | if not Assigned(AOllamaBox) then Exit; 443 | 444 | AOllamaBox.ServerPath := string(APath); 445 | end; 446 | 447 | function obGetServerDownloadPath(const AOllamaBox: TOllamaBox): PWideChar; 448 | begin 449 | Result := nil; 450 | if not Assigned(AOllamaBox) then Exit; 451 | 452 | Result := PWideChar(AOllamaBox.ServerDownloadPath); 453 | end; 454 | 455 | procedure obSetServerDownloadPath(const AOllamaBox: TOllamaBox; const APath: PWideChar); 456 | begin 457 | if not Assigned(AOllamaBox) then Exit; 458 | 459 | AOllamaBox.ServerDownloadPath := string(APath); 460 | end; 461 | 462 | function obGetModel(const AOllamaBox: TOllamaBox): PWideChar; 463 | begin 464 | Result := nil; 465 | if not Assigned(AOllamaBox) then Exit; 466 | 467 | Result := PWideChar(AOllamaBox.Model); 468 | end; 469 | 470 | procedure obSetModel(const AOllamaBox: TOllamaBox; const AModel: PWideChar); 471 | begin 472 | if not Assigned(AOllamaBox) then Exit; 473 | 474 | AOllamaBox.Model := string(AModel); 475 | end; 476 | 477 | function obGetPrompt(const AOllamaBox: TOllamaBox): PWideChar; 478 | begin 479 | Result := nil; 480 | if not Assigned(AOllamaBox) then Exit; 481 | 482 | Result := PWideChar(AOllamaBox.Prompt); 483 | end; 484 | 485 | procedure obSetPrompt(const AOllamaBox: TOllamaBox; const APrompt: PWideChar); 486 | begin 487 | if not Assigned(AOllamaBox) then Exit; 488 | 489 | AOllamaBox.Prompt := string(APrompt); 490 | end; 491 | 492 | function obGetKeepAlive(const AOllamaBox: TOllamaBox): Int32; 493 | begin 494 | Result := 0; 495 | if not Assigned(AOllamaBox) then Exit; 496 | 497 | Result := AOllamaBox.KeepAlive; 498 | end; 499 | 500 | procedure obSetKeepAlive(const AOllamaBox: TOllamaBox; const AKeepAlive: Int32); 501 | begin 502 | if not Assigned(AOllamaBox) then Exit; 503 | 504 | AOllamaBox.KeepAlive := AKeepAlive; 505 | end; 506 | 507 | function obGetMainGPU(const AOllamaBox: TOllamaBox): Int32; 508 | begin 509 | Result := 0; 510 | if not Assigned(AOllamaBox) then Exit; 511 | 512 | Result := AOllamaBox.MainGPU; 513 | end; 514 | 515 | procedure obSetMainGPU(const AOllamaBox: TOllamaBox; const AMainGPU: Int32); 516 | begin 517 | if not Assigned(AOllamaBox) then Exit; 518 | 519 | AOllamaBox.MainGPU := AMainGPU; 520 | end; 521 | 522 | function obGetGPULayers(const AOllamaBox: TOllamaBox): Int32; 523 | begin 524 | Result := 0; 525 | if not Assigned(AOllamaBox) then Exit; 526 | 527 | Result := AOllamaBox.GPULayers; 528 | end; 529 | 530 | procedure obSetGPULayer(const AOllamaBox: TOllamaBox; const AGPULayers: Int32); 531 | begin 532 | if not Assigned(AOllamaBox) then Exit; 533 | 534 | AOllamaBox.GPULayers := AGPULayers; 535 | end; 536 | 537 | function obGetMaxContext(const AOllamaBox: TOllamaBox): UInt32; 538 | begin 539 | Result := 0; 540 | if not Assigned(AOllamaBox) then Exit; 541 | 542 | Result := AOllamaBox.MaxContext; 543 | end; 544 | 545 | procedure obSetMaxContext(const AOllamaBox: TOllamaBox; const AMaxContext: UInt32); 546 | begin 547 | if not Assigned(AOllamaBox) then Exit; 548 | 549 | AOllamaBox.MaxContext := AMaxContext; 550 | end; 551 | 552 | function obGetSuffix(const AOllamaBox: TOllamaBox): PWideChar; 553 | begin 554 | Result := nil; 555 | if not Assigned(AOllamaBox) then Exit; 556 | 557 | Result := PWideChar(AOllamaBox.Suffix); 558 | end; 559 | 560 | procedure obSetSuffix(const AOllamaBox: TOllamaBox; const ASuffix: PWideChar); 561 | begin 562 | if not Assigned(AOllamaBox) then Exit; 563 | 564 | AOllamaBox.Suffix := string(ASuffix); 565 | end; 566 | 567 | function obGetTemperature(const AOllamaBox: TOllamaBox): Single; 568 | begin 569 | Result := 0; 570 | if not Assigned(AOllamaBox) then Exit; 571 | 572 | Result := AOllamaBox.Temperature; 573 | end; 574 | 575 | procedure obSetTemperature(const AOllamaBox: TOllamaBox; const ATemperature: Single); 576 | begin 577 | if not Assigned(AOllamaBox) then Exit; 578 | 579 | AOllamaBox.Temperature := ATemperature; 580 | end; 581 | 582 | function obGetSeed(const AOllamaBox: TOllamaBox): Int32; 583 | begin 584 | Result := 0; 585 | if not Assigned(AOllamaBox) then Exit; 586 | 587 | Result := AOllamaBox.Seed; 588 | end; 589 | 590 | procedure obSetSeed(const AOllamaBox: TOllamaBox; const ASeed: Int32); 591 | begin 592 | if not Assigned(AOllamaBox) then Exit; 593 | 594 | AOllamaBox.Seed := ASeed; 595 | end; 596 | 597 | function obGetThreads(const AOllamaBox: TOllamaBox): Int32; 598 | begin 599 | Result := 0; 600 | if not Assigned(AOllamaBox) then Exit; 601 | 602 | Result := AOllamaBox.Threads; 603 | end; 604 | 605 | procedure obSetThreads(const AOllamaBox: TOllamaBox; const AThreads: Int32); 606 | begin 607 | if not Assigned(AOllamaBox) then Exit; 608 | 609 | AOllamaBox.Threads := AThreads; 610 | 611 | end; 612 | 613 | function obGetResponse(const AOllamaBox: TOllamaBox): PWideChar; 614 | begin 615 | Result := nil; 616 | if not Assigned(AOllamaBox) then Exit; 617 | 618 | Result := PWideChar(AOllamaBox.Response); 619 | end; 620 | 621 | function obGetSystem(const AOllamaBox: TOllamaBox): PWideChar; 622 | begin 623 | Result := nil; 624 | if not Assigned(AOllamaBox) then Exit; 625 | 626 | Result := PWideChar(AOllamaBox.System); 627 | end; 628 | 629 | function obGetInputTokens(const AOllamaBox: TOllamaBox): UInt32; 630 | begin 631 | Result := 0; 632 | if not Assigned(AOllamaBox) then Exit; 633 | 634 | Result := AOllamaBox.InputTokens; 635 | end; 636 | 637 | function obGetOutputTokens(const AOllamaBox: TOllamaBox): UInt32; 638 | begin 639 | Result := 0; 640 | if not Assigned(AOllamaBox) then Exit; 641 | 642 | Result := AOllamaBox.OutputTokens; 643 | end; 644 | 645 | function obGetTotalTokens(const AOllamaBox: TOllamaBox): UInt32; 646 | begin 647 | Result := 0; 648 | if not Assigned(AOllamaBox) then Exit; 649 | 650 | Result := AOllamaBox.TotalTokens; 651 | end; 652 | 653 | function obGetSpeed(const AOllamaBox: TOllamaBox): Double; 654 | begin 655 | Result := 0; 656 | if not Assigned(AOllamaBox) then Exit; 657 | 658 | Result := AOllamaBox.Speed; 659 | end; 660 | 661 | function obGetTime(const AOllamaBox: TOllamaBox): Double; 662 | begin 663 | Result := 0; 664 | if not Assigned(AOllamaBox) then Exit; 665 | 666 | Result := AOllamaBox.Time; 667 | end; 668 | 669 | function obGetWasCancelled(const AOllamaBox: TOllamaBox): Boolean; 670 | begin 671 | Result := False; 672 | if not Assigned(AOllamaBox) then Exit; 673 | 674 | Result := AOllamaBox.WasCancelled; 675 | end; 676 | 677 | function obGetShowThinking(const AOllamaBox: TOllamaBox): Boolean; 678 | begin 679 | Result := False; 680 | if not Assigned(AOllamaBox) then Exit; 681 | 682 | Result := AOllamaBox.ShowThinking; 683 | end; 684 | 685 | procedure obSetShowThinking(const AOllamaBox: TOllamaBox; const AShowThinking: Boolean); 686 | begin 687 | if not Assigned(AOllamaBox) then Exit; 688 | 689 | AOllamaBox.ShowThinking := AShowThinking; 690 | end; 691 | 692 | function obThinking(const AOllamaBox: TOllamaBox): Boolean; 693 | begin 694 | Result := False; 695 | if not Assigned(AOllamaBox) then Exit; 696 | 697 | Result := AOllamaBox.Thinking; 698 | end; 699 | 700 | function obGetShowResponding(const AOllamaBox: TOllamaBox): Boolean; 701 | begin 702 | Result := False; 703 | if not Assigned(AOllamaBox) then Exit; 704 | 705 | Result := AOllamaBox.ShowResponding; 706 | end; 707 | 708 | procedure obSetShowResponding(const AOllamaBox: TOllamaBox; const AShowResponding: Boolean); 709 | begin 710 | if not Assigned(AOllamaBox) then Exit; 711 | 712 | AOllamaBox.ShowResponding := AShowResponding; 713 | end; 714 | 715 | function obResponding(const AOllamaBox: TOllamaBox): Boolean; 716 | begin 717 | Result := False; 718 | if not Assigned(AOllamaBox) then Exit; 719 | 720 | Result := AOllamaBox.Responding; 721 | end; 722 | 723 | function obHttpStatusCode(const AOllamaBox: TOllamaBox): Int32; 724 | begin 725 | Result := 0; 726 | if not Assigned(AOllamaBox) then Exit; 727 | 728 | Result := AOllamaBox.HttpStatusCode; 729 | end; 730 | 731 | function obHttpStatusText(const AOllamaBox: TOllamaBox): PWideChar; 732 | begin 733 | Result := nil; 734 | if not Assigned(AOllamaBox) then Exit; 735 | 736 | Result := PWideChar(AOllamaBox.HttpStatusText); 737 | end; 738 | 739 | end. 740 | -------------------------------------------------------------------------------- /src/OllamaBox - Embed & Control Ollama In Your Delphi App.groupproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | {B30647FC-6D28-44A2-AA8B-8FE41F334C82} 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | Default.Personality.12 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 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/OllamaBox.Defines.inc: -------------------------------------------------------------------------------- 1 | {=============================================================================== 2 | ___ _ _ ___ 3 | / _ \| | |__ _ _ __ __ _| _ ) _____ __™ 4 | | (_) | | / _` | ' \/ _` | _ \/ _ \ \ / 5 | \___/|_|_\__,_|_|_|_\__,_|___/\___/_\_\ 6 | Embed & Control Ollama In Your Delphi App 7 | 8 | Copyright © 2025-present tinyBigGAMES™ LLC 9 | All Rights Reserved. 10 | 11 | https://github.com/tinyBigGAMES/OllamaBox 12 | 13 | See LICENSE file for license information 14 | ===============================================================================} 15 | 16 | {$WARN SYMBOL_DEPRECATED OFF} 17 | {$WARN SYMBOL_PLATFORM OFF} 18 | 19 | {$WARN UNIT_PLATFORM OFF} 20 | {$WARN UNIT_DEPRECATED OFF} 21 | 22 | {$Z4} 23 | {$A8} 24 | 25 | {$INLINE AUTO} 26 | 27 | {$IFNDEF WIN64} 28 | {$MESSAGE Error 'Unsupported platform'} 29 | {$ENDIF} 30 | 31 | {$IF (CompilerVersion < 36.0)} 32 | {$IFNDEF WIN64} 33 | {$MESSAGE Error 'Must use Delphi 12 or higher'} 34 | {$ENDIF} 35 | {$IFEND} 36 | -------------------------------------------------------------------------------- /src/OllamaBox64.h: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | ___ _ _ ___ 3 | / _ \| | |__ _ _ __ __ _| _ ) _____ __™ 4 | | (_) | | / _` | ' \/ _` | _ \/ _ \ \ / 5 | \___/|_|_\__,_|_|_|_\__,_|___/\___/_\_\ 6 | Embed & Control Ollama In Your Delphi App 7 | 8 | Copyright © 2025-present tinyBigGAMES™ LLC 9 | All Rights Reserved. 10 | 11 | https://github.com/tinyBigGAMES/OllamaBox 12 | 13 | See LICENSE file for license information 14 | *******************************************************************************/ 15 | 16 | #ifndef OLLAMABOX64_H 17 | #define OLLAMABOX64_H 18 | 19 | // Check for supported platform 20 | #ifndef _WIN64 21 | #error "Unsupported platform" 22 | #endif 23 | 24 | // Link in OllamaBox64.lib 25 | #pragma comment(lib,"OllamaBox64.lib") 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | #include 32 | #include 33 | 34 | #define CobStart 0 35 | #define CobInProgress 1 36 | #define CcbEnd 2 37 | 38 | typedef void* TOllamaBox; 39 | 40 | typedef void (__stdcall *TobCallback)(void* AUserData); 41 | typedef int (__stdcall *TobCancelCallback)(void* AUserData); 42 | typedef void (__stdcall *TobNextTokenCallback)(const wchar_t* AToken, void* AUserData); 43 | typedef void (__stdcall *TobPullModelCallback)(const wchar_t* AMessage, double APercent, uint32_t AStatus, void* AUserData); 44 | 45 | TOllamaBox __stdcall obCreate(void); 46 | void __stdcall obFree(TOllamaBox* AOllamaBox); 47 | 48 | void __stdcall obSetOnCancel(TOllamaBox AOllamaBox, TobCancelCallback AHandler, void* AUserData); 49 | void __stdcall obSetOnNextToken(TOllamaBox AOllamaBox, TobNextTokenCallback AHandler, void* AUserData); 50 | void __stdcall obSetOnThinkStart(TOllamaBox AOllamaBox, TobCallback AHandler, void* AUserData); 51 | void __stdcall obSetOnThinkEnd(TOllamaBox AOllamaBox, TobCallback AHandler, void* AUserData); 52 | void __stdcall obSetOnResponseStart(TOllamaBox AOllamaBox, TobCallback AHandler, void* AUserData); 53 | void __stdcall obSetOnResponseEnd(TOllamaBox AOllamaBox, TobCallback AHandler, void* AUserData); 54 | void __stdcall obSetOnPullModel(TOllamaBox AOllamaBox, TobPullModelCallback AHandler, void* AUserData); 55 | 56 | const wchar_t* __stdcall obGetVersion(TOllamaBox AOllamaBox); 57 | const wchar_t* __stdcall obGetOllamaVersion(TOllamaBox AOllamaBox); 58 | void __stdcall obDisplayLogo(TOllamaBox AOllamaBox, const wchar_t* AColor); 59 | void __stdcall obDownloadServer(TOllamaBox AOllamaBox); 60 | int __stdcall obStartServer(TOllamaBox AOllamaBox); 61 | int __stdcall obServerStarted(TOllamaBox AOllamaBox); 62 | void __stdcall obStopServer(TOllamaBox AOllamaBox); 63 | int __stdcall obServerRunning(TOllamaBox AOllamaBox); 64 | 65 | const wchar_t* __stdcall obGetServerBaseAPIUrl(TOllamaBox AOllamaBox); 66 | void __stdcall obClearSystem(TOllamaBox AOllamaBox); 67 | uint32_t __stdcall obAddSystem(TOllamaBox AOllamaBox, const wchar_t* AText); 68 | uint32_t __stdcall obSystemCount(TOllamaBox AOllamaBox); 69 | void __stdcall obRemoveSystem(TOllamaBox AOllamaBox, uint32_t AIndex); 70 | const wchar_t* __stdcall obGetSystem(TOllamaBox AOllamaBox); 71 | 72 | void __stdcall obClearContext(TOllamaBox AOllamaBox); 73 | int __stdcall obSaveContext(TOllamaBox AOllamaBox, const wchar_t* AFilename); 74 | int __stdcall obLoadContext(TOllamaBox AOllamaBox, const wchar_t* AFilename); 75 | 76 | void __stdcall obClearImages(TOllamaBox AOllamaBox); 77 | int __stdcall obAddImage(TOllamaBox AOllamaBox, const wchar_t* AFilename); 78 | int __stdcall obPull(TOllamaBox AOllamaBox); 79 | int __stdcall obGenerate(TOllamaBox AOllamaBox); 80 | 81 | const wchar_t* __stdcall obWebSearch(TOllamaBox AOllamaBox, const wchar_t* AQuery); 82 | uint32_t __stdcall obGetServerPort(TOllamaBox AOllamaBox); 83 | void __stdcall obSetServerPort(TOllamaBox AOllamaBox, uint32_t APort); 84 | const wchar_t* __stdcall obGetModelPath(TOllamaBox AOllamaBox); 85 | void __stdcall obSetModelPath(TOllamaBox AOllamaBox, const wchar_t* APath); 86 | const wchar_t* __stdcall obGetServerPath(TOllamaBox AOllamaBox); 87 | void __stdcall obSetServerPath(TOllamaBox AOllamaBox, const wchar_t* APath); 88 | const wchar_t* __stdcall obGetServerDownloadPath(TOllamaBox AOllamaBox); 89 | void __stdcall obSetServerDownloadPath(TOllamaBox AOllamaBox, const wchar_t* APath); 90 | const wchar_t* __stdcall obGetModel(TOllamaBox AOllamaBox); 91 | void __stdcall obSetModel(TOllamaBox AOllamaBox, const wchar_t* AModel); 92 | const wchar_t* __stdcall obGetPrompt(TOllamaBox AOllamaBox); 93 | void __stdcall obSetPrompt(TOllamaBox AOllamaBox, const wchar_t* APrompt); 94 | 95 | int32_t __stdcall obGetKeepAlive(TOllamaBox AOllamaBox); 96 | void __stdcall obSetKeepAlive(TOllamaBox AOllamaBox, int32_t AKeepAlive); 97 | int32_t __stdcall obGetMainGPU(TOllamaBox AOllamaBox); 98 | void __stdcall obSetMainGPU(TOllamaBox AOllamaBox, int32_t AMainGPU); 99 | int32_t __stdcall obGetGPULayers(TOllamaBox AOllamaBox); 100 | void __stdcall obSetGPULayer(TOllamaBox AOllamaBox, int32_t AGPULayers); 101 | uint32_t __stdcall obGetMaxContext(TOllamaBox AOllamaBox); 102 | void __stdcall obSetMaxContext(TOllamaBox AOllamaBox, uint32_t AMaxContext); 103 | const wchar_t* __stdcall obGetSuffix(TOllamaBox AOllamaBox); 104 | void __stdcall obSetSuffix(TOllamaBox AOllamaBox, const wchar_t* ASuffix); 105 | float __stdcall obGetTemperature(TOllamaBox AOllamaBox); 106 | void __stdcall obSetTemperature(TOllamaBox AOllamaBox, float ATemperature); 107 | int32_t __stdcall obGetSeed(TOllamaBox AOllamaBox); 108 | void __stdcall obSetSeed(TOllamaBox AOllamaBox, int32_t ASeed); 109 | int32_t __stdcall obGetThreads(TOllamaBox AOllamaBox); 110 | void __stdcall obSetThreads(TOllamaBox AOllamaBox, int32_t AThreads); 111 | 112 | const wchar_t* __stdcall obGetResponse(TOllamaBox AOllamaBox); 113 | uint32_t __stdcall obGetInputTokens(TOllamaBox AOllamaBox); 114 | uint32_t __stdcall obGetOutputTokens(TOllamaBox AOllamaBox); 115 | uint32_t __stdcall obGetTotalTokens(TOllamaBox AOllamaBox); 116 | double __stdcall obGetSpeed(TOllamaBox AOllamaBox); 117 | double __stdcall obGetTime(TOllamaBox AOllamaBox); 118 | int __stdcall obGetWasCancelled(TOllamaBox AOllamaBox); 119 | 120 | int __stdcall obGetShowThinking(TOllamaBox AOllamaBox); 121 | void __stdcall obSetShowThinking(TOllamaBox AOllamaBox, int AShowThinking); 122 | int __stdcall obThinking(TOllamaBox AOllamaBox); 123 | int __stdcall obGetShowResponding(TOllamaBox AOllamaBox); 124 | void __stdcall obSetShowResponding(TOllamaBox AOllamaBox, int AShowResponding); 125 | int __stdcall obResponding(TOllamaBox AOllamaBox); 126 | 127 | int32_t __stdcall obHttpStatusCode(TOllamaBox AOllamaBox); 128 | const wchar_t* __stdcall obHttpStatusText(TOllamaBox AOllamaBox); 129 | 130 | #ifdef __cplusplus 131 | } 132 | #endif 133 | 134 | #endif // OLLAMABOX64_H 135 | -------------------------------------------------------------------------------- /src/OllamaBox64.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinyBigGAMES/OllamaBox/a99f30e598493e224de5bcb5f230048239ebe08a/src/OllamaBox64.lib -------------------------------------------------------------------------------- /src/OllamaBox64.pas: -------------------------------------------------------------------------------- 1 | {=============================================================================== 2 | ___ _ _ ___ 3 | / _ \| | |__ _ _ __ __ _| _ ) _____ __™ 4 | | (_) | | / _` | ' \/ _` | _ \/ _ \ \ / 5 | \___/|_|_\__,_|_|_|_\__,_|___/\___/_\_\ 6 | Embed & Control Ollama In Your Delphi App 7 | 8 | Copyright © 2025-present tinyBigGAMES™ LLC 9 | All Rights Reserved. 10 | 11 | https://github.com/tinyBigGAMES/OllamaBox 12 | 13 | See LICENSE file for license information 14 | ===============================================================================} 15 | 16 | unit OllamaBox64; 17 | 18 | interface 19 | 20 | const 21 | COllamaBoxDLL = 'OllamaBox64.dll'; 22 | 23 | CobStart = 0; 24 | CobInProgress = 1; 25 | CobEnd = 2; 26 | 27 | type 28 | /// 29 | /// A generic pointer representing an opaque handle to a TOllamaBox instance 30 | /// managed by the OllamaBox DLL. 31 | /// 32 | /// 33 | /// This pointer type is used to abstract the internal structure of the object when 34 | /// exposing it to foreign code or other languages. It must be created and released 35 | /// using and . 36 | /// 37 | TOllamaBox = Pointer; 38 | 39 | /// 40 | /// A simple callback procedure with no parameters, except for user-defined context. 41 | /// 42 | /// 43 | /// A pointer to user-defined data passed back when the callback is invoked. 44 | /// 45 | /// 46 | /// Use this for lifecycle events like thinking start/end or response start/end. 47 | /// 48 | TobCallback = procedure(const AUserData: Pointer); stdcall; 49 | 50 | /// 51 | /// A callback function used to check whether the current operation should be cancelled. 52 | /// 53 | /// 54 | /// A pointer to user-defined data passed back to determine cancellation contextually. 55 | /// 56 | /// 57 | /// True if the operation should be cancelled; otherwise, False. 58 | /// 59 | /// 60 | /// This callback is invoked periodically during inference and model pulls 61 | /// to support user interruption or timeout logic. 62 | /// 63 | TobCancelCallback = function(const AUserData: Pointer): Boolean; stdcall; 64 | 65 | /// 66 | /// A callback procedure that is invoked for each token generated by the model. 67 | /// 68 | /// 69 | /// A pointer to a null-terminated wide string representing the current output token. 70 | /// 71 | /// 72 | /// A pointer to user-defined context data. 73 | /// 74 | /// 75 | /// This callback enables token-by-token streaming and real-time output display. 76 | /// The token is provided as UTF-16 (PWideChar) for wide platform compatibility. 77 | /// 78 | TobNextTokenCallback = procedure( 79 | const AToken: PWideChar; 80 | const AUserData: Pointer 81 | ); stdcall; 82 | 83 | /// 84 | /// A callback procedure that provides real-time status updates during model downloading. 85 | /// 86 | /// 87 | /// A pointer to a null-terminated wide string describing the current download step. 88 | /// 89 | /// 90 | /// A floating-point percentage (0.0 to 100.0) indicating download progress. 91 | /// 92 | /// 93 | /// A numeric status code representing the operation phase: 94 | /// 0 = Start, 1 = In Progress, 2 = End. 95 | /// 96 | /// 97 | /// A pointer to user-defined data associated with the download session. 98 | /// 99 | /// 100 | /// This callback provides structured progress feedback to the caller, 101 | /// allowing for integration with progress bars, logs, or UI updates. 102 | /// 103 | TobPullModelCallback = procedure( 104 | const AMessage: PWideChar; 105 | const APercent: Double; 106 | const AStatus: UInt32; 107 | const AUserData: Pointer 108 | ); stdcall; 109 | 110 | /// 111 | /// Creates and returns a new instance of the class from the external DLL. 112 | /// 113 | /// 114 | /// A newly allocated instance managed externally via the OllamaBox DLL. 115 | /// 116 | /// 117 | /// This function is declared with stdcall calling convention for compatibility with 118 | /// external languages such as C, C++, or other environments interfacing with the DLL. 119 | /// The returned object must be freed using . 120 | /// 121 | function obCreate(): TOllamaBox; stdcall; external COllamaBoxDLL; 122 | 123 | /// 124 | /// Releases a previously created instance. 125 | /// 126 | /// 127 | /// A reference to the instance to free. 128 | /// 129 | /// 130 | /// After calling this function, the passed-in reference is invalid and should not be accessed. 131 | /// This is the counterpart to and must be used to avoid memory leaks 132 | /// when working with the OllamaBox DLL from outside Delphi. 133 | /// 134 | procedure obFree(var AOllamaBox: TOllamaBox); stdcall; external COllamaBoxDLL; 135 | 136 | /// 137 | /// Registers a cancellation callback for the specified instance. 138 | /// 139 | /// 140 | /// A handle to the TOllamaBox instance returned by . 141 | /// 142 | /// 143 | /// A callback function of type to be called during inference or pull operations. 144 | /// 145 | /// 146 | /// A user-defined pointer that will be passed back to the callback when invoked. 147 | /// 148 | /// 149 | /// The cancellation callback allows external code to interrupt long-running operations 150 | /// such as model generation or download. The callback will be polled periodically, 151 | /// and should return True to abort the current process. 152 | /// 153 | procedure obSetOnCancel( 154 | const AOllamaBox: TOllamaBox; 155 | const AHandler: TobCancelCallback; 156 | const AUserData: Pointer 157 | ); stdcall; external COllamaBoxDLL; 158 | 159 | /// 160 | /// Registers a streaming token callback for the specified instance. 161 | /// 162 | /// 163 | /// A handle to the TOllamaBox instance returned by . 164 | /// 165 | /// 166 | /// A callback procedure of type that will be invoked as each token is generated. 167 | /// 168 | /// 169 | /// A user-defined pointer that will be passed to the callback on each invocation. 170 | /// 171 | /// 172 | /// This callback is called once per generated token during the model's response phase. 173 | /// It enables real-time streaming, progressive display, or external output processing. 174 | /// 175 | procedure obSetOnNextToken( 176 | const AOllamaBox: TOllamaBox; 177 | const AHandler: TobNextTokenCallback; 178 | const AUserData: Pointer 179 | ); stdcall; external COllamaBoxDLL; 180 | 181 | /// 182 | /// Registers a callback to be invoked immediately before the model begins its "thinking" phase. 183 | /// 184 | /// 185 | /// A handle to the instance. 186 | /// 187 | /// 188 | /// A procedure of type to be called at the start of thinking. 189 | /// 190 | /// 191 | /// A pointer to user-defined data that will be passed to the callback when invoked. 192 | /// 193 | /// 194 | /// This callback is typically used to update the UI or prepare the application 195 | /// for upcoming token generation. It fires just before inference begins. 196 | /// 197 | procedure obSetOnThinkStart( 198 | const AOllamaBox: TOllamaBox; 199 | const AHandler: TobCallback; 200 | const AUserData: Pointer 201 | ); stdcall; external COllamaBoxDLL; 202 | 203 | /// 204 | /// Registers a callback to be invoked immediately after the model completes its "thinking" phase. 205 | /// 206 | /// 207 | /// A handle to the instance. 208 | /// 209 | /// 210 | /// A procedure of type to be called when thinking ends. 211 | /// 212 | /// 213 | /// A pointer to user-defined data that will be passed to the callback when invoked. 214 | /// 215 | /// 216 | /// This callback is typically used to conclude loading indicators or transition the application 217 | /// into the response streaming phase. It is triggered right before tokens begin streaming. 218 | /// 219 | procedure obSetOnThinkEnd( 220 | const AOllamaBox: TOllamaBox; 221 | const AHandler: TobCallback; 222 | const AUserData: Pointer 223 | ); stdcall; external COllamaBoxDLL; 224 | 225 | /// 226 | /// Registers a callback to be invoked just before the model begins streaming its response. 227 | /// 228 | /// 229 | /// A handle to the instance. 230 | /// 231 | /// 232 | /// A procedure of type to be executed at the start of the response phase. 233 | /// 234 | /// 235 | /// A pointer to user-defined data passed back to the callback. 236 | /// 237 | /// 238 | /// This callback occurs immediately after the "thinking" phase ends and before the first token 239 | /// is emitted by the model. It is commonly used to prepare the UI for output, such as starting 240 | /// visual feedback or enabling a response container. 241 | /// 242 | procedure obSetOnResponseStart( 243 | const AOllamaBox: TOllamaBox; 244 | const AHandler: TobCallback; 245 | const AUserData: Pointer 246 | ); stdcall; external COllamaBoxDLL; 247 | 248 | /// 249 | /// Registers a callback to be invoked after the model finishes generating its response. 250 | /// 251 | /// 252 | /// A handle to the instance. 253 | /// 254 | /// 255 | /// A procedure of type to be executed at the end of the response phase. 256 | /// 257 | /// 258 | /// A pointer to user-defined data passed back to the callback. 259 | /// 260 | /// 261 | /// This callback is triggered when the model has finished generating all tokens 262 | /// or the operation has been cancelled. It can be used to finalize UI updates, 263 | /// hide streaming indicators, or enable follow-up actions. 264 | /// 265 | procedure obSetOnResponseEnd( 266 | const AOllamaBox: TOllamaBox; 267 | const AHandler: TobCallback; 268 | const AUserData: Pointer 269 | ); stdcall; external COllamaBoxDLL; 270 | 271 | /// 272 | /// Registers a callback for receiving progress updates during a model pull operation from the Ollama registry. 273 | /// 274 | /// 275 | /// A handle to the instance. 276 | /// 277 | /// 278 | /// A procedure of type to receive pull progress, status messages, and phase updates. 279 | /// 280 | /// 281 | /// A user-defined pointer that will be passed to the callback for contextual reference. 282 | /// 283 | /// 284 | /// This callback is invoked during model download and setup operations. 285 | /// It allows the application to show progress bars, log messages, or handle cancellation UI. 286 | /// 287 | procedure obSetOnPullModel( 288 | const AOllamaBox: TOllamaBox; 289 | const AHandler: TobPullModelCallback; 290 | const AUserData: Pointer 291 | ); stdcall; external COllamaBoxDLL; 292 | 293 | /// 294 | /// Returns the SemVer version string of the TOllamaBox wrapper. 295 | /// 296 | /// 297 | /// A handle to the instance. 298 | /// 299 | /// 300 | /// A pointer to a null-terminated wide string (UTF-16) containing the wrapper version (e.g., "1.0.0"). 301 | /// 302 | /// 303 | /// This version reflects the version of the OllamaBox library itself, not the Ollama runtime. 304 | /// It follows Semantic Versioning: MAJOR.MINOR.PATCH. 305 | /// 306 | function obGetVersion(const AOllamaBox: TOllamaBox): PWideChar; stdcall; external COllamaBoxDLL; 307 | 308 | /// 309 | /// Returns the version string of the Ollama runtime currently installed or running. 310 | /// 311 | /// 312 | /// A handle to the instance. 313 | /// 314 | /// 315 | /// A pointer to a null-terminated wide string (UTF-16) representing the Ollama runtime version (e.g., "0.1.34"). 316 | /// 317 | /// 318 | /// This version is retrieved from the Ollama server itself, and can be used to check compatibility 319 | /// between the host wrapper and the runtime backend. 320 | /// 321 | function obGetOllamaVersion(const AOllamaBox: TOllamaBox): PWideChar; stdcall; external COllamaBoxDLL; 322 | 323 | /// 324 | /// Displays the ASCII logo to the active console using the specified text color. 325 | /// 326 | /// 327 | /// A handle to the instance. 328 | /// 329 | /// 330 | /// A pointer to a null-terminated wide string representing the desired color name (e.g., "Green", "Cyan"). 331 | /// 332 | /// 333 | /// The color must match a recognized console color name based on the CIS (Common Interface Specification) color set. 334 | /// If the color is invalid or unsupported, a default console color will be used. 335 | /// This function writes directly to the standard output stream. 336 | /// 337 | procedure obDisplayLogo( 338 | const AOllamaBox: TOllamaBox; 339 | const AColor: PWideChar 340 | ); stdcall; external COllamaBoxDLL; 341 | 342 | /// 343 | /// Downloads and extracts the Ollama server binary from its official GitHub release. 344 | /// 345 | /// 346 | /// A handle to the instance. 347 | /// 348 | /// 349 | /// This method retrieves the latest Ollama release, stores it in the ServerDownloadPath, 350 | /// and extracts the server executable to ServerPath. 351 | /// It is required before calling unless the server has already been downloaded. 352 | /// 353 | procedure obDownloadServer( 354 | const AOllamaBox: TOllamaBox 355 | ); stdcall; external COllamaBoxDLL; 356 | 357 | /// 358 | /// Starts the embedded Ollama server in the current application process. 359 | /// 360 | /// 361 | /// A handle to the instance. 362 | /// 363 | /// 364 | /// True if the server was successfully started; otherwise, False. 365 | /// 366 | /// 367 | /// The server executable must already be present at the path specified by ServerPath, 368 | /// typically via a prior call to . This method launches the Ollama 369 | /// server within the same process context without creating an external service or detached process. 370 | /// 371 | function obStartServer(const AOllamaBox: TOllamaBox): Boolean; stdcall; external COllamaBoxDLL; 372 | 373 | /// 374 | /// Determines whether the Ollama server has already been started in the current process. 375 | /// 376 | /// 377 | /// A handle to the instance. 378 | /// 379 | /// 380 | /// True if the Ollama server is currently running inside the application; otherwise, False. 381 | /// 382 | /// 383 | /// This method checks the internal state of the process and does not inspect system services 384 | /// or external processes. Use it to verify whether has already been called. 385 | /// 386 | function obServerStarted(const AOllamaBox: TOllamaBox): Boolean; stdcall; external COllamaBoxDLL; 387 | 388 | /// 389 | /// Stops the embedded Ollama server running inside the current application process. 390 | /// 391 | /// 392 | /// A handle to the instance. 393 | /// 394 | /// 395 | /// This method terminates the locally started Ollama server that was launched using 396 | /// . It has no effect if the server is not running. 397 | /// Resources associated with the server will be released. 398 | /// 399 | procedure obStopServer(const AOllamaBox: TOllamaBox); stdcall; external COllamaBoxDLL; 400 | 401 | /// 402 | /// Checks whether the Ollama server is running and accessible via its local API endpoint. 403 | /// 404 | /// 405 | /// A handle to the instance. 406 | /// 407 | /// 408 | /// True if the server is running and responding to requests at its base URL; otherwise, False. 409 | /// 410 | /// 411 | /// Unlike , this method performs a connectivity check 412 | /// (e.g., ping or version request) against the server endpoint returned by . 413 | /// 414 | function obServerRunning(const AOllamaBox: TOllamaBox): Boolean; stdcall; external COllamaBoxDLL; 415 | 416 | /// 417 | /// Returns the base API URL used to communicate with the embedded Ollama server. 418 | /// 419 | /// 420 | /// A handle to the instance. 421 | /// 422 | /// 423 | /// A pointer to a null-terminated wide string containing the full base URL 424 | /// (e.g., "http://localhost:11434"). 425 | /// 426 | /// 427 | /// This URL includes the host and port defined by the ServerPort property 428 | /// and is used as the root endpoint for all local API requests. 429 | /// 430 | function obGetServerBaseAPIUrl(const AOllamaBox: TOllamaBox): PWideChar; stdcall; external COllamaBoxDLL; 431 | 432 | /// 433 | /// Clears all system prompts from the current conversation context. 434 | /// 435 | /// 436 | /// A handle to the instance. 437 | /// 438 | /// 439 | /// This removes all previously added system instructions that guide the model's behavior. 440 | /// After calling this method, the model will no longer be influenced by prior system-level directives 441 | /// unless new ones are added using . 442 | /// 443 | procedure obClearSystem(const AOllamaBox: TOllamaBox); stdcall; external COllamaBoxDLL; 444 | 445 | /// 446 | /// Adds a system prompt to the conversation context, which influences the model's behavior. 447 | /// 448 | /// 449 | /// A handle to the instance. 450 | /// 451 | /// 452 | /// A null-terminated wide string containing the system instruction or behavioral directive. 453 | /// 454 | /// 455 | /// The zero-based index of the newly added system prompt. 456 | /// 457 | /// 458 | /// System prompts are used to establish rules, persona, tone, or formatting expectations. 459 | /// They are submitted to the model before user prompts during inference. 460 | /// 461 | function obAddSystem(const AOllamaBox: TOllamaBox; const AText: PWideChar): UInt32; stdcall; external COllamaBoxDLL; 462 | 463 | /// 464 | /// Returns the number of system prompts currently added to the conversation context. 465 | /// 466 | /// 467 | /// A handle to the instance. 468 | /// 469 | /// 470 | /// A 32-bit unsigned integer representing the total number of active system prompts. 471 | /// 472 | /// 473 | /// This reflects the count of prompts added using . 474 | /// 475 | function obSystemCount(const AOllamaBox: TOllamaBox): UInt32; stdcall; external COllamaBoxDLL; 476 | 477 | /// 478 | /// Removes a specific system prompt by index from the conversation context. 479 | /// 480 | /// 481 | /// A handle to the instance. 482 | /// 483 | /// 484 | /// The zero-based index of the system prompt to remove. 485 | /// 486 | /// 487 | /// If the specified index is out of bounds, the call may be ignored or raise an internal error, 488 | /// depending on the implementation. Use to validate the index range. 489 | /// 490 | procedure obRemoveSystem(const AOllamaBox: TOllamaBox; const AIndex: UInt32); stdcall; external COllamaBoxDLL; 491 | 492 | /// 493 | /// Returns the concatenated content of all active system prompts. 494 | /// 495 | /// 496 | /// A handle to the instance. 497 | /// 498 | /// 499 | /// A pointer to a null-terminated wide string containing all system prompts combined into one block. 500 | /// 501 | /// 502 | /// This is useful for displaying, logging, or exporting the currently active system instructions 503 | /// in their full concatenated form. 504 | /// 505 | function obGetSystem(const AOllamaBox: TOllamaBox): PWideChar; stdcall; external COllamaBoxDLL; 506 | 507 | /// 508 | /// Clears the current token-based conversation context. 509 | /// 510 | /// 511 | /// A handle to the instance. 512 | /// 513 | /// 514 | /// This removes all prior input tokens, system prompts, and response history 515 | /// from memory, effectively resetting the session. 516 | /// Use this when beginning a new, unrelated interaction with the model. 517 | /// 518 | procedure obClearContext(const AOllamaBox: TOllamaBox); stdcall; external COllamaBoxDLL; 519 | 520 | /// 521 | /// Saves the current model context (tokens, system, history) to a file. 522 | /// 523 | /// 524 | /// A handle to the instance. 525 | /// 526 | /// 527 | /// A null-terminated wide string representing the path to the context file to create. 528 | /// 529 | /// 530 | /// True if the context was successfully written to disk; otherwise, False. 531 | /// 532 | /// 533 | /// The context file includes model token memory and may also contain system and prompt structure, 534 | /// depending on implementation. It can be restored later using . 535 | /// 536 | function obSaveContext(const AOllamaBox: TOllamaBox; const AFilename: PWideChar): Boolean; stdcall; external COllamaBoxDLL; 537 | 538 | /// 539 | /// Loads a previously saved conversation context from a file. 540 | /// 541 | /// 542 | /// A handle to the instance. 543 | /// 544 | /// 545 | /// A null-terminated wide string representing the path to the context file to load. 546 | /// 547 | /// 548 | /// True if the context was successfully loaded; otherwise, False. 549 | /// 550 | /// 551 | /// This restores the full model session state, allowing inference to continue from 552 | /// where it previously left off. Only context files generated by 553 | /// are guaranteed to be compatible. 554 | /// 555 | function obLoadContext(const AOllamaBox: TOllamaBox; const AFilename: PWideChar): Boolean; stdcall; external COllamaBoxDLL; 556 | 557 | /// 558 | /// Clears all previously added image inputs from the current conversation context. 559 | /// 560 | /// 561 | /// A handle to the instance. 562 | /// 563 | /// 564 | /// This resets the internal image array, removing all images that were added 565 | /// using . It is typically called before starting a new 566 | /// multimodal inference request. 567 | /// 568 | procedure obClearImages(const AOllamaBox: TOllamaBox); stdcall; external COllamaBoxDLL; 569 | 570 | /// 571 | /// Adds an image to the current input context for use with multimodal models that support image input. 572 | /// 573 | /// 574 | /// A handle to the instance. 575 | /// 576 | /// 577 | /// A null-terminated wide string containing the full path to the image file to be added. 578 | /// 579 | /// 580 | /// True if the image was successfully loaded and processed; otherwise, False. 581 | /// 582 | /// 583 | /// The image will be converted to a base64-encoded representation internally 584 | /// and attached to the input for use with vision-capable models like LLaVA, Gemma-Vision, etc. 585 | /// Supported formats typically include PNG and JPEG. 586 | /// 587 | function obAddImage(const AOllamaBox: TOllamaBox; const AFilename: PWideChar): Boolean; stdcall; external COllamaBoxDLL; 588 | 589 | /// 590 | /// Pulls the specified model from the Ollama model registry and prepares it for local use. 591 | /// 592 | /// 593 | /// A handle to the instance. 594 | /// 595 | /// 596 | /// True if the model was successfully pulled and initialized; otherwise, False. 597 | /// 598 | /// 599 | /// The model name is defined via the Model property on the instance. 600 | /// This function downloads and verifies the model, making it ready for inference. 601 | /// Progress can be monitored using . 602 | /// 603 | function obPull(const AOllamaBox: TOllamaBox): Boolean; stdcall; external COllamaBoxDLL; 604 | 605 | /// 606 | /// Performs text generation using the currently set model, prompt, and input context. 607 | /// 608 | /// 609 | /// A handle to the instance. 610 | /// 611 | /// 612 | /// True if a response was successfully generated; otherwise, False. 613 | /// 614 | /// 615 | /// The model, prompt, system prompts, images, and other context data must be configured before calling this method. 616 | /// Tokens are streamed using , and lifecycle events 617 | /// like and are triggered if set. 618 | /// 619 | function obGenerate(const AOllamaBox: TOllamaBox): Boolean; stdcall; external COllamaBoxDLL; 620 | 621 | /// 622 | /// Performs a web search using the given query and returns summarized results. 623 | /// 624 | /// 625 | /// A handle to the instance. 626 | /// 627 | /// 628 | /// A null-terminated wide string containing the search query text. 629 | /// 630 | /// 631 | /// A pointer to a null-terminated wide string containing the plain text search results. 632 | /// 633 | /// 634 | /// This function connects to an external search provider (e.g., Tavily) to retrieve 635 | /// real-time web content relevant to the query. It is useful for enhancing inference 636 | /// with up-to-date or externally sourced information in RAG workflows.

637 | /// Requires an active internet connection and a valid API key (configured internally). 638 | ///
639 | function obWebSearch(const AOllamaBox: TOllamaBox; const AQuery: PWideChar): PWideChar; stdcall; external COllamaBoxDLL; 640 | 641 | /// 642 | /// Retrieves the TCP port number configured for the embedded Ollama server. 643 | /// 644 | /// 645 | /// A handle to the instance. 646 | /// 647 | /// 648 | /// A 32-bit unsigned integer representing the port number (e.g., 11434). 649 | /// 650 | /// 651 | /// This is the port on which the Ollama server will listen for local HTTP API requests. 652 | /// It must match the value used to construct the server's base URL (see ). 653 | /// 654 | function obGetServerPort(const AOllamaBox: TOllamaBox): UInt32; stdcall; external COllamaBoxDLL; 655 | 656 | /// 657 | /// Sets the TCP port number for the embedded Ollama server. 658 | /// 659 | /// 660 | /// A handle to the instance. 661 | /// 662 | /// 663 | /// A 32-bit unsigned integer representing the desired port (e.g., 11434). 664 | /// 665 | /// 666 | /// This must be set before calling . If the specified port is already 667 | /// in use or invalid, server startup may fail. Use port numbers in the valid TCP range (typically above 1024). 668 | /// 669 | procedure obSetServerPort(const AOllamaBox: TOllamaBox; const APort: UInt32); stdcall; external COllamaBoxDLL; 670 | 671 | /// 672 | /// Retrieves the current file system path to the model used for inference. 673 | /// 674 | /// 675 | /// A handle to the instance. 676 | /// 677 | /// 678 | /// A pointer to a null-terminated wide string containing the model file or directory path. 679 | /// 680 | /// 681 | /// This path points to a local GGUF model file or a directory managed by Ollama. 682 | /// It is determined automatically after a successful or can be manually assigned. 683 | /// 684 | function obGetModelPath(const AOllamaBox: TOllamaBox): PWideChar; stdcall; external COllamaBoxDLL; 685 | 686 | /// 687 | /// Sets the file system path to the local model file or directory to be used for inference. 688 | /// 689 | /// 690 | /// A handle to the instance. 691 | /// 692 | /// 693 | /// A null-terminated wide string containing the full path to a local GGUF file or model directory. 694 | /// 695 | /// 696 | /// This allows manually specifying a local model instead of pulling one from the Ollama registry. 697 | /// The model at this path will be used for subsequent inference operations. 698 | /// 699 | procedure obSetModelPath(const AOllamaBox: TOllamaBox; const APath: PWideChar); stdcall; external COllamaBoxDLL; 700 | 701 | /// 702 | /// Retrieves the file system path where the Ollama server executable is located. 703 | /// 704 | /// 705 | /// A handle to the instance. 706 | /// 707 | /// 708 | /// A pointer to a null-terminated wide string containing the server path. 709 | /// 710 | /// 711 | /// This is the folder where extracts the Ollama server binary. 712 | /// It is also the location from which will launch the server. 713 | /// 714 | function obGetServerPath(const AOllamaBox: TOllamaBox): PWideChar; stdcall; external COllamaBoxDLL; 715 | 716 | /// 717 | /// Sets the file system path where the Ollama server should be extracted and run. 718 | /// 719 | /// 720 | /// A handle to the instance. 721 | /// 722 | /// 723 | /// A null-terminated wide string specifying the target directory for the Ollama server binary. 724 | /// 725 | /// 726 | /// This path must be writable and must be set before calling or . 727 | /// It determines where the server files will be unpacked and run. 728 | /// 729 | procedure obSetServerPath(const AOllamaBox: TOllamaBox; const APath: PWideChar); stdcall; external COllamaBoxDLL; 730 | 731 | /// 732 | /// Retrieves the file system path where the Ollama server ZIP file will be downloaded. 733 | /// 734 | /// 735 | /// A handle to the instance. 736 | /// 737 | /// 738 | /// A pointer to a null-terminated wide string containing the temporary download path. 739 | /// 740 | /// 741 | /// This path is used by to store the server archive 742 | /// before it is extracted to the final location. 743 | /// 744 | function obGetServerDownloadPath(const AOllamaBox: TOllamaBox): PWideChar; stdcall; external COllamaBoxDLL; 745 | 746 | /// 747 | /// Sets the path where the Ollama server ZIP file should be downloaded before extraction. 748 | /// 749 | /// 750 | /// A handle to the instance. 751 | /// 752 | /// 753 | /// A null-terminated wide string specifying the temporary folder for server downloads. 754 | /// 755 | /// 756 | /// This directory must be writable. If the file already exists, it may be overwritten. 757 | /// After download and extraction, the ZIP file may be deleted depending on internal cleanup behavior. 758 | /// 759 | procedure obSetServerDownloadPath(const AOllamaBox: TOllamaBox; const APath: PWideChar); stdcall; external COllamaBoxDLL; 760 | 761 | /// 762 | /// Retrieves the model name currently assigned to the instance. 763 | /// 764 | /// 765 | /// A handle to the instance. 766 | /// 767 | /// 768 | /// A pointer to a null-terminated wide string containing the model name (e.g., "llama3", "gemma:7b"). 769 | /// 770 | /// 771 | /// This is the value used by to locate and download the appropriate model from the Ollama registry. 772 | /// 773 | function obGetModel(const AOllamaBox: TOllamaBox): PWideChar; stdcall; external COllamaBoxDLL; 774 | 775 | /// 776 | /// Sets the model name to be used for inference and pulling from the Ollama registry. 777 | /// 778 | /// 779 | /// A handle to the instance. 780 | /// 781 | /// 782 | /// A null-terminated wide string representing the model name or tag (e.g., "llama3:latest"). 783 | /// 784 | /// 785 | /// The model name must be a valid identifier recognized by the Ollama registry. 786 | /// This value is required before calling or . 787 | /// 788 | procedure obSetModel(const AOllamaBox: TOllamaBox; const AModel: PWideChar); stdcall; external COllamaBoxDLL; 789 | 790 | /// 791 | /// Retrieves the current prompt text assigned to the instance. 792 | /// 793 | /// 794 | /// A handle to the instance. 795 | /// 796 | /// 797 | /// A pointer to a null-terminated wide string representing the prompt text. 798 | /// 799 | /// 800 | /// This is the user input or instruction that will be submitted to the model 801 | /// when is called. It may be a question, task instruction, 802 | /// or continuation depending on the application. 803 | /// 804 | function obGetPrompt(const AOllamaBox: TOllamaBox): PWideChar; stdcall; external COllamaBoxDLL; 805 | 806 | /// 807 | /// Sets the prompt text to be used for the next inference operation. 808 | /// 809 | /// 810 | /// A handle to the instance. 811 | /// 812 | /// 813 | /// A null-terminated wide string representing the prompt to submit to the model. 814 | /// 815 | /// 816 | /// The prompt is used as the main input during a call to . 817 | /// It may include question content, formatting instructions, or appended context. 818 | /// System prompts and images (if used) are processed alongside this main prompt. 819 | /// 820 | procedure obSetPrompt(const AOllamaBox: TOllamaBox; const APrompt: PWideChar); stdcall; external COllamaBoxDLL; 821 | 822 | /// 823 | /// Retrieves the current keep-alive setting for the embedded Ollama server. 824 | /// 825 | /// 826 | /// A handle to the instance. 827 | /// 828 | /// 829 | /// An integer value representing the keep-alive behavior: 830 | /// 831 | /// 0 – shut down immediately after each operation 832 | /// > 0 – keep alive for N seconds of inactivity 833 | /// < 0 – keep model in VRAM indefinitely 834 | /// 835 | /// 836 | /// 837 | /// This setting controls how long the server or model remains loaded between operations, 838 | /// affecting startup delay and GPU memory usage. 839 | /// 840 | function obGetKeepAlive(const AOllamaBox: TOllamaBox): Int32; stdcall; external COllamaBoxDLL; 841 | 842 | /// 843 | /// Sets the keep-alive timeout for the embedded Ollama server. 844 | /// 845 | /// 846 | /// A handle to the instance. 847 | /// 848 | /// 849 | /// An integer value controlling idle behavior: 850 | /// 851 | /// 0 – terminate server immediately after use 852 | /// 60 – keep alive for 60 seconds after last use 853 | /// -1 – keep model persistently loaded in VRAM 854 | /// 855 | /// 856 | /// 857 | /// This setting is useful for optimizing performance when reusing models across multiple requests. 858 | /// It should be set before calling . 859 | /// 860 | procedure obSetKeepAlive(const AOllamaBox: TOllamaBox; const AKeepAlive: Int32); stdcall; external COllamaBoxDLL; 861 | 862 | /// 863 | /// Retrieves the index of the main GPU device configured for model inference. 864 | /// 865 | /// 866 | /// A handle to the instance. 867 | /// 868 | /// 869 | /// An integer indicating the GPU index to use: 870 | /// 871 | /// -1 – automatically select the best available GPU 872 | /// 0 or greater – use a specific GPU by index 873 | /// 874 | /// 875 | /// 876 | /// GPU indexing is platform-dependent and may vary based on installed hardware. 877 | /// This value must be set before model execution for it to take effect. 878 | /// 879 | function obGetMainGPU(const AOllamaBox: TOllamaBox): Int32; stdcall; external COllamaBoxDLL; 880 | 881 | /// 882 | /// Sets the index of the GPU device to use as the primary accelerator for model inference. 883 | /// 884 | /// 885 | /// A handle to the instance. 886 | /// 887 | /// 888 | /// An integer indicating the target GPU: 889 | /// 890 | /// -1 – auto-select the best available GPU 891 | /// 0 – use the first GPU 892 | /// 1, 2, etc. – use specific GPU by index 893 | /// 894 | /// 895 | /// 896 | /// This should be configured before model load or inference begins. 897 | /// If the selected GPU is unavailable or unsupported, fallback behavior is implementation-defined. 898 | /// 899 | procedure obSetMainGPU(const AOllamaBox: TOllamaBox; const AMainGPU: Int32); stdcall; external COllamaBoxDLL; 900 | 901 | /// 902 | /// Retrieves the number of model layers currently configured to run on the GPU. 903 | /// 904 | /// 905 | /// A handle to the instance. 906 | /// 907 | /// 908 | /// An integer representing the number of transformer layers offloaded to the GPU: 909 | /// 910 | /// -1 – all eligible layers are assigned to the GPU 911 | /// 0 – all layers run on CPU only 912 | /// 1..N – only the first N layers are offloaded to the GPU 913 | /// 914 | /// 915 | /// 916 | /// This value determines how much of the model is accelerated by GPU hardware, 917 | /// directly affecting performance and VRAM usage. 918 | /// 919 | function obGetGPULayers(const AOllamaBox: TOllamaBox): Int32; stdcall; external COllamaBoxDLL; 920 | 921 | /// 922 | /// Sets the number of model layers to offload to the GPU for inference acceleration. 923 | /// 924 | /// 925 | /// A handle to the instance. 926 | /// 927 | /// 928 | /// An integer controlling layer usage: 929 | /// 930 | /// -1 – use GPU for all eligible layers 931 | /// 0 – use CPU only 932 | /// 1..N – offload only the first N layers to GPU 933 | /// 934 | /// 935 | /// 936 | /// Higher values offer better performance but consume more VRAM. 937 | /// This setting must be configured before model load or inference begins. 938 | /// 939 | procedure obSetGPULayer(const AOllamaBox: TOllamaBox; const AGPULayers: Int32); stdcall; external COllamaBoxDLL; 940 | 941 | /// 942 | /// Retrieves the maximum number of context tokens configured for inference. 943 | /// 944 | /// 945 | /// A handle to the instance. 946 | /// 947 | /// 948 | /// A 32-bit unsigned integer indicating the total context window size in tokens. 949 | /// 950 | /// 951 | /// This value defines how many tokens (prompt + generated) can be retained in memory 952 | /// during inference. The value must be compatible with the model’s maximum capacity 953 | /// and VRAM limits when using GPU acceleration. 954 | /// 955 | function obGetMaxContext(const AOllamaBox: TOllamaBox): UInt32; stdcall; external COllamaBoxDLL; 956 | 957 | /// 958 | /// Sets the maximum number of context tokens the model should use for inference. 959 | /// 960 | /// 961 | /// A handle to the instance. 962 | /// 963 | /// 964 | /// A 32-bit unsigned integer representing the desired context window size (in tokens). 965 | /// 966 | /// 967 | /// This setting affects how much of the conversation history the model can "remember" during generation. 968 | /// Larger values increase memory and VRAM requirements and must not exceed the model's maximum context limit. 969 | /// 970 | procedure obSetMaxContext(const AOllamaBox: TOllamaBox; const AMaxContext: UInt32); stdcall; external COllamaBoxDLL; 971 | 972 | /// 973 | /// Retrieves the suffix text that will be appended after the model’s generated response. 974 | /// 975 | /// 976 | /// A handle to the instance. 977 | /// 978 | /// 979 | /// A pointer to a null-terminated wide string representing the suffix text. 980 | /// 981 | /// 982 | /// The suffix is added after the last generated token and is not part of the prompt 983 | /// or model inference context. It is often used for formatting, such as line breaks, 984 | /// punctuation, or custom delimiters. 985 | /// 986 | function obGetSuffix(const AOllamaBox: TOllamaBox): PWideChar; stdcall; external COllamaBoxDLL; 987 | 988 | /// 989 | /// Sets the suffix text to append after the model's response is fully generated. 990 | /// 991 | /// 992 | /// A handle to the instance. 993 | /// 994 | /// 995 | /// A null-terminated wide string representing the suffix text to append (e.g., "\n" or ""). 996 | /// 997 | /// 998 | /// This suffix is applied after generation is complete and is not included in the prompt or token count. 999 | /// It is useful for terminal output, formatting in logs, or signaling end-of-response to a downstream parser. 1000 | /// 1001 | procedure obSetSuffix(const AOllamaBox: TOllamaBox; const ASuffix: PWideChar); stdcall; external COllamaBoxDLL; 1002 | 1003 | /// 1004 | /// Retrieves the current temperature value used for controlling token sampling randomness. 1005 | /// 1006 | /// 1007 | /// A handle to the instance. 1008 | /// 1009 | /// 1010 | /// A single-precision floating-point value representing the temperature (e.g., 0.8). 1011 | /// 1012 | /// 1013 | /// Temperature affects the variability of the model's output: 1014 | /// 1015 | /// 0.0 – deterministic output 1016 | /// ~0.7 – balanced creativity and coherence 1017 | /// 1.0+ – high randomness and diversity 1018 | /// 1019 | /// 1020 | function obGetTemperature(const AOllamaBox: TOllamaBox): Single; stdcall; external COllamaBoxDLL; 1021 | 1022 | /// 1023 | /// Sets the temperature value used to control the randomness of model output. 1024 | /// 1025 | /// 1026 | /// A handle to the instance. 1027 | /// 1028 | /// 1029 | /// A single-precision float indicating the desired temperature (e.g., 0.7). 1030 | /// 1031 | /// 1032 | /// Higher temperatures produce more varied and creative results, while lower values 1033 | /// yield more focused and deterministic output. A typical default is 0.7. 1034 | /// Values below 0.0 may be clamped or treated as 0. 1035 | /// 1036 | procedure obSetTemperature(const AOllamaBox: TOllamaBox; const ATemperature: Single); stdcall; external COllamaBoxDLL; 1037 | 1038 | /// 1039 | /// Retrieves the random seed currently set for model inference. 1040 | /// 1041 | /// 1042 | /// A handle to the instance. 1043 | /// 1044 | /// 1045 | /// A signed 32-bit integer representing the seed value. 1046 | /// 1047 | /// 1048 | /// The seed determines the randomness of token sampling. When the same prompt and parameters 1049 | /// are used with the same seed, the output will be deterministic. 1050 | /// A negative value (e.g., -1) indicates that a random seed will be used. 1051 | /// 1052 | function obGetSeed(const AOllamaBox: TOllamaBox): Int32; stdcall; external COllamaBoxDLL; 1053 | 1054 | /// 1055 | /// Sets the random seed used for inference token generation. 1056 | /// 1057 | /// 1058 | /// A handle to the instance. 1059 | /// 1060 | /// 1061 | /// A signed 32-bit integer to use as the seed: 1062 | /// 1063 | /// >= 0 – use this exact seed for reproducible output 1064 | /// < 0 – use a randomly generated seed each time 1065 | /// 1066 | /// 1067 | /// 1068 | /// Seeds allow for deterministic behavior when testing or comparing outputs, 1069 | /// and non-deterministic behavior when seeking diverse results. 1070 | /// 1071 | procedure obSetSeed(const AOllamaBox: TOllamaBox; const ASeed: Int32); stdcall; external COllamaBoxDLL; 1072 | 1073 | /// 1074 | /// Retrieves the number of CPU threads currently configured for model inference. 1075 | /// 1076 | /// 1077 | /// A handle to the instance. 1078 | /// 1079 | /// 1080 | /// A signed 32-bit integer indicating the number of threads to use: 1081 | /// 1082 | /// 0 or less – auto-select optimal number of threads 1083 | /// 1..N – fixed number of CPU threads 1084 | /// 1085 | /// 1086 | /// 1087 | /// This value controls parallelism during model execution and directly affects 1088 | /// CPU-bound performance. If GPU acceleration is used, fewer threads may be necessary. 1089 | /// 1090 | function obGetThreads(const AOllamaBox: TOllamaBox): Int32; stdcall; external COllamaBoxDLL; 1091 | 1092 | /// 1093 | /// Sets the number of CPU threads to use for model inference. 1094 | /// 1095 | /// 1096 | /// A handle to the instance. 1097 | /// 1098 | /// 1099 | /// A signed 32-bit integer specifying the thread count: 1100 | /// 1101 | /// 0 or negative – auto-detect optimal thread count 1102 | /// 1..N – manually specify thread usage 1103 | /// 1104 | /// 1105 | /// 1106 | /// This should be set before inference begins. Higher values can improve performance 1107 | /// on multi-core systems, but may increase CPU usage and memory pressure. 1108 | /// 1109 | procedure obSetThreads(const AOllamaBox: TOllamaBox; const AThreads: Int32); stdcall; external COllamaBoxDLL; 1110 | 1111 | /// 1112 | /// Retrieves the full response text generated by the model during the last inference operation. 1113 | /// 1114 | /// 1115 | /// A handle to the instance. 1116 | /// 1117 | /// 1118 | /// A pointer to a null-terminated wide string containing the full generated response. 1119 | /// 1120 | /// 1121 | /// This response is collected after calling and reflects 1122 | /// the final assembled output after all tokens have been processed.
1123 | /// If streaming output via was used, this contains the concatenated result. 1124 | ///
1125 | function obGetResponse(const AOllamaBox: TOllamaBox): PWideChar; stdcall; external COllamaBoxDLL; 1126 | 1127 | /// 1128 | /// Returns the number of input tokens used in the most recent inference operation. 1129 | /// 1130 | /// 1131 | /// A handle to the instance. 1132 | /// 1133 | /// 1134 | /// The number of tokens used for the prompt, system messages, and context. 1135 | /// 1136 | /// 1137 | /// Useful for measuring prompt size and tracking model usage costs. 1138 | /// 1139 | function obGetInputTokens(const AOllamaBox: TOllamaBox): UInt32; stdcall; external COllamaBoxDLL; 1140 | 1141 | /// 1142 | /// Returns the number of tokens generated by the model during the last inference. 1143 | /// 1144 | /// 1145 | /// A handle to the instance. 1146 | /// 1147 | /// 1148 | /// The number of output tokens produced by the model. 1149 | /// 1150 | /// 1151 | /// This does not include any manually appended suffix text. 1152 | /// 1153 | function obGetOutputTokens(const AOllamaBox: TOllamaBox): UInt32; stdcall; external COllamaBoxDLL; 1154 | 1155 | /// 1156 | /// Returns the total number of tokens processed during the last inference session. 1157 | /// 1158 | /// 1159 | /// A handle to the instance. 1160 | /// 1161 | /// 1162 | /// The combined count of input and output tokens. 1163 | /// 1164 | /// 1165 | /// Equivalent to InputTokens + OutputTokens. 1166 | /// Helpful for logging, billing estimation, or session history. 1167 | /// 1168 | function obGetTotalTokens(const AOllamaBox: TOllamaBox): UInt32; stdcall; external COllamaBoxDLL; 1169 | 1170 | /// 1171 | /// Returns the speed of token generation in tokens per second. 1172 | /// 1173 | /// 1174 | /// A handle to the instance. 1175 | /// 1176 | /// 1177 | /// A floating-point value representing tokens per second. 1178 | /// 1179 | /// 1180 | /// Calculated based on output token count and elapsed generation time. 1181 | /// Reflects model performance on the current system. 1182 | /// 1183 | function obGetSpeed(const AOllamaBox: TOllamaBox): Double; stdcall; external COllamaBoxDLL; 1184 | 1185 | /// 1186 | /// Returns the total time in seconds taken by the last inference operation. 1187 | /// 1188 | /// 1189 | /// A handle to the instance. 1190 | /// 1191 | /// 1192 | /// Elapsed time in seconds, including preprocessing and generation. 1193 | /// 1194 | /// 1195 | /// Measured with sub-second precision. 1196 | /// Useful for benchmarking and profiling generation performance. 1197 | /// 1198 | function obGetTime(const AOllamaBox: TOllamaBox): Double; stdcall; external COllamaBoxDLL; 1199 | 1200 | /// 1201 | /// Indicates whether the most recent inference operation was cancelled before completion. 1202 | /// 1203 | /// 1204 | /// A handle to the instance. 1205 | /// 1206 | /// 1207 | /// True if the generation was cancelled by a registered callback; otherwise, False. 1208 | /// 1209 | /// 1210 | /// This flag is automatically reset at the start of each new inference cycle. 1211 | /// It reflects whether the returned True during token generation. 1212 | /// 1213 | function obGetWasCancelled(const AOllamaBox: TOllamaBox): Boolean; stdcall; external COllamaBoxDLL; 1214 | 1215 | /// 1216 | /// Retrieves whether the model's token output should be wrapped in <think></think> tags. 1217 | /// 1218 | /// 1219 | /// A handle to the instance. 1220 | /// 1221 | /// 1222 | /// True if thinking output tags are enabled; otherwise, False. 1223 | /// 1224 | /// 1225 | /// When enabled, tokens generated during the "thinking" phase are streamed between 1226 | /// the tags <think> and </think>, allowing the host UI or 1227 | /// parser to distinguish pre-response reasoning content. 1228 | /// 1229 | function obGetShowThinking(const AOllamaBox: TOllamaBox): Boolean; stdcall; external COllamaBoxDLL; 1230 | 1231 | /// 1232 | /// Enables or disables the wrapping of "thinking" tokens in <think></think> tags. 1233 | /// 1234 | /// 1235 | /// A handle to the instance. 1236 | /// 1237 | /// 1238 | /// True to enable output tagging; False to disable. 1239 | /// 1240 | /// 1241 | /// This affects how streamed output is formatted when the model is reasoning 1242 | /// prior to emitting a final response. It is purely cosmetic and does not affect the model's behavior. 1243 | /// 1244 | procedure obSetShowThinking(const AOllamaBox: TOllamaBox; const AShowThinking: Boolean); stdcall; external COllamaBoxDLL; 1245 | 1246 | /// 1247 | /// Returns whether the model is currently in the "thinking" phase of inference. 1248 | /// 1249 | /// 1250 | /// A handle to the instance. 1251 | /// 1252 | /// 1253 | /// True if the model is currently reasoning or preparing a response; otherwise, False. 1254 | /// 1255 | /// 1256 | /// This flag is useful for updating UI indicators or controlling application flow 1257 | /// while the model is actively generating tokens. 1258 | /// 1259 | function obThinking(const AOllamaBox: TOllamaBox): Boolean; stdcall; external COllamaBoxDLL; 1260 | 1261 | /// 1262 | /// Retrieves whether the model's response tokens should be wrapped in <response></response> tags. 1263 | /// 1264 | /// 1265 | /// A handle to the instance. 1266 | /// 1267 | /// 1268 | /// True if response output tagging is enabled; otherwise, False. 1269 | /// 1270 | /// 1271 | /// When enabled, the generated response will be enclosed between <response> 1272 | /// and </response> tags. This helps downstream tools or UIs identify 1273 | /// the boundaries of the final answer. 1274 | /// 1275 | function obGetShowResponding(const AOllamaBox: TOllamaBox): Boolean; stdcall; external COllamaBoxDLL; 1276 | 1277 | /// 1278 | /// Enables or disables wrapping of the model's output in <response></response> tags. 1279 | /// 1280 | /// 1281 | /// A handle to the instance. 1282 | /// 1283 | /// 1284 | /// True to enable tagging; False to disable. 1285 | /// 1286 | /// 1287 | /// This setting is useful for log formatting, parsing automation, or frontend highlighting. 1288 | /// It is a cosmetic wrapper and does not alter model behavior. 1289 | /// 1290 | procedure obSetShowResponding(const AOllamaBox: TOllamaBox; const AShowResponding: Boolean); stdcall; external COllamaBoxDLL; 1291 | 1292 | /// 1293 | /// Indicates whether the model is currently in the "responding" phase of inference. 1294 | /// 1295 | /// 1296 | /// A handle to the instance. 1297 | /// 1298 | /// 1299 | /// True if the model is actively generating a final response; otherwise, False. 1300 | /// 1301 | /// 1302 | /// This can be used to detect when the response phase has begun (after thinking) 1303 | /// and is still ongoing, enabling live UI updates or stream parsing logic. 1304 | /// 1305 | function obResponding(const AOllamaBox: TOllamaBox): Boolean; stdcall; external COllamaBoxDLL; 1306 | 1307 | /// 1308 | /// Retrieves the HTTP status code from the most recent API request. 1309 | /// 1310 | /// 1311 | /// A handle to the instance. 1312 | /// 1313 | /// 1314 | /// An integer representing the HTTP status code (e.g., 200, 404, 500). 1315 | /// 1316 | /// 1317 | /// This value reflects the raw HTTP response from the last operation involving a network request, 1318 | /// such as or . It can be used to programmatically 1319 | /// detect and handle errors or success states. 1320 | /// 1321 | function obHttpStatusCode(const AOllamaBox: TOllamaBox): Int32; stdcall; external COllamaBoxDLL; 1322 | 1323 | /// 1324 | /// Retrieves the HTTP status message or reason phrase from the most recent API request. 1325 | /// 1326 | /// 1327 | /// A handle to the instance. 1328 | /// 1329 | /// 1330 | /// A pointer to a null-terminated wide string containing the HTTP status text 1331 | /// (e.g., "OK", "Not Found", "Internal Server Error"). 1332 | /// 1333 | /// 1334 | /// This message is provided by the remote server as part of the HTTP response. 1335 | /// It is useful for logging, error reporting, and human-readable diagnostics. 1336 | /// 1337 | function obHttpStatusText(const AOllamaBox: TOllamaBox): PWideChar; stdcall; external COllamaBoxDLL; 1338 | 1339 | implementation 1340 | 1341 | end. 1342 | -------------------------------------------------------------------------------- /tools/README.txt: -------------------------------------------------------------------------------- 1 | Tools used by the OllamaBox project 2 | 3 | polib.exe - http://www.smorgasbordet.com/pellesc/ 4 | -------------------------------------------------------------------------------- /tools/dump.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | cd /d "%~dp0" 3 | call tdump "..\bin\OllamaBox64.dll" > OllamaBox64.dll.txt 4 | call OllamaBox64.dll.txt 5 | -------------------------------------------------------------------------------- /tools/lib.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | cd /d "%~dp0" 3 | call polib /machine:x64 /out:"..\src\OllamaBox64.lib" "..\bin\OllamaBox64.dll" -------------------------------------------------------------------------------- /tools/polib.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tinyBigGAMES/OllamaBox/a99f30e598493e224de5bcb5f230048239ebe08a/tools/polib.exe --------------------------------------------------------------------------------