cactusfruit-sdk 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cactusfruit-sdk
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for Cactusfruit model services
|
|
5
|
+
Requires-Python: >=3.9
|
|
6
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
7
|
+
Requires-Dist: requests>=2.31.0
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
|
|
10
|
+
# Cactusfruit SDK
|
|
11
|
+
|
|
12
|
+
A Python SDK for interacting with Cactusfruit model services, including text embeddings, token counting, and text generation.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- Generate text using a configured language model.
|
|
17
|
+
- Create document embeddings.
|
|
18
|
+
- Create query embeddings.
|
|
19
|
+
- Count embedding tokens.
|
|
20
|
+
- Configure the server URL and model paths.
|
|
21
|
+
- Run the configuration loader explicitly when needed.
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
|
|
25
|
+
Install from PyPI:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install cactusfruit-sdk
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
Import the client:
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from cactusfruit.sdk import LlmServerClient
|
|
37
|
+
|
|
38
|
+
client = LlmServerClient()
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Generate Text
|
|
42
|
+
|
|
43
|
+
```python
|
|
44
|
+
response = client.generate(
|
|
45
|
+
role="user",
|
|
46
|
+
content="Explain what a Python SDK is.",
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
print(response)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
You can also provide generation parameters:
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
response = client.generate(
|
|
56
|
+
role="user",
|
|
57
|
+
content="Write a short introduction to machine learning.",
|
|
58
|
+
params={
|
|
59
|
+
"temperature": 0.7,
|
|
60
|
+
"max_tokens": 200,
|
|
61
|
+
},
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
print(response)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The parameters accepted depend on the underlying Cactusfruit model service.
|
|
68
|
+
|
|
69
|
+
### Generate Document Embeddings
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
embedding = client.embed_document(
|
|
73
|
+
"This is a document to embed."
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
print(embedding)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Generate Query Embeddings
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
embedding = client.embed_query(
|
|
83
|
+
"How does semantic search work?"
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
print(embedding)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Count Embedding Tokens
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
token_count = client.embed_token_count(
|
|
93
|
+
"Count the tokens in this text."
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
print(token_count)
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Configuration
|
|
100
|
+
|
|
101
|
+
The `LlmServerClient` supports configuration through constructor arguments.
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from cactusfruit.sdk import LlmServerClient
|
|
105
|
+
|
|
106
|
+
client = LlmServerClient(
|
|
107
|
+
base_url="http://localhost:8000",
|
|
108
|
+
embedder_model_path="models/all-MiniLM-L6-v2",
|
|
109
|
+
generator_model_path="models/your-generator-model",
|
|
110
|
+
)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
| Argument | Description |
|
|
114
|
+
|---|---|
|
|
115
|
+
| `base_url` | Base URL of the Cactusfruit model service |
|
|
116
|
+
| `embedder_model_path` | Model path used for document embeddings, query embeddings, and embedding token counts |
|
|
117
|
+
| `generator_model_path` | Model path used for text generation |
|
|
118
|
+
|
|
119
|
+
The default server URL is `http://localhost:8000`. The default embedding model path is `models/all-MiniLM-L6-v2`.
|
|
120
|
+
|
|
121
|
+
The default generator model path in the current client implementation is also `models/all-MiniLM-L6-v2`. For text generation, explicitly configure a suitable generator model path.
|
|
122
|
+
|
|
123
|
+
## Configuration Loader
|
|
124
|
+
|
|
125
|
+
Cactusfruit SDK includes a configuration loader intended for environments such as Docker.
|
|
126
|
+
|
|
127
|
+
The configuration loader is **not executed automatically** when the package is installed or imported. Run it explicitly when you want to generate `/app/.env`.
|
|
128
|
+
|
|
129
|
+
### Run the loader
|
|
130
|
+
|
|
131
|
+
Set `MODEL_CONFIG_ARG` to a JSON configuration and invoke the module:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
export MODEL_CONFIG_ARG='{
|
|
135
|
+
"type": "generative",
|
|
136
|
+
"system_prompt": "You are a helpful assistant.",
|
|
137
|
+
"params": {
|
|
138
|
+
"threads": 8,
|
|
139
|
+
"parallel": 4
|
|
140
|
+
}
|
|
141
|
+
}'
|
|
142
|
+
|
|
143
|
+
python -m cactusfruit.dockerscripts.configloader
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
The loader writes configuration values to `/app/.env`.
|
|
147
|
+
|
|
148
|
+
### Example Docker usage
|
|
149
|
+
|
|
150
|
+
```dockerfile
|
|
151
|
+
FROM python:3.11-slim
|
|
152
|
+
|
|
153
|
+
WORKDIR /app
|
|
154
|
+
|
|
155
|
+
RUN pip install --no-cache-dir cactusfruit-sdk
|
|
156
|
+
|
|
157
|
+
ENV MODEL_CONFIG_ARG='{"type":"generative","system_prompt":"You are a helpful assistant.","params":{"threads":8,"parallel":4}}'
|
|
158
|
+
|
|
159
|
+
RUN python -m cactusfruit.dockerscripts.configloader
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**Note:** The loader writes to `/app/.env`, so the process must have permission to create or modify that file. The loader's environment variables are used to generate the file; writing a `.env` file does not automatically load its values into every running process. Your application must load the file or otherwise configure its environment.
|
|
163
|
+
|
|
164
|
+
Avoid putting secrets in Docker build arguments or image environment variables, as they may be exposed through image metadata or build history.
|
|
165
|
+
|
|
166
|
+
## Model Service Endpoints
|
|
167
|
+
|
|
168
|
+
The client communicates with the configured model service using these endpoints:
|
|
169
|
+
|
|
170
|
+
| Operation | Endpoint |
|
|
171
|
+
|---|---|
|
|
172
|
+
| Document embeddings | `/m/embed/doc` |
|
|
173
|
+
| Query embeddings | `/m/embed/query` |
|
|
174
|
+
| Embedding token count | `/m/embed/token/count` |
|
|
175
|
+
| Text generation | `/m/prompt` |
|
|
176
|
+
|
|
177
|
+
The model service must be running and accessible at the configured `base_url`.
|
|
178
|
+
|
|
179
|
+
## Requirements
|
|
180
|
+
|
|
181
|
+
- Python 3.10 or later
|
|
182
|
+
- `requests`
|
|
183
|
+
- `python-dotenv`
|
|
184
|
+
|
|
185
|
+
These dependencies are installed automatically when you install `cactusfruit-sdk` from PyPI.
|
|
186
|
+
|
|
187
|
+
## Development
|
|
188
|
+
|
|
189
|
+
Clone the repository:
|
|
190
|
+
|
|
191
|
+
```bash
|
|
192
|
+
git clone https://github.com/jon004/cactusfruit-sdk.git
|
|
193
|
+
cd cactusfruit-sdk
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
Install the package in editable mode:
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
python -m pip install -e .
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Build the distribution:
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
python -m pip install --upgrade build
|
|
206
|
+
python -m build
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Contributing
|
|
210
|
+
|
|
211
|
+
Contributions, bug reports, and feature requests are welcome. Please open an issue or pull request in the [GitHub repository](https://github.com/jon004/cactusfruit-sdk).
|
|
212
|
+
|
|
213
|
+
## License
|
|
214
|
+
|
|
215
|
+
Add your project's chosen license here before publishing. If you intend others to use, modify, and redistribute this SDK, include an appropriate license file in the repository.
|