coeai 0.1.1__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.
coeai/__init__.py ADDED
@@ -0,0 +1 @@
1
+ from .infer import LLMinfer
coeai/infer.py ADDED
@@ -0,0 +1,76 @@
1
+ import requests
2
+ import base64
3
+ import os
4
+
5
+ class LLMinfer:
6
+ def __init__(self, api_url="http://localhost:8000/generate", api_key="mysecretkey", model="llama4"):
7
+ self.api_url = api_url
8
+ self.api_key = api_key
9
+ self.model = model
10
+ self.headers = {
11
+ "Content-Type": "application/json",
12
+ "X-API-Key": self.api_key
13
+ }
14
+
15
+ def infer(self, mode, prompt_text, image_path=None, max_tokens=1024, temperature=0.7, top_p=1.0, stream=False):
16
+ if mode == "text-to-text":
17
+ payload = {
18
+ "model": self.model,
19
+ "messages": [
20
+ {
21
+ "role": "system",
22
+ "content": "This is a chat between a user and an assistant. The assistant is helping the user with general questions."
23
+ },
24
+ {
25
+ "role": "user",
26
+ "content": prompt_text
27
+ }
28
+ ],
29
+ "max_tokens": max_tokens,
30
+ "temperature": temperature,
31
+ "top_p": top_p,
32
+ "stream": stream
33
+ }
34
+
35
+ elif mode == "image-text-to-text":
36
+ if not image_path or not os.path.exists(image_path):
37
+ raise FileNotFoundError("Image path must be provided and valid for image-text-to-text mode.")
38
+
39
+ with open(image_path, "rb") as f:
40
+ base64_image = base64.b64encode(f.read()).decode("utf-8")
41
+
42
+ payload = {
43
+ "model": self.model,
44
+ "messages": [
45
+ {
46
+ "role": "system",
47
+ "content": "This is a chat between a user and an assistant. The assistant is helping the user to describe an image."
48
+ },
49
+ {
50
+ "role": "user",
51
+ "content": [
52
+ {
53
+ "type": "image_url",
54
+ "image_url": {
55
+ "url": f"data:image/jpeg;base64,{base64_image}"
56
+ }
57
+ },
58
+ {
59
+ "type": "text",
60
+ "text": prompt_text
61
+ }
62
+ ]
63
+ }
64
+ ],
65
+ "max_tokens": max_tokens,
66
+ "temperature": temperature,
67
+ "top_p": top_p,
68
+ "stream": stream
69
+ }
70
+
71
+ else:
72
+ raise ValueError("Invalid mode. Use 'text-to-text' or 'image-text-to-text'.")
73
+
74
+ response = requests.post(self.api_url, headers=self.headers, json=payload)
75
+ response.raise_for_status()
76
+ return response.json()
@@ -0,0 +1,308 @@
1
+ Metadata-Version: 2.4
2
+ Name: coeai
3
+ Version: 0.1.1
4
+ Summary: Client to interact with COE AI-hosted LLM models
5
+ Home-page: https://github.com/pkonal/coeai
6
+ Author: Konal Puri
7
+ Author-email: purikonal23@gmail.com
8
+ License: MIT
9
+ Keywords: llm inference coeai ollama ai-client
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.6
16
+ Classifier: Programming Language :: Python :: 3.7
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Operating System :: OS Independent
20
+ Requires-Python: >=3.6
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: requests
24
+ Dynamic: author
25
+ Dynamic: author-email
26
+ Dynamic: classifier
27
+ Dynamic: description
28
+ Dynamic: description-content-type
29
+ Dynamic: home-page
30
+ Dynamic: keywords
31
+ Dynamic: license
32
+ Dynamic: license-file
33
+ Dynamic: requires-dist
34
+ Dynamic: requires-python
35
+ Dynamic: summary
36
+
37
+ # coeai `PyPI Package`
38
+
39
+ **Interact with high-capacity multimodal LLMs hosted on the COE AI GPU cluster from any Python environment.**
40
+
41
+ `coeai` is a lightweight Python wrapper currently around the *LLaMA-4 16x17B* model (128K context, vision-enabled) deployed on the Centre of Excellence for AI (COE AI) servers at UPES. It exposes a single `/generate` HTTP endpoint, making it trivial to run both text-only and image+text inference from notebooks, scripts or backend services connected to the UPES Wi-Fi.
42
+
43
+ > **Text and image input** **128,000-token context** **Streaming or batch** **Runs on the COE AI GPU node**
44
+
45
+ ---
46
+
47
+ ## Table of Contents
48
+ 1. [Features](#features)
49
+ 2. [Requirements](#requirements)
50
+ 3. [Installation](#installation)
51
+ 4. [Quick Start](#quick-start)
52
+ 5. [API Usage](#api-usage)
53
+ 6. [Model Parameters](#model-parameters)
54
+ 7. [Authentication](#authentication)
55
+ 8. [Joining COE AI](#joining-coe-ai)
56
+ 9. [Troubleshooting](#troubleshooting)
57
+ 10. [License](#license)
58
+ 11. [Author](#author)
59
+
60
+ ---
61
+
62
+ ## Features
63
+
64
+ * **Ultra-long context** up to **128K tokens** per request for long documents or multi-turn chats
65
+ * **Vision support** send images along with text for multimodal reasoning
66
+ * **High performance** queries are served by a dedicated GPU node inside the COE AI HPC cluster
67
+ * **Simple auth** authenticate with a short-lived API key (valid 30 days) sent in the request header
68
+ * **Drop-in wrapper** minimal Python API; no need to handle HTTP manually
69
+
70
+ ---
71
+
72
+ ## Requirements
73
+
74
+ * Python **3.8 or newer**
75
+ * Network access to `http://10.16.1.50:8000` from the UPES campus Wi-Fi
76
+ * A **valid API key** issued by the COE AI team
77
+
78
+ ---
79
+
80
+ ## Installation
81
+
82
+ ```bash
83
+ pip install coeai
84
+ ```
85
+
86
+ This pulls the latest release from PyPI.
87
+
88
+ ---
89
+
90
+ ## Quick Start
91
+
92
+ The wrapper exposes a single `LLMinfer` class. Initialize it with the API URL and your API key, then call `infer()`.
93
+
94
+ ### Text-to-Text
95
+
96
+ ```python
97
+ from coeai import LLMinfer
98
+
99
+ llm = LLMinfer(
100
+ api_url="http://10.16.1.50:8000/generate",
101
+ api_key="API_KEY"
102
+ )
103
+
104
+ response = llm.infer(
105
+ mode="text-to-text",
106
+ prompt_text="Summarize the key points of general relativity.",
107
+ max_tokens=500,
108
+ temperature=0.6,
109
+ top_p=0.95,
110
+ stream=False
111
+ )
112
+
113
+ print(response)
114
+
115
+ ```
116
+
117
+ ### Image + Text
118
+
119
+ ```python
120
+ from coeai import LLMinfer
121
+
122
+ # Initialize the client
123
+ llm = LLMinfer(
124
+ api_url="http://10.16.1.50:8000/generate",
125
+ api_key="API_KEY"
126
+ )
127
+
128
+ # Run inference with image and prompt
129
+ response = llm.infer(
130
+ mode="image-text-to-text",
131
+ prompt_text="Describe what's happening in the image.",
132
+ image_path="/home/konal.106904/sample.jpg", # <-- update to a valid path
133
+ max_tokens=512,
134
+ temperature=0.7,
135
+ top_p=1.0,
136
+ stream=False
137
+ )
138
+
139
+ # Print the response
140
+ print(response)
141
+
142
+ ```
143
+
144
+ ---
145
+
146
+ ## API Usage
147
+
148
+ ### Using the Python Wrapper
149
+
150
+ The examples above show the recommended approach using the `LLMinfer` class.
151
+
152
+ ### Direct API Access with cURL
153
+
154
+ You can also interact directly with the `/generate` endpoint using cURL.
155
+
156
+ #### Prerequisites
157
+
158
+ | Requirement | Purpose |
159
+ |-------------|---------|
160
+ | A running instance of the API | Default URL: `http://10.16.1.50:8000/generate` |
161
+ | Valid API key | Supply in the `X-API-Key` request header |
162
+ | cURL 7.68+ | Supports `--data @-` JSON piping |
163
+
164
+ #### Text-Only Request
165
+
166
+ ```bash
167
+ curl -X POST http://10.16.1.50:8000/generate \
168
+ -H "Content-Type: application/json" \
169
+ -H "X-API-Key: YOUR_API_KEY_HERE" \
170
+ -d '{
171
+ "model": "llama4",
172
+ "messages": [
173
+ {
174
+ "role": "system",
175
+ "content": "This is a chat between a user and an assistant. The assistant is helping the user with general questions."
176
+ },
177
+ {
178
+ "role": "user",
179
+ "content": "Explain what a black hole is."
180
+ }
181
+ ],
182
+ "max_tokens": 512,
183
+ "temperature": 0.7,
184
+ "top_p": 1.0,
185
+ "stream": false
186
+ }'
187
+ ```
188
+
189
+ #### Image + Text Request
190
+
191
+ For multimodal requests, include the image as a Base64-encoded Data URI in the `content` array:
192
+
193
+ > **Note:** Replace `YOUR_API_KEY_HERE` with your own API key and `PUT_BASE64_IMAGE_STRING_HERE` with the **Base64-encoded** contents of your image file.
194
+
195
+ **How it Works:**
196
+ 1. **Inline Image**: The `image_url` object embeds the entire image as a Data URI so no separate file upload is required
197
+ 2. **Multi-Modal Prompt**: The `content` field is an array containing both the image and the accompanying text question, preserving ordering
198
+ 3. **Response**: The server returns a JSON object containing the assistant's interpretation of the supplied image
199
+
200
+ ---
201
+
202
+ ## Model Parameters
203
+
204
+ ### Default Parameters
205
+
206
+ | Field | Description | Default |
207
+ |----------------|----------------------------------------------|---------|
208
+ | `model` | Model name (currently fixed to `llama4`) | `llama4` |
209
+ | `stream` | Return tokens incrementally | `false` |
210
+ | `max_tokens` | Maximum new tokens to generate | `1024` |
211
+ | `temperature` | Sampling temperature (creativity) | `0.7` |
212
+ | `top_p` | Nucleus sampling | `1.0` |
213
+ | `stop` | List of stop sequences | `null` |
214
+
215
+ ### Parameter Details
216
+
217
+ | Parameter | Description |
218
+ |----------------|-------------|
219
+ | `model` | The model identifier exposed by your server (here `llama4`) |
220
+ | `messages` | Conversation history, each entry containing a `role` and `content` |
221
+ | `max_tokens` | Upper bound on tokens in the assistant reply |
222
+ | `temperature` | Controls randomness; lower values yield more deterministic output |
223
+ | `top_p` | Nucleus sampling; keep at `1.0` for default behavior |
224
+ | `stream` | When `true`, the API will send incremental responses via Server-Sent Events (SSE) |
225
+
226
+ > **Note:** The server enforces total context of 128K tokens (prompt + generated). Adjust `max_tokens` accordingly.
227
+
228
+ ---
229
+
230
+ ## Authentication
231
+
232
+ All requests must include an **API key** issued by the COE AI team. Pass the key when constructing `LLMinfer` (it is added as an `Authorization` header behind the scenes).
233
+
234
+ ### Requesting an API Key
235
+
236
+ 1. **Join COE AI** see [Joining COE AI](#joining-coe-ai) for membership instructions
237
+ 2. After joining, send an email to `hpc-access@ddn.upes.ac.in` *from your official UPES account* using this template:
238
+
239
+ ```
240
+ Subject: API Key Request for COE AI LLM Access
241
+
242
+ Dear COE AI Team,
243
+
244
+ I am requesting access to the LLM API for my project work.
245
+
246
+ Project Details:
247
+ - Project Name: <Your Project Name>
248
+ - Project Description: <Brief description>
249
+ - Expected Usage: <How you plan to use the LLM>
250
+ - Duration: <Timeline>
251
+
252
+ Reason for API Access:
253
+ <Research objectives or academic requirements>
254
+
255
+ Additional Information:
256
+ - Name: <Your Name>
257
+ - Email: <Your Email>
258
+ - Department/Affiliation: <Dept/Organisation>
259
+ - Student/Faculty ID: <If applicable>
260
+
261
+ Thank you for considering my request.
262
+
263
+ Best regards,
264
+ <Your Name>
265
+ ```
266
+
267
+ 3. Allow **2-3 business days** for processing. The team will reply with your API key.
268
+
269
+ ### Key Renewal
270
+
271
+ Keys expire **after 30 days**. Email the same address with the subject:
272
+ ```
273
+ Subject: API Key Renewal Request for COE AI LLM Access
274
+ ```
275
+
276
+ Include your previous key and a brief usage summary.
277
+
278
+ ---
279
+
280
+ ## Joining COE AI
281
+
282
+ Interested in HPC and AI research? Apply for membership (UPES Wi-Fi only):
283
+ <https://coeai.ddn.upes.ac.in/how-to-join>
284
+
285
+ ---
286
+
287
+ ## Troubleshooting
288
+
289
+ | Symptom | Possible Cause | Fix |
290
+ |---------|----------------|-----|
291
+ | `ConnectionError` | Not on UPES network | Connect to campus Wi-Fi or VPN |
292
+ | `401 Unauthorized` | Missing/expired API key | Request or renew your key |
293
+ | Long latency | Very large prompts or high `max_tokens` | Reduce prompt size or output length |
294
+
295
+ ---
296
+
297
+ ## License
298
+
299
+ `coeai` is released under the **MIT License**.
300
+
301
+ ---
302
+
303
+ ## Author
304
+
305
+ **Konal Puri**
306
+ Centre of Excellence: AI (COE AI), HPC Project, UPES
307
+
308
+ PyPI: <https://pypi.org/project/coeai>
@@ -0,0 +1,7 @@
1
+ coeai/__init__.py,sha256=vLXMYyyBWhoyGee7OVxKNOaJTM2qv_bcgB-1CxHKbzM,28
2
+ coeai/infer.py,sha256=96G9vJBTM0X_wvu0I8qAFzhrFVGFuKaBWjOJXyRiDoo,2846
3
+ coeai-0.1.1.dist-info/licenses/LICENSE,sha256=qXsP9AmMi_x5sId95dmTEx1RTxbQ7SFiV24JHxBJAhs,1162
4
+ coeai-0.1.1.dist-info/METADATA,sha256=9tmdVS6nYH31u4vZDCNfHAcQK3u3qjGqSVid9pGlzmU,8983
5
+ coeai-0.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
+ coeai-0.1.1.dist-info/top_level.txt,sha256=x0uabhCPxXblZZou3qnbneFxQDkrVIX4NK-eONZd8N8,6
7
+ coeai-0.1.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025–2027 Konal Puri
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ coeai