├── .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 | 
2 | [](https://discord.gg/tPWjMwK)
3 | [](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 |
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
--------------------------------------------------------------------------------