hcli-hai 2.1.3__tar.gz → 3.0.1__tar.gz
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.
- {hcli_hai-2.1.3/hcli_hai.egg-info → hcli_hai-3.0.1}/PKG-INFO +3 -3
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/hcli_hai/cli/ai.py +6 -6
- hcli_hai-3.0.1/hcli_hai/cli/cli.py +93 -0
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/hcli_hai/cli/config.py +8 -2
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/hcli_hai/cli/context.py +1 -1
- hcli_hai-3.0.1/hcli_hai/cli/model.py +34 -0
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/hcli_hai/cli/template.json +58 -10
- hcli_hai-3.0.1/hcli_hai/cli/utils/formatting.py +47 -0
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/hcli_hai/package.py +1 -1
- {hcli_hai-2.1.3 → hcli_hai-3.0.1/hcli_hai.egg-info}/PKG-INFO +3 -3
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/pyproject.toml +2 -2
- hcli_hai-3.0.1/tests/test_hai.py +41 -0
- hcli_hai-2.1.3/hcli_hai/cli/cli.py +0 -102
- hcli_hai-2.1.3/hcli_hai/cli/model.py +0 -18
- hcli_hai-2.1.3/hcli_hai/cli/utils/formatting.py +0 -14
- hcli_hai-2.1.3/tests/test_hai.py +0 -60
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/LICENSE.txt +0 -0
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/MANIFEST.in +0 -0
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/README.rst +0 -0
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/hcli_hai/__init__.py +0 -0
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/hcli_hai/__main__.py +0 -0
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/hcli_hai/cli/__init__.py +0 -0
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/hcli_hai/cli/logger.py +0 -0
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/hcli_hai/cli/utils/hutils.py +0 -0
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/hcli_hai/cli/utils/summary.py +0 -0
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/hcli_hai/config.py +0 -0
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/hcli_hai/data/hcli_hai.1 +0 -0
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/hcli_hai/hutils.py +0 -0
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/hcli_hai.egg-info/SOURCES.txt +0 -0
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/hcli_hai.egg-info/dependency_links.txt +0 -0
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/hcli_hai.egg-info/entry_points.txt +0 -0
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/hcli_hai.egg-info/requires.txt +0 -0
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/hcli_hai.egg-info/top_level.txt +0 -0
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/requirements.txt +0 -0
- {hcli_hai-2.1.3 → hcli_hai-3.0.1}/setup.cfg +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: hcli_hai
|
|
3
|
-
Version:
|
|
3
|
+
Version: 3.0.1
|
|
4
4
|
Summary: HCLI hai is a python package wrapper that contains an HCLI sample application (hai); hai is an HCLI for interacting with Anthropic's Claude or OpenAI's GPT AI models via terminal input and output streams.
|
|
5
|
-
Author-email: Jeff Michaud <cometaj2@
|
|
5
|
+
Author-email: Jeff Michaud <cometaj2@proton.me>
|
|
6
6
|
License: MIT
|
|
7
7
|
Project-URL: Homepage, https://github.com/cometaj2/hcli_hai
|
|
8
|
-
Keywords: cli,client,server,connector,hypermedia,rest,generic,development
|
|
8
|
+
Keywords: ai,llm,cli,client,server,connector,hypermedia,rest,generic,development
|
|
9
9
|
Classifier: Development Status :: 4 - Beta
|
|
10
10
|
Classifier: Intended Audience :: Developers
|
|
11
11
|
Classifier: Topic :: Software Development
|
|
@@ -8,7 +8,6 @@ import logger
|
|
|
8
8
|
import config
|
|
9
9
|
import context as c
|
|
10
10
|
import config
|
|
11
|
-
import uuid
|
|
12
11
|
import shutil
|
|
13
12
|
|
|
14
13
|
from datetime import datetime
|
|
@@ -149,12 +148,13 @@ class AI:
|
|
|
149
148
|
|
|
150
149
|
return sorted_contexts
|
|
151
150
|
|
|
152
|
-
def set(self,
|
|
151
|
+
def set(self, context_id):
|
|
153
152
|
contexts = self.ls()
|
|
154
153
|
context_ids = [context['context_id'] for context in contexts]
|
|
155
|
-
if
|
|
156
|
-
self.contextmgr.set(
|
|
154
|
+
if context_id in context_ids:
|
|
155
|
+
self.contextmgr.set(context_id)
|
|
157
156
|
else:
|
|
157
|
+
logging.warning(context_id)
|
|
158
158
|
logging.warning("provided context id is not found in available contexts.")
|
|
159
159
|
|
|
160
160
|
def new(self):
|
|
@@ -165,8 +165,8 @@ class AI:
|
|
|
165
165
|
|
|
166
166
|
return self.current()
|
|
167
167
|
|
|
168
|
-
def rm(self,
|
|
169
|
-
context_folder = os.path.join(self.config.dot_hai_context,
|
|
168
|
+
def rm(self, context_id):
|
|
169
|
+
context_folder = os.path.join(self.config.dot_hai_context, context_id)
|
|
170
170
|
if os.path.exists(context_folder):
|
|
171
171
|
shutil.rmtree(context_folder)
|
|
172
172
|
logging.info("removed " + context_folder)
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import io
|
|
3
|
+
import ai
|
|
4
|
+
from utils import formatting
|
|
5
|
+
|
|
6
|
+
from typing import Optional, Dict, Callable, List
|
|
7
|
+
|
|
8
|
+
class CLI:
|
|
9
|
+
def __init__(self, commands: List[str], inputstream: Optional[io.BytesIO] = None):
|
|
10
|
+
self.commands = commands
|
|
11
|
+
self.inputstream = inputstream
|
|
12
|
+
self.ai = ai.AI()
|
|
13
|
+
self.handlers: Dict[str, Callable] = {
|
|
14
|
+
'clear': lambda: self.ai.clear(),
|
|
15
|
+
'context': self._handle_context,
|
|
16
|
+
'ls': self._handle_ls,
|
|
17
|
+
'new': self._handle_new,
|
|
18
|
+
'current': lambda: io.BytesIO(self.ai.current().encode('utf-8')),
|
|
19
|
+
'behavior': lambda: self.ai.behavior(self.inputstream) if self.inputstream else None,
|
|
20
|
+
'name': self._handle_name,
|
|
21
|
+
'model': self._handle_model,
|
|
22
|
+
'set': lambda: self.ai.set(self.commands[2]) if len(self.commands) == 3 else None,
|
|
23
|
+
'rm': lambda: self.ai.rm(self.commands[2]) if len(self.commands) == 3 else None
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
def execute(self) -> Optional[io.BytesIO]:
|
|
27
|
+
if len(self.commands) == 1 and self.inputstream:
|
|
28
|
+
response = self.ai.chat(self.inputstream)
|
|
29
|
+
return io.BytesIO(response.encode('utf-8'))
|
|
30
|
+
|
|
31
|
+
if len(self.commands) > 1 and self.commands[1] in self.handlers:
|
|
32
|
+
return self.handlers[self.commands[1]]()
|
|
33
|
+
|
|
34
|
+
return None
|
|
35
|
+
|
|
36
|
+
def _handle_context(self) -> Optional[io.BytesIO]:
|
|
37
|
+
if len(self.commands) == 2:
|
|
38
|
+
readable_context = self.ai.get_readable_context()
|
|
39
|
+
return io.BytesIO(readable_context.encode('utf-8'))
|
|
40
|
+
if len(self.commands) == 3 and self.commands[2] == '--json':
|
|
41
|
+
context = self.ai.get_context()
|
|
42
|
+
return io.BytesIO(context.serialize().encode('utf-8'))
|
|
43
|
+
|
|
44
|
+
return None
|
|
45
|
+
|
|
46
|
+
def _handle_name(self) -> Optional[io.BytesIO]:
|
|
47
|
+
if len(self.commands) == 2:
|
|
48
|
+
name = self.ai.name()
|
|
49
|
+
return io.BytesIO((name or "None").encode('utf-8'))
|
|
50
|
+
if len(self.commands) == 4 and self.commands[2] == "set":
|
|
51
|
+
self.ai.set_name(self.commands[3])
|
|
52
|
+
|
|
53
|
+
return None
|
|
54
|
+
|
|
55
|
+
def _handle_ls(self) -> Optional[io.BytesIO]:
|
|
56
|
+
if len(self.commands) == 2:
|
|
57
|
+
contexts = self.ai.ls()
|
|
58
|
+
return io.BytesIO(formatting.format_rows(contexts).encode('utf-8'))
|
|
59
|
+
if len(self.commands) == 3:
|
|
60
|
+
if self.commands[2] == "--json":
|
|
61
|
+
return io.BytesIO(json.dumps(self.ai.ls(), indent=4).encode('utf-8'))
|
|
62
|
+
|
|
63
|
+
return None
|
|
64
|
+
|
|
65
|
+
def _handle_new(self) -> Optional[io.BytesIO]:
|
|
66
|
+
if len(self.commands) == 2:
|
|
67
|
+
return io.BytesIO(self.ai.new().encode('utf-8'))
|
|
68
|
+
if len(self.commands) == 3:
|
|
69
|
+
if self.commands[2] == "--json":
|
|
70
|
+
return io.BytesIO(json.dumps([self.ai.new()], indent=4).encode('utf-8'))
|
|
71
|
+
|
|
72
|
+
return None
|
|
73
|
+
|
|
74
|
+
def _handle_model(self) -> Optional[io.BytesIO]:
|
|
75
|
+
if len(self.commands) == 2:
|
|
76
|
+
model = self.ai.model()
|
|
77
|
+
return io.BytesIO((model or "None").encode('utf-8'))
|
|
78
|
+
if len(self.commands) == 3:
|
|
79
|
+
if self.commands[2] == "--json":
|
|
80
|
+
model = self.ai.model()
|
|
81
|
+
return io.BytesIO(json.dumps([model or "None"], indent=4).encode('utf-8'))
|
|
82
|
+
if self.commands[2] == "ls":
|
|
83
|
+
models = self.ai.list_models()
|
|
84
|
+
return io.BytesIO("\n".join(models).encode('utf-8'))
|
|
85
|
+
if len(self.commands) == 4:
|
|
86
|
+
if self.commands[2] == "ls" and self.commands[3] == '--json':
|
|
87
|
+
models = self.ai.list_models()
|
|
88
|
+
return io.BytesIO(json.dumps(models, indent=4).encode('utf-8'))
|
|
89
|
+
if self.commands[2] == "set":
|
|
90
|
+
self.ai.set_model(self.commands[3])
|
|
91
|
+
|
|
92
|
+
return None
|
|
93
|
+
|
|
@@ -12,7 +12,7 @@ import sys
|
|
|
12
12
|
import shutil
|
|
13
13
|
import json
|
|
14
14
|
import logger
|
|
15
|
-
import
|
|
15
|
+
import base64
|
|
16
16
|
import context as c
|
|
17
17
|
|
|
18
18
|
logging = logger.Logger()
|
|
@@ -42,6 +42,12 @@ class Config:
|
|
|
42
42
|
self.create_configuration()
|
|
43
43
|
self.parse_configuration()
|
|
44
44
|
|
|
45
|
+
# base32 approach (10 chars) to help avoid 1/I 0/O visual discrepancies.
|
|
46
|
+
def generate_id(self):
|
|
47
|
+
random_bytes = os.urandom(6) # 6 bytes = 10 chars in base32
|
|
48
|
+
id = base64.b32encode(random_bytes).decode('utf-8').rstrip('=')
|
|
49
|
+
return id
|
|
50
|
+
|
|
45
51
|
# parses the configuration of a given cli to set configured execution
|
|
46
52
|
def parse_configuration(self):
|
|
47
53
|
if self.parser.has_section("default"):
|
|
@@ -62,7 +68,7 @@ class Config:
|
|
|
62
68
|
hutils.create_file(self.dot_hai_config_file)
|
|
63
69
|
|
|
64
70
|
self.parser.read_file(StringIO(u"[default]"))
|
|
65
|
-
self.parser.set("default", "context", str(
|
|
71
|
+
self.parser.set("default", "context", str(self.generate_id()))
|
|
66
72
|
with open(self.dot_hai_config_file, "w") as config:
|
|
67
73
|
self.parser.write(config)
|
|
68
74
|
else:
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
models = {
|
|
2
|
+
"claude-3-haiku-20240307": {
|
|
3
|
+
'model' : "claude-3-haiku-20240307",
|
|
4
|
+
'max_tokens' : 2048
|
|
5
|
+
},
|
|
6
|
+
"claude-3-5-haiku-22024102": {
|
|
7
|
+
'model' : "claude-3-haiku-20240307",
|
|
8
|
+
'max_tokens' : 8192
|
|
9
|
+
},
|
|
10
|
+
"claude-3-5-haiku-latest": {
|
|
11
|
+
'model' : "claude-3-5-haiku-latest",
|
|
12
|
+
'max_tokens' : 8192
|
|
13
|
+
},
|
|
14
|
+
"claude-3-5-sonnet-latest": {
|
|
15
|
+
'model' : "claude-3-5-sonnet-20240620",
|
|
16
|
+
'max_tokens' : 8192
|
|
17
|
+
},
|
|
18
|
+
"claude-3-5-sonnet-20241022": {
|
|
19
|
+
'model' : "claude-3-5-sonnet-20241022",
|
|
20
|
+
'max_tokens' : 8192
|
|
21
|
+
},
|
|
22
|
+
"claude-3-5-sonnet-20240620": {
|
|
23
|
+
'model' : "claude-3-5-sonnet-20240620",
|
|
24
|
+
'max_tokens' : 8192
|
|
25
|
+
},
|
|
26
|
+
"claude-3-opus-latest": {
|
|
27
|
+
'model' : "claude-3-opus-latest",
|
|
28
|
+
'max_tokens' : 4096
|
|
29
|
+
},
|
|
30
|
+
"claude-3-opus-20240229": {
|
|
31
|
+
'model' : "claude-3-opus-20240229",
|
|
32
|
+
'max_tokens' : 4096
|
|
33
|
+
},
|
|
34
|
+
}
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
"command": "hai new",
|
|
14
14
|
"http": "post"
|
|
15
15
|
},
|
|
16
|
+
{
|
|
17
|
+
"command": "hai new --json",
|
|
18
|
+
"http": "post"
|
|
19
|
+
},
|
|
16
20
|
{
|
|
17
21
|
"command": "hai name",
|
|
18
22
|
"http": "get"
|
|
@@ -26,21 +30,33 @@
|
|
|
26
30
|
"http": "get"
|
|
27
31
|
},
|
|
28
32
|
{
|
|
29
|
-
"command": "hai context
|
|
33
|
+
"command": "hai context --json",
|
|
30
34
|
"http": "get"
|
|
31
35
|
},
|
|
32
36
|
{
|
|
33
37
|
"command": "hai current",
|
|
34
38
|
"http": "get"
|
|
35
39
|
},
|
|
40
|
+
{
|
|
41
|
+
"command": "hai current --json",
|
|
42
|
+
"http": "get"
|
|
43
|
+
},
|
|
36
44
|
{
|
|
37
45
|
"command": "hai model",
|
|
38
46
|
"http": "get"
|
|
39
47
|
},
|
|
48
|
+
{
|
|
49
|
+
"command": "hai model --json",
|
|
50
|
+
"http": "get"
|
|
51
|
+
},
|
|
40
52
|
{
|
|
41
53
|
"command": "hai model ls",
|
|
42
54
|
"http": "get"
|
|
43
55
|
},
|
|
56
|
+
{
|
|
57
|
+
"command": "hai model ls --json",
|
|
58
|
+
"http": "get"
|
|
59
|
+
},
|
|
44
60
|
{
|
|
45
61
|
"command": "hai model set {p}",
|
|
46
62
|
"http": "post"
|
|
@@ -49,6 +65,10 @@
|
|
|
49
65
|
"command": "hai ls",
|
|
50
66
|
"http": "get"
|
|
51
67
|
},
|
|
68
|
+
{
|
|
69
|
+
"command": "hai ls --json",
|
|
70
|
+
"http": "get"
|
|
71
|
+
},
|
|
52
72
|
{
|
|
53
73
|
"command": "hai rm {p}",
|
|
54
74
|
"http": "post"
|
|
@@ -183,6 +203,13 @@
|
|
|
183
203
|
"name": "set",
|
|
184
204
|
"description": "The \"set\" command sets the current model per the allowed list of usable models."
|
|
185
205
|
}
|
|
206
|
+
],
|
|
207
|
+
"option": [
|
|
208
|
+
{
|
|
209
|
+
"href": "haimodel--json",
|
|
210
|
+
"name": "--json",
|
|
211
|
+
"description": "Return a JSON formatted output."
|
|
212
|
+
}
|
|
186
213
|
]
|
|
187
214
|
},
|
|
188
215
|
{
|
|
@@ -195,12 +222,19 @@
|
|
|
195
222
|
},
|
|
196
223
|
{
|
|
197
224
|
"name": "synopsis",
|
|
198
|
-
"description": "hai model ls"
|
|
225
|
+
"description": "hai model ls [--json]"
|
|
199
226
|
},
|
|
200
227
|
{
|
|
201
228
|
"name": "description",
|
|
202
229
|
"description": "The \"ls\" command lists all available models to select from."
|
|
203
230
|
}
|
|
231
|
+
],
|
|
232
|
+
"option": [
|
|
233
|
+
{
|
|
234
|
+
"href": "haimodells--json",
|
|
235
|
+
"name": "--json",
|
|
236
|
+
"description": "Return a JSON formatted output."
|
|
237
|
+
}
|
|
204
238
|
]
|
|
205
239
|
},
|
|
206
240
|
{
|
|
@@ -240,6 +274,13 @@
|
|
|
240
274
|
"name": "description",
|
|
241
275
|
"description": "The \"new\" command creates a brand new context and switches to it as the current context."
|
|
242
276
|
}
|
|
277
|
+
],
|
|
278
|
+
"option": [
|
|
279
|
+
{
|
|
280
|
+
"href": "hainew--json",
|
|
281
|
+
"name": "--json",
|
|
282
|
+
"description": "Return a JSON formatted output."
|
|
283
|
+
}
|
|
243
284
|
]
|
|
244
285
|
},
|
|
245
286
|
{
|
|
@@ -294,22 +335,22 @@
|
|
|
294
335
|
"section": [
|
|
295
336
|
{
|
|
296
337
|
"name": "name",
|
|
297
|
-
"description": "context - allows you to
|
|
338
|
+
"description": "context - allows you to view the current conversation context."
|
|
298
339
|
},
|
|
299
340
|
{
|
|
300
341
|
"name": "synopsis",
|
|
301
|
-
"description": "hai context [
|
|
342
|
+
"description": "hai context [--json]"
|
|
302
343
|
},
|
|
303
344
|
{
|
|
304
345
|
"name": "description",
|
|
305
|
-
"description": "The \"context\" command allows you to view the current context. The context is what makes the chatbot remember what was previously discussed so that a more coherent conversation can take place."
|
|
346
|
+
"description": "The \"context\" command allows you to view the current context in a human readable format. The context is what makes the chatbot remember what was previously discussed so that a more coherent conversation can take place."
|
|
306
347
|
}
|
|
307
348
|
],
|
|
308
349
|
"option": [
|
|
309
350
|
{
|
|
310
|
-
"href": "haicontext
|
|
311
|
-
"name": "
|
|
312
|
-
"description": "
|
|
351
|
+
"href": "haicontext--json",
|
|
352
|
+
"name": "--json",
|
|
353
|
+
"description": "Return a JSON formatted output."
|
|
313
354
|
}
|
|
314
355
|
]
|
|
315
356
|
},
|
|
@@ -327,7 +368,7 @@
|
|
|
327
368
|
},
|
|
328
369
|
{
|
|
329
370
|
"name": "description",
|
|
330
|
-
"description": "The \"current\" command allows you to fetch the context id
|
|
371
|
+
"description": "The \"current\" command allows you to fetch the context id of the current context."
|
|
331
372
|
}
|
|
332
373
|
]
|
|
333
374
|
},
|
|
@@ -359,12 +400,19 @@
|
|
|
359
400
|
},
|
|
360
401
|
{
|
|
361
402
|
"name": "synopsis",
|
|
362
|
-
"description": "hai ls"
|
|
403
|
+
"description": "hai ls [--json]"
|
|
363
404
|
},
|
|
364
405
|
{
|
|
365
406
|
"name": "description",
|
|
366
407
|
"description": "The \"ls\" command lists all usable contexts by context id. Each context is also tied to an auto generated title that acts as a summary and helps provide a bit of additional information about the related context. The list is sorted by context update time."
|
|
367
408
|
}
|
|
409
|
+
],
|
|
410
|
+
"option": [
|
|
411
|
+
{
|
|
412
|
+
"href": "hails--json",
|
|
413
|
+
"name": "--json",
|
|
414
|
+
"description": "Return a JSON formatted output."
|
|
415
|
+
}
|
|
368
416
|
]
|
|
369
417
|
},
|
|
370
418
|
{
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
class Formatting:
|
|
2
|
+
SEPARATOR = "----"
|
|
3
|
+
NEWLINES = "\n\n"
|
|
4
|
+
SECTION_TEMPLATE = "{separator}{name}:{newlines}{content}{newlines}"
|
|
5
|
+
|
|
6
|
+
@classmethod
|
|
7
|
+
def format(cls, name, content):
|
|
8
|
+
return cls.SECTION_TEMPLATE.format(
|
|
9
|
+
separator=cls.SEPARATOR,
|
|
10
|
+
name=name,
|
|
11
|
+
content=content,
|
|
12
|
+
newlines=cls.NEWLINES
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
def format_row(context_id: str, title: str, name: str, update_time: str,
|
|
16
|
+
ID_LENGTH: int, TITLE_MAX_LENGTH: int, NAME_LENGTH: int) -> str:
|
|
17
|
+
# Truncate title if needed and pad with spaces
|
|
18
|
+
title_display = (title[:TITLE_MAX_LENGTH-3] + "...") if len(title) > TITLE_MAX_LENGTH else title
|
|
19
|
+
title_display = title_display.ljust(TITLE_MAX_LENGTH)
|
|
20
|
+
|
|
21
|
+
# Pad other fields
|
|
22
|
+
context_id = context_id.ljust(ID_LENGTH)
|
|
23
|
+
name = name.ljust(NAME_LENGTH)
|
|
24
|
+
|
|
25
|
+
return f"{context_id} {title_display} {name} {update_time}\n"
|
|
26
|
+
|
|
27
|
+
def format_rows(contexts) -> str:
|
|
28
|
+
ID_LENGTH = 10
|
|
29
|
+
TITLE_MAX_LENGTH = 41
|
|
30
|
+
NAME_LENGTH = 10
|
|
31
|
+
DATE_LENGTH = 19 # YYYY-MM-DD HH:MM:SS
|
|
32
|
+
|
|
33
|
+
header = format_row("CONTEXT_ID", "TITLE", "NAME", "UPDATE_TIME",
|
|
34
|
+
ID_LENGTH, TITLE_MAX_LENGTH, NAME_LENGTH)
|
|
35
|
+
|
|
36
|
+
output = header
|
|
37
|
+
for context in contexts:
|
|
38
|
+
output += format_row(
|
|
39
|
+
context["context_id"],
|
|
40
|
+
context["title"] or "",
|
|
41
|
+
context["name"] or "",
|
|
42
|
+
context["update_time"],
|
|
43
|
+
ID_LENGTH,
|
|
44
|
+
TITLE_MAX_LENGTH,
|
|
45
|
+
NAME_LENGTH
|
|
46
|
+
)
|
|
47
|
+
return output.rstrip()
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: hcli_hai
|
|
3
|
-
Version:
|
|
3
|
+
Version: 3.0.1
|
|
4
4
|
Summary: HCLI hai is a python package wrapper that contains an HCLI sample application (hai); hai is an HCLI for interacting with Anthropic's Claude or OpenAI's GPT AI models via terminal input and output streams.
|
|
5
|
-
Author-email: Jeff Michaud <cometaj2@
|
|
5
|
+
Author-email: Jeff Michaud <cometaj2@proton.me>
|
|
6
6
|
License: MIT
|
|
7
7
|
Project-URL: Homepage, https://github.com/cometaj2/hcli_hai
|
|
8
|
-
Keywords: cli,client,server,connector,hypermedia,rest,generic,development
|
|
8
|
+
Keywords: ai,llm,cli,client,server,connector,hypermedia,rest,generic,development
|
|
9
9
|
Classifier: Development Status :: 4 - Beta
|
|
10
10
|
Classifier: Intended Audience :: Developers
|
|
11
11
|
Classifier: Topic :: Software Development
|
|
@@ -7,7 +7,7 @@ name = "hcli_hai"
|
|
|
7
7
|
dynamic = ["version", "dependencies"]
|
|
8
8
|
description="HCLI hai is a python package wrapper that contains an HCLI sample application (hai); hai is an HCLI for interacting with Anthropic's Claude or OpenAI's GPT AI models via terminal input and output streams."
|
|
9
9
|
readme = "README.rst"
|
|
10
|
-
authors = [{name = "Jeff Michaud", email = "cometaj2@
|
|
10
|
+
authors = [{name = "Jeff Michaud", email = "cometaj2@proton.me"}]
|
|
11
11
|
license = {text = "MIT"}
|
|
12
12
|
classifiers = [
|
|
13
13
|
"Development Status :: 4 - Beta",
|
|
@@ -18,7 +18,7 @@ classifiers = [
|
|
|
18
18
|
"Programming Language :: Python :: 3.11",
|
|
19
19
|
"Programming Language :: Python :: 3.12"
|
|
20
20
|
]
|
|
21
|
-
keywords = ["cli", "client", "server", "connector", "hypermedia", "rest", "generic", "development"]
|
|
21
|
+
keywords = ["ai", "llm", "cli", "client", "server", "connector", "hypermedia", "rest", "generic", "development"]
|
|
22
22
|
|
|
23
23
|
[project.urls]
|
|
24
24
|
Homepage = "https://github.com/cometaj2/hcli_hai"
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
import os
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
def test_hai_context(gunicorn_server, cleanup):
|
|
6
|
+
hello = """
|
|
7
|
+
#!/bin/bash
|
|
8
|
+
set -x
|
|
9
|
+
|
|
10
|
+
export HUCKLE_HOME=~/.huckle_test
|
|
11
|
+
eval $(huckle env)
|
|
12
|
+
|
|
13
|
+
hai new > /dev/null 2>&1
|
|
14
|
+
hai context --json
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
p2 = subprocess.Popen(['bash', '-c', hello], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
18
|
+
out, err = p2.communicate()
|
|
19
|
+
error = err.decode('utf-8')
|
|
20
|
+
result = out.decode('utf-8')
|
|
21
|
+
|
|
22
|
+
assert('{\n "messages": [\n {\n "content": "",\n "role": "system"\n }\n ],\n "name": "",\n "title": ""\n}\n' == result)
|
|
23
|
+
|
|
24
|
+
def test_hai_name(gunicorn_server, cleanup):
|
|
25
|
+
hello = """
|
|
26
|
+
#!/bin/bash
|
|
27
|
+
set -x
|
|
28
|
+
|
|
29
|
+
export HUCKLE_HOME=~/.huckle_test
|
|
30
|
+
eval $(huckle env)
|
|
31
|
+
|
|
32
|
+
hai name set hello
|
|
33
|
+
hai name
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
p3 = subprocess.Popen(['bash', '-c', hello], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
37
|
+
out, err = p3.communicate()
|
|
38
|
+
error = err.decode('utf-8')
|
|
39
|
+
result = out.decode('utf-8')
|
|
40
|
+
|
|
41
|
+
assert('hello\n' == result)
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
import io
|
|
3
|
-
import os
|
|
4
|
-
import sys
|
|
5
|
-
import inspect
|
|
6
|
-
import traceback
|
|
7
|
-
import tiktoken
|
|
8
|
-
import logger
|
|
9
|
-
import ai
|
|
10
|
-
|
|
11
|
-
from anthropic import Anthropic
|
|
12
|
-
|
|
13
|
-
logging = logger.Logger()
|
|
14
|
-
logging.setLevel(logger.INFO)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class CLI:
|
|
18
|
-
commands = None
|
|
19
|
-
inputstream = None
|
|
20
|
-
|
|
21
|
-
def __init__(self, commands, inputstream):
|
|
22
|
-
self.commands = commands
|
|
23
|
-
self.inputstream = inputstream
|
|
24
|
-
self.ai = ai.AI()
|
|
25
|
-
|
|
26
|
-
def execute(self):
|
|
27
|
-
if len(self.commands) == 1:
|
|
28
|
-
if self.inputstream is not None:
|
|
29
|
-
response = self.ai.chat(self.inputstream)
|
|
30
|
-
return io.BytesIO(response.encode('utf-8'))
|
|
31
|
-
|
|
32
|
-
if self.commands[1] == "clear":
|
|
33
|
-
self.ai.clear()
|
|
34
|
-
return
|
|
35
|
-
|
|
36
|
-
if self.commands[1] == "context":
|
|
37
|
-
if len(self.commands) == 2:
|
|
38
|
-
context = self.ai.get_context()
|
|
39
|
-
return io.BytesIO(context.serialize().encode('utf-8'))
|
|
40
|
-
if len(self.commands) == 3:
|
|
41
|
-
readable_context = self.ai.get_readable_context()
|
|
42
|
-
return io.BytesIO(readable_context.encode('utf-8'))
|
|
43
|
-
|
|
44
|
-
if self.commands[1] == "ls":
|
|
45
|
-
contexts = self.ai.ls()
|
|
46
|
-
return io.BytesIO(json.dumps(contexts, indent=4).encode('utf-8'))
|
|
47
|
-
|
|
48
|
-
if self.commands[1] == "new":
|
|
49
|
-
current = self.ai.new()
|
|
50
|
-
return io.BytesIO(current.encode('utf-8'))
|
|
51
|
-
|
|
52
|
-
if self.commands[1] == "current":
|
|
53
|
-
current = self.ai.current()
|
|
54
|
-
return io.BytesIO(current.encode('utf-8'))
|
|
55
|
-
|
|
56
|
-
if self.commands[1] == "behavior":
|
|
57
|
-
if self.inputstream is not None:
|
|
58
|
-
self.ai.behavior(self.inputstream)
|
|
59
|
-
return
|
|
60
|
-
|
|
61
|
-
if self.commands[1] == "name":
|
|
62
|
-
if len(self.commands) == 2:
|
|
63
|
-
name = self.ai.name()
|
|
64
|
-
if name is not None:
|
|
65
|
-
return io.BytesIO(name.encode('utf-8'))
|
|
66
|
-
else:
|
|
67
|
-
return io.BytesIO(b"None")
|
|
68
|
-
|
|
69
|
-
if len(self.commands) == 4:
|
|
70
|
-
if self.commands[2] == "set":
|
|
71
|
-
self.ai.set_name(self.commands[3])
|
|
72
|
-
return None
|
|
73
|
-
|
|
74
|
-
if self.commands[1] == "model":
|
|
75
|
-
if len(self.commands) == 2:
|
|
76
|
-
model = self.ai.model()
|
|
77
|
-
if model is not None:
|
|
78
|
-
return io.BytesIO(model.encode('utf-8'))
|
|
79
|
-
else:
|
|
80
|
-
return io.BytesIO(b"None")
|
|
81
|
-
|
|
82
|
-
if len(self.commands) == 3:
|
|
83
|
-
if self.commands[2] == "ls":
|
|
84
|
-
models = self.ai.list_models()
|
|
85
|
-
return io.BytesIO(json.dumps(models, indent=4).encode('utf-8'))
|
|
86
|
-
|
|
87
|
-
if len(self.commands) == 4:
|
|
88
|
-
if self.commands[2] == "set":
|
|
89
|
-
self.ai.set_model(self.commands[3])
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
if self.commands[1] == "set":
|
|
93
|
-
if len(self.commands) == 3:
|
|
94
|
-
self.ai.set(self.commands[2])
|
|
95
|
-
return
|
|
96
|
-
|
|
97
|
-
if self.commands[1] == "rm":
|
|
98
|
-
if len(self.commands) == 3:
|
|
99
|
-
self.ai.rm(self.commands[2])
|
|
100
|
-
return
|
|
101
|
-
|
|
102
|
-
return None
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
models = {
|
|
2
|
-
"claude-3-opus-20240229": {
|
|
3
|
-
'model' : "claude-3-opus-20240229",
|
|
4
|
-
'max_tokens' : 4096
|
|
5
|
-
},
|
|
6
|
-
"claude-3-haiku-20240307": {
|
|
7
|
-
'model' : "claude-3-haiku-20240307",
|
|
8
|
-
'max_tokens' : 2048
|
|
9
|
-
},
|
|
10
|
-
"claude-3-5-sonnet-20241022": {
|
|
11
|
-
'model' : "claude-3-5-sonnet-20241022",
|
|
12
|
-
'max_tokens' : 4096
|
|
13
|
-
},
|
|
14
|
-
"claude-3-5-sonnet-20240620": {
|
|
15
|
-
'model' : "claude-3-5-sonnet-20240620",
|
|
16
|
-
'max_tokens' : 4096
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
class Formatting:
|
|
2
|
-
SEPARATOR = "----"
|
|
3
|
-
NEWLINES = "\n\n"
|
|
4
|
-
SECTION_TEMPLATE = "{separator}{name}:{newlines}{content}{newlines}"
|
|
5
|
-
|
|
6
|
-
@classmethod
|
|
7
|
-
def format(cls, name, content):
|
|
8
|
-
return cls.SECTION_TEMPLATE.format(
|
|
9
|
-
separator=cls.SEPARATOR,
|
|
10
|
-
name=name,
|
|
11
|
-
content=content,
|
|
12
|
-
newlines=cls.NEWLINES
|
|
13
|
-
)
|
|
14
|
-
|
hcli_hai-2.1.3/tests/test_hai.py
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import subprocess
|
|
2
|
-
import os
|
|
3
|
-
|
|
4
|
-
def test_hai_context():
|
|
5
|
-
setup = """
|
|
6
|
-
#!/bin/bash
|
|
7
|
-
set -x
|
|
8
|
-
|
|
9
|
-
gunicorn --workers=1 --threads=1 "hcli_core:connector(\\"`hcli_hai path`\\")" --error-log ./error.log --daemon
|
|
10
|
-
sleep 3
|
|
11
|
-
huckle cli install http://127.0.0.1:8000
|
|
12
|
-
|
|
13
|
-
cat ./error.log
|
|
14
|
-
"""
|
|
15
|
-
|
|
16
|
-
p1 = subprocess.Popen(['bash', '-c', setup], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
17
|
-
out, err = p1.communicate()
|
|
18
|
-
|
|
19
|
-
error = err.decode('utf-8')
|
|
20
|
-
result = out.decode('utf-8')
|
|
21
|
-
print(error)
|
|
22
|
-
print(result)
|
|
23
|
-
|
|
24
|
-
hello = """
|
|
25
|
-
#!/bin/bash
|
|
26
|
-
set -x
|
|
27
|
-
|
|
28
|
-
eval $(huckle env)
|
|
29
|
-
hai new > /dev/null 2>&1
|
|
30
|
-
hai context
|
|
31
|
-
"""
|
|
32
|
-
|
|
33
|
-
p2 = subprocess.Popen(['bash', '-c', hello], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
34
|
-
out, err = p2.communicate()
|
|
35
|
-
error = err.decode('utf-8')
|
|
36
|
-
result = out.decode('utf-8')
|
|
37
|
-
print(error)
|
|
38
|
-
print(result)
|
|
39
|
-
|
|
40
|
-
assert(result == '{\n "messages": [\n {\n "content": "",\n "role": "system"\n }\n ],\n "name": "",\n "title": ""\n}')
|
|
41
|
-
|
|
42
|
-
def test_hai_name():
|
|
43
|
-
hello = """
|
|
44
|
-
#!/bin/bash
|
|
45
|
-
set -x
|
|
46
|
-
|
|
47
|
-
eval $(huckle env)
|
|
48
|
-
hai name set hello
|
|
49
|
-
hai name
|
|
50
|
-
ps aux | grep '[g]unicorn' | awk '{print $2}' | xargs kill
|
|
51
|
-
"""
|
|
52
|
-
|
|
53
|
-
p3 = subprocess.Popen(['bash', '-c', hello], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
54
|
-
out, err = p3.communicate()
|
|
55
|
-
error = err.decode('utf-8')
|
|
56
|
-
result = out.decode('utf-8')
|
|
57
|
-
print(error)
|
|
58
|
-
print(result)
|
|
59
|
-
|
|
60
|
-
assert(result == 'hello')
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|