hcli-hai 3.0.1__tar.gz → 3.2.0__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-3.0.1/hcli_hai.egg-info → hcli_hai-3.2.0}/PKG-INFO +10 -5
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/README.rst +3 -1
- hcli_hai-3.2.0/hcli_hai/__main__.py +61 -0
- hcli_hai-3.2.0/hcli_hai/cli/__pycache__/ai.cpython-311.pyc +0 -0
- hcli_hai-3.2.0/hcli_hai/cli/__pycache__/behavior.cpython-311.pyc +0 -0
- hcli_hai-3.2.0/hcli_hai/cli/__pycache__/cli.cpython-311.pyc +0 -0
- hcli_hai-3.2.0/hcli_hai/cli/__pycache__/config.cpython-311.pyc +0 -0
- hcli_hai-3.2.0/hcli_hai/cli/__pycache__/context.cpython-311.pyc +0 -0
- hcli_hai-3.2.0/hcli_hai/cli/__pycache__/jobqueue.cpython-311.pyc +0 -0
- hcli_hai-3.2.0/hcli_hai/cli/__pycache__/logger.cpython-311.pyc +0 -0
- hcli_hai-3.2.0/hcli_hai/cli/__pycache__/model.cpython-311.pyc +0 -0
- hcli_hai-3.2.0/hcli_hai/cli/__pycache__/runner.cpython-311.pyc +0 -0
- hcli_hai-3.2.0/hcli_hai/cli/__pycache__/service.cpython-311.pyc +0 -0
- hcli_hai-3.2.0/hcli_hai/cli/ai.py +221 -0
- hcli_hai-3.2.0/hcli_hai/cli/behavior.py +133 -0
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/hcli_hai/cli/cli.py +16 -1
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/hcli_hai/cli/config.py +3 -0
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/hcli_hai/cli/context.py +8 -32
- hcli_hai-3.2.0/hcli_hai/cli/jobqueue.py +49 -0
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/hcli_hai/cli/model.py +16 -2
- hcli_hai-3.2.0/hcli_hai/cli/runner.py +118 -0
- hcli_hai-3.2.0/hcli_hai/cli/service.py +89 -0
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/hcli_hai/cli/template.json +79 -0
- hcli_hai-3.2.0/hcli_hai/cli/utils/__pycache__/formatting.cpython-311.pyc +0 -0
- hcli_hai-3.2.0/hcli_hai/cli/utils/__pycache__/hutils.cpython-311.pyc +0 -0
- hcli_hai-3.2.0/hcli_hai/cli/utils/__pycache__/summary.cpython-311.pyc +0 -0
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/hcli_hai/data/hcli_hai.1 +1 -1
- hcli_hai-3.2.0/hcli_hai/package.py +5 -0
- {hcli_hai-3.0.1 → hcli_hai-3.2.0/hcli_hai.egg-info}/PKG-INFO +10 -5
- hcli_hai-3.2.0/hcli_hai.egg-info/SOURCES.txt +47 -0
- hcli_hai-3.2.0/hcli_hai.egg-info/requires.txt +4 -0
- hcli_hai-3.2.0/requirements.txt +4 -0
- hcli_hai-3.0.1/hcli_hai/__main__.py +0 -44
- hcli_hai-3.0.1/hcli_hai/cli/ai.py +0 -192
- hcli_hai-3.0.1/hcli_hai/package.py +0 -3
- hcli_hai-3.0.1/hcli_hai.egg-info/SOURCES.txt +0 -30
- hcli_hai-3.0.1/hcli_hai.egg-info/requires.txt +0 -2
- hcli_hai-3.0.1/requirements.txt +0 -2
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/LICENSE.txt +0 -0
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/MANIFEST.in +0 -0
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/hcli_hai/__init__.py +0 -0
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/hcli_hai/cli/__init__.py +0 -0
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/hcli_hai/cli/logger.py +0 -0
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/hcli_hai/cli/utils/formatting.py +0 -0
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/hcli_hai/cli/utils/hutils.py +0 -0
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/hcli_hai/cli/utils/summary.py +0 -0
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/hcli_hai/config.py +0 -0
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/hcli_hai/hutils.py +0 -0
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/hcli_hai.egg-info/dependency_links.txt +0 -0
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/hcli_hai.egg-info/entry_points.txt +0 -0
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/hcli_hai.egg-info/top_level.txt +0 -0
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/pyproject.toml +0 -0
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/setup.cfg +0 -0
- {hcli_hai-3.0.1 → hcli_hai-3.2.0}/tests/test_hai.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: hcli_hai
|
|
3
|
-
Version: 3.0
|
|
3
|
+
Version: 3.2.0
|
|
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
5
|
Author-email: Jeff Michaud <cometaj2@proton.me>
|
|
6
6
|
License: MIT
|
|
@@ -15,8 +15,11 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
15
15
|
Classifier: Programming Language :: Python :: 3.12
|
|
16
16
|
Description-Content-Type: text/x-rst
|
|
17
17
|
License-File: LICENSE.txt
|
|
18
|
-
Requires-Dist: tiktoken==0.
|
|
19
|
-
Requires-Dist: anthropic==0.
|
|
18
|
+
Requires-Dist: tiktoken==0.9.0
|
|
19
|
+
Requires-Dist: anthropic==0.49.0
|
|
20
|
+
Requires-Dist: huckle<6.0.0,>=5.6.0
|
|
21
|
+
Requires-Dist: apscheduler==3.11.0
|
|
22
|
+
Dynamic: license-file
|
|
20
23
|
|
|
21
24
|
|pypi| |build status| |pyver|
|
|
22
25
|
|
|
@@ -85,6 +88,8 @@ Supports
|
|
|
85
88
|
- Automatic title creation based on context
|
|
86
89
|
- Custom context naming to help organize contexts
|
|
87
90
|
- Behavior setting to allow for persistent chatbot behavior (e.g. the Do Anything Now (DAN) prompt).
|
|
91
|
+
- Conversation vibing via detailed plans and HCLI integration to allow for external tool use.
|
|
92
|
+
- This allows for capabilities enhancements (e.g. web search, git repo interaction, terminal use, etc.).
|
|
88
93
|
|
|
89
94
|
To Do
|
|
90
95
|
-----
|
|
@@ -98,7 +103,7 @@ To Do
|
|
|
98
103
|
Bugs
|
|
99
104
|
----
|
|
100
105
|
|
|
101
|
-
|
|
106
|
+
Vibing thread stays tied to a single and context and won't budge if a different context is selected
|
|
102
107
|
|
|
103
108
|
.. |build status| image:: https://circleci.com/gh/cometaj2/hcli_hai.svg?style=shield
|
|
104
109
|
:target: https://circleci.com/gh/cometaj2/hcli_hai
|
|
@@ -65,6 +65,8 @@ Supports
|
|
|
65
65
|
- Automatic title creation based on context
|
|
66
66
|
- Custom context naming to help organize contexts
|
|
67
67
|
- Behavior setting to allow for persistent chatbot behavior (e.g. the Do Anything Now (DAN) prompt).
|
|
68
|
+
- Conversation vibing via detailed plans and HCLI integration to allow for external tool use.
|
|
69
|
+
- This allows for capabilities enhancements (e.g. web search, git repo interaction, terminal use, etc.).
|
|
68
70
|
|
|
69
71
|
To Do
|
|
70
72
|
-----
|
|
@@ -78,7 +80,7 @@ To Do
|
|
|
78
80
|
Bugs
|
|
79
81
|
----
|
|
80
82
|
|
|
81
|
-
|
|
83
|
+
Vibing thread stays tied to a single and context and won't budge if a different context is selected
|
|
82
84
|
|
|
83
85
|
.. |build status| image:: https://circleci.com/gh/cometaj2/hcli_hai.svg?style=shield
|
|
84
86
|
:target: https://circleci.com/gh/cometaj2/hcli_hai
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
from subprocess import call
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from . import package
|
|
6
|
+
from . import config
|
|
7
|
+
from . import hutils
|
|
8
|
+
|
|
9
|
+
def main():
|
|
10
|
+
if len(sys.argv) == 2:
|
|
11
|
+
|
|
12
|
+
if sys.argv[1] == "--version":
|
|
13
|
+
show_dependencies()
|
|
14
|
+
sys.exit(0)
|
|
15
|
+
|
|
16
|
+
elif sys.argv[1] == "help":
|
|
17
|
+
display_man_page(config.hcli_hai_manpage_path)
|
|
18
|
+
sys.exit(0)
|
|
19
|
+
|
|
20
|
+
elif sys.argv[1] == "path":
|
|
21
|
+
print(config.plugin_path)
|
|
22
|
+
sys.exit(0)
|
|
23
|
+
|
|
24
|
+
else:
|
|
25
|
+
hcli_hai_help()
|
|
26
|
+
|
|
27
|
+
hcli_hai_help()
|
|
28
|
+
|
|
29
|
+
# show version and version of dependencies
|
|
30
|
+
def show_dependencies():
|
|
31
|
+
def parse_dependency(dep_string):
|
|
32
|
+
# Common version specifiers
|
|
33
|
+
specifiers = ['==', '>=', '<=', '~=', '>', '<', '!=']
|
|
34
|
+
|
|
35
|
+
# Find the first matching specifier
|
|
36
|
+
for specifier in specifiers:
|
|
37
|
+
if specifier in dep_string:
|
|
38
|
+
name, version = dep_string.split(specifier, 1)
|
|
39
|
+
return name.strip(), specifier, version.strip()
|
|
40
|
+
|
|
41
|
+
# If no specifier found, return just the name
|
|
42
|
+
return dep_string.strip(), '', ''
|
|
43
|
+
|
|
44
|
+
dependencies = ""
|
|
45
|
+
for dep in package.dependencies:
|
|
46
|
+
name, specifier, version = parse_dependency(dep)
|
|
47
|
+
if version: # Only add separator if there's a version
|
|
48
|
+
dependencies += f" {name}/{version}"
|
|
49
|
+
else:
|
|
50
|
+
dependencies += f" {name}"
|
|
51
|
+
|
|
52
|
+
print(f"hcli_hai/{package.__version__}{dependencies}")
|
|
53
|
+
|
|
54
|
+
def hcli_hai_help():
|
|
55
|
+
hutils.eprint("for help, use:\n")
|
|
56
|
+
hutils.eprint(" hcli_hai help")
|
|
57
|
+
sys.exit(2)
|
|
58
|
+
|
|
59
|
+
# displays a man page (file) located on a given path
|
|
60
|
+
def display_man_page(path):
|
|
61
|
+
call(["man", path])
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import io
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
import re
|
|
6
|
+
import inspect
|
|
7
|
+
import traceback
|
|
8
|
+
import logger
|
|
9
|
+
import config
|
|
10
|
+
import context as c
|
|
11
|
+
import shutil
|
|
12
|
+
import time
|
|
13
|
+
import threading
|
|
14
|
+
|
|
15
|
+
from datetime import datetime
|
|
16
|
+
from anthropic import Anthropic
|
|
17
|
+
from model import models
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
logging = logger.Logger()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class AI:
|
|
24
|
+
instance = None
|
|
25
|
+
init_lock = threading.RLock()
|
|
26
|
+
config = None
|
|
27
|
+
contextmgr = None
|
|
28
|
+
|
|
29
|
+
def __new__(cls):
|
|
30
|
+
with cls.init_lock:
|
|
31
|
+
if cls.instance is None:
|
|
32
|
+
cls.instance = super().__new__(cls)
|
|
33
|
+
cls.instance.__init_singleton()
|
|
34
|
+
return cls.instance
|
|
35
|
+
|
|
36
|
+
def __init_singleton(self):
|
|
37
|
+
self.rlock = threading.RLock()
|
|
38
|
+
logging.debug("[ hai ] Initializing AI singleton")
|
|
39
|
+
self.config = config.Config()
|
|
40
|
+
self.contextmgr = c.ContextManager()
|
|
41
|
+
logging.debug(f"[ hai ] AI initialization complete: config={bool(self.config)}, contextmgr={bool(self.contextmgr)}")
|
|
42
|
+
|
|
43
|
+
def chat(self, inputstream):
|
|
44
|
+
with self.rlock:
|
|
45
|
+
if self.config.model is not None:
|
|
46
|
+
inputstream = inputstream.read().decode('utf-8')
|
|
47
|
+
if inputstream != "":
|
|
48
|
+
inputstream = inputstream.rstrip()
|
|
49
|
+
question = { "role" : "user", "content" : inputstream }
|
|
50
|
+
self.contextmgr.append(question)
|
|
51
|
+
self.contextmgr.trim()
|
|
52
|
+
|
|
53
|
+
tokens = self.contextmgr.counter.get_stats(self.contextmgr.context)
|
|
54
|
+
logging.info("[ hai ] Request - total context tokens: " + str(tokens['total_tokens']))
|
|
55
|
+
|
|
56
|
+
if self.contextmgr.counter.total_tokens != 0:
|
|
57
|
+
try:
|
|
58
|
+
client = Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
|
|
59
|
+
|
|
60
|
+
# Separate system message from user messages
|
|
61
|
+
model = models[self.config.model]
|
|
62
|
+
system_message = next((msg["content"] for msg in self.contextmgr.messages() if msg["role"] == "system"), "")
|
|
63
|
+
user_messages = [msg for msg in self.contextmgr.messages() if msg["role"] != "system"]
|
|
64
|
+
|
|
65
|
+
response = client.messages.create(
|
|
66
|
+
**model,
|
|
67
|
+
system=system_message,
|
|
68
|
+
messages=user_messages
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
logging.debug(response)
|
|
72
|
+
|
|
73
|
+
except Exception as e:
|
|
74
|
+
logging.error(traceback.format_exc())
|
|
75
|
+
return None
|
|
76
|
+
else:
|
|
77
|
+
warning = "[ hai ] The token trim backoff completely collapsed. This means that the stream was too large to fit within the total allowable context limit of " + str(self.contextmgr.counter.max_context_length) + " tokens, and the last trimming operation ended up completely wiping out the remaining conversation context."
|
|
78
|
+
logging.warning(warning)
|
|
79
|
+
self.contextmgr.save()
|
|
80
|
+
|
|
81
|
+
return warning
|
|
82
|
+
|
|
83
|
+
output_response = response
|
|
84
|
+
|
|
85
|
+
# Extract the text content from the response
|
|
86
|
+
output_content = " ".join([block.text for block in output_response.content if block.type == 'text'])
|
|
87
|
+
|
|
88
|
+
self.contextmgr.append({ "role" : output_response.role, "content" : output_content})
|
|
89
|
+
|
|
90
|
+
tokens = self.contextmgr.counter.get_stats(self.contextmgr.context)
|
|
91
|
+
logging.info("[ hai ] Response - total context tokens: " + str(tokens['total_tokens']))
|
|
92
|
+
|
|
93
|
+
output = output_content
|
|
94
|
+
|
|
95
|
+
self.contextmgr.generate_title()
|
|
96
|
+
self.contextmgr.save()
|
|
97
|
+
|
|
98
|
+
return output
|
|
99
|
+
else:
|
|
100
|
+
warning = "[ hai ] No model selected. Select one from the list of models."
|
|
101
|
+
logging.warning(warning)
|
|
102
|
+
return warning
|
|
103
|
+
|
|
104
|
+
def get_context(self):
|
|
105
|
+
with self.rlock:
|
|
106
|
+
return self.contextmgr.get_context()
|
|
107
|
+
|
|
108
|
+
def get_readable_context(self):
|
|
109
|
+
with self.rlock:
|
|
110
|
+
return self.contextmgr.get_readable_context()
|
|
111
|
+
|
|
112
|
+
def clear(self):
|
|
113
|
+
with self.rlock:
|
|
114
|
+
self.contextmgr.clear()
|
|
115
|
+
|
|
116
|
+
def behavior(self, inputstream):
|
|
117
|
+
with self.rlock:
|
|
118
|
+
self.contextmgr.behavior(inputstream)
|
|
119
|
+
|
|
120
|
+
def ls(self):
|
|
121
|
+
with self.rlock:
|
|
122
|
+
contexts = []
|
|
123
|
+
share = self.config.dot_hai_context
|
|
124
|
+
|
|
125
|
+
# Iterate through all items in the folder
|
|
126
|
+
for item in os.listdir(share):
|
|
127
|
+
item_path = os.path.join(share, item)
|
|
128
|
+
# Check if the item is a directory
|
|
129
|
+
if os.path.isdir(item_path):
|
|
130
|
+
|
|
131
|
+
context_file = os.path.join(item_path, 'context.json')
|
|
132
|
+
if os.path.exists(context_file):
|
|
133
|
+
try:
|
|
134
|
+
with open(context_file, 'r') as f:
|
|
135
|
+
context = c.Context(json.load(f))
|
|
136
|
+
title = context.title
|
|
137
|
+
name = context.name
|
|
138
|
+
update_time = os.path.getmtime(context_file)
|
|
139
|
+
contexts.append({
|
|
140
|
+
'context_id': item,
|
|
141
|
+
'title': title,
|
|
142
|
+
'name': name,
|
|
143
|
+
'update_time': update_time
|
|
144
|
+
})
|
|
145
|
+
except json.JSONDecodeError:
|
|
146
|
+
# If there's an error reading the JSON, just use the directory name
|
|
147
|
+
contexts.append({
|
|
148
|
+
'context_id': item,
|
|
149
|
+
'title': 'N/A',
|
|
150
|
+
'name': 'N/A',
|
|
151
|
+
'update_time': os.path.getmtime(context_file) if os.path.exists(context_file) else 0
|
|
152
|
+
})
|
|
153
|
+
else:
|
|
154
|
+
# If context.json doesn't exist, use the directory name only
|
|
155
|
+
contexts.append({
|
|
156
|
+
'context_id': item,
|
|
157
|
+
'title': 'N/A',
|
|
158
|
+
'name': 'N/A',
|
|
159
|
+
'update_time': 0
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
# Sort contexts by creation time, newest at the bottom of the list
|
|
163
|
+
sorted_contexts = sorted(contexts, key=lambda x: x['update_time'], reverse=False)
|
|
164
|
+
|
|
165
|
+
# Format the creation time and remove it from the final output
|
|
166
|
+
for context in sorted_contexts:
|
|
167
|
+
context['update_time'] = datetime.fromtimestamp(context['update_time']).strftime('%Y-%m-%d %H:%M:%S')
|
|
168
|
+
|
|
169
|
+
return sorted_contexts
|
|
170
|
+
|
|
171
|
+
def set(self, context_id):
|
|
172
|
+
with self.rlock:
|
|
173
|
+
contexts = self.ls()
|
|
174
|
+
context_ids = [context['context_id'] for context in contexts]
|
|
175
|
+
if context_id in context_ids:
|
|
176
|
+
self.contextmgr.set(context_id)
|
|
177
|
+
else:
|
|
178
|
+
logging.warning(context_id)
|
|
179
|
+
logging.warning("[ hai ] Provided context id is not found in available contexts.")
|
|
180
|
+
|
|
181
|
+
def new(self):
|
|
182
|
+
with self.rlock:
|
|
183
|
+
if os.path.exists(self.config.dot_hai_config_file):
|
|
184
|
+
os.remove(self.config.dot_hai_config_file)
|
|
185
|
+
self.config.init()
|
|
186
|
+
self.contextmgr.init()
|
|
187
|
+
|
|
188
|
+
return self.current()
|
|
189
|
+
|
|
190
|
+
def rm(self, context_id):
|
|
191
|
+
with self.rlock:
|
|
192
|
+
context_folder = os.path.join(self.config.dot_hai_context, context_id)
|
|
193
|
+
if os.path.exists(context_folder):
|
|
194
|
+
shutil.rmtree(context_folder)
|
|
195
|
+
logging.info("[ hai ] Removed " + context_folder)
|
|
196
|
+
|
|
197
|
+
def current(self):
|
|
198
|
+
with self.rlock:
|
|
199
|
+
return self.config.context
|
|
200
|
+
|
|
201
|
+
def list_models(self):
|
|
202
|
+
with self.rlock:
|
|
203
|
+
return self.config.list_models()
|
|
204
|
+
|
|
205
|
+
def model(self):
|
|
206
|
+
with self.rlock:
|
|
207
|
+
return self.config.model
|
|
208
|
+
|
|
209
|
+
def set_model(self, model):
|
|
210
|
+
with self.rlock:
|
|
211
|
+
models = self.list_models()
|
|
212
|
+
if model in models:
|
|
213
|
+
self.config.model = model
|
|
214
|
+
|
|
215
|
+
def name(self):
|
|
216
|
+
with self.rlock:
|
|
217
|
+
return self.contextmgr.name()
|
|
218
|
+
|
|
219
|
+
def set_name(self, name):
|
|
220
|
+
with self.rlock:
|
|
221
|
+
self.contextmgr.set_name(name)
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
hcli_integration_behavior = """
|
|
2
|
+
# AI An expert HCLI integration and Task Planning Assistant
|
|
3
|
+
|
|
4
|
+
You are an AI specialized in creating detailed external hypertext command line interface (HCLI) tool integration plans for a task requiring external tool integration via HCLI.
|
|
5
|
+
|
|
6
|
+
Note that you should simply output unconstrained responses if there is no need for HCLI external tool integration.
|
|
7
|
+
|
|
8
|
+
You will be given a a template, instructions and formatting instructions.
|
|
9
|
+
|
|
10
|
+
Your goal is to break down the given task into clear, actionable steps that a person can follow to complete the task.
|
|
11
|
+
|
|
12
|
+
Create a detailed plan for the given task. Your plan should:
|
|
13
|
+
|
|
14
|
+
- Stick to the task at hand.
|
|
15
|
+
- Do not come up with a new and different task nor a different sequence of steps. Stick to the original plan.
|
|
16
|
+
- Break down the task into clear, logical steps.
|
|
17
|
+
- Ensure the plan is detailed enough to allow a person to do the task.
|
|
18
|
+
- Include at most one hcli integration call to help trigger external tool use (only if needed).
|
|
19
|
+
- If an HCLI service can't be navigated or isn't running, move on, DO NOT try to start nor configure it.
|
|
20
|
+
- Be 100% correct and complete.
|
|
21
|
+
|
|
22
|
+
Note: Focus solely on the technical implementation. Ignore any mentions of human tasks or non-technical aspects.
|
|
23
|
+
|
|
24
|
+
Do not create a plan if no HCLI external tool integration is needed.
|
|
25
|
+
|
|
26
|
+
Encoded in XML tags, here is what you will be given:
|
|
27
|
+
TEMPLATE: A high level template of an example formatted response
|
|
28
|
+
INSTRUCTIONS: Guidelines to generate the formatted response
|
|
29
|
+
FORMAT: Instructions on how to format your response.
|
|
30
|
+
|
|
31
|
+
Encoded in XML tags, here is what you will output:
|
|
32
|
+
PLAN: A detailed plan to accomplish the task.
|
|
33
|
+
|
|
34
|
+
Not encoded in XML tags, unconststrained otherwise, here is what you may output after the XML plan tag:
|
|
35
|
+
ANYTHING: Unconstrained output.
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
# Template
|
|
40
|
+
|
|
41
|
+
## Constraints:
|
|
42
|
+
|
|
43
|
+
1. Only output one plan per response.
|
|
44
|
+
1. Only output one task per plan
|
|
45
|
+
2. Only output one list per plan.
|
|
46
|
+
3. Only output steps in a list.
|
|
47
|
+
4. Only output one hcli XML tag per plan.
|
|
48
|
+
|
|
49
|
+
## Example
|
|
50
|
+
|
|
51
|
+
no text here.
|
|
52
|
+
|
|
53
|
+
<plan>
|
|
54
|
+
<task>__TASK_GOAL__</task>
|
|
55
|
+
<list>
|
|
56
|
+
<step>__FIRST_STEP__</step>
|
|
57
|
+
<step>__SECOND_STEP__</step>
|
|
58
|
+
<step>__THIRD_STEP__</step>
|
|
59
|
+
<list>
|
|
60
|
+
<hcli>__CLI_INTEGRATION_COMMANDS__</hcli>
|
|
61
|
+
</plan>
|
|
62
|
+
|
|
63
|
+
unconstrained text here.
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
# Instructions
|
|
68
|
+
|
|
69
|
+
<instructions>
|
|
70
|
+
|
|
71
|
+
1. You should first look at the list of available hcli tools with "huckle cli ls".
|
|
72
|
+
2. If you need to manipulate hcli tools (e.g. remove, install, configure, etc.), you should use "huckle help"
|
|
73
|
+
3. You will only output a plan if you haven't reached your goal.
|
|
74
|
+
4. Reaching your goal means completing each and every step in the original plan.
|
|
75
|
+
5. When you have reached your goal you must NOT output a plan and you must simply output an unconstrained response.
|
|
76
|
+
6. Do not volunteer to demonstrate usage. Stick to the original task and plan.
|
|
77
|
+
7. Be strict in your implementation of the plan.
|
|
78
|
+
|
|
79
|
+
</instructions>
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
# Format
|
|
84
|
+
|
|
85
|
+
<format>
|
|
86
|
+
|
|
87
|
+
Format your response within the plan XML tags as follows:
|
|
88
|
+
|
|
89
|
+
<plan>
|
|
90
|
+
|
|
91
|
+
## Constraints
|
|
92
|
+
|
|
93
|
+
1. Present the overarching task so that you may know what your target is.
|
|
94
|
+
2. Present your plan as a list of remaining numbered steps.
|
|
95
|
+
3. After the list of numbered steps, you will output a hcli XML Tags.
|
|
96
|
+
|
|
97
|
+
## Task
|
|
98
|
+
|
|
99
|
+
For example:
|
|
100
|
+
<task>this is the task I'm trying to accomplish</task>
|
|
101
|
+
|
|
102
|
+
## List
|
|
103
|
+
|
|
104
|
+
Following a task is the list of remaining numbered steps. Each step should be clear and should only be for one thing, not multiple things.
|
|
105
|
+
|
|
106
|
+
for example:
|
|
107
|
+
<list>
|
|
108
|
+
<step>1. first step</step>
|
|
109
|
+
<step>2. second step</step>
|
|
110
|
+
<step>3. third step</step>
|
|
111
|
+
<list>
|
|
112
|
+
|
|
113
|
+
## HCLI
|
|
114
|
+
|
|
115
|
+
After the numbered list of steps, and per the next step to execute in the plan, output only one of the following in an hcli XML tag:
|
|
116
|
+
1. HCLI Tools: huckle cli ls
|
|
117
|
+
2. Huckle help: huckle help
|
|
118
|
+
3. HCLI Tool help: hcli_tool help
|
|
119
|
+
4. Command help: hcli_tool command help
|
|
120
|
+
|
|
121
|
+
hcli_tool is expected to be a tool listed from huckle cli ls.
|
|
122
|
+
|
|
123
|
+
For example:
|
|
124
|
+
<hcli>huckle cli ls</hcli>
|
|
125
|
+
|
|
126
|
+
</plan>
|
|
127
|
+
|
|
128
|
+
## Unconstrained
|
|
129
|
+
|
|
130
|
+
Unconststrained output here otherwise, as needed.
|
|
131
|
+
|
|
132
|
+
</format>
|
|
133
|
+
"""
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import io
|
|
3
3
|
import ai
|
|
4
|
+
import service
|
|
5
|
+
import logger
|
|
4
6
|
from utils import formatting
|
|
5
7
|
|
|
6
8
|
from typing import Optional, Dict, Callable, List
|
|
7
9
|
|
|
10
|
+
logging = logger.Logger()
|
|
11
|
+
logging.setLevel(logger.INFO)
|
|
12
|
+
|
|
13
|
+
|
|
8
14
|
class CLI:
|
|
9
15
|
def __init__(self, commands: List[str], inputstream: Optional[io.BytesIO] = None):
|
|
10
16
|
self.commands = commands
|
|
11
17
|
self.inputstream = inputstream
|
|
12
18
|
self.ai = ai.AI()
|
|
19
|
+
self.service = service.Service()
|
|
13
20
|
self.handlers: Dict[str, Callable] = {
|
|
14
21
|
'clear': lambda: self.ai.clear(),
|
|
15
22
|
'context': self._handle_context,
|
|
@@ -20,7 +27,8 @@ class CLI:
|
|
|
20
27
|
'name': self._handle_name,
|
|
21
28
|
'model': self._handle_model,
|
|
22
29
|
'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
|
|
30
|
+
'rm': lambda: self.ai.rm(self.commands[2]) if len(self.commands) == 3 else None,
|
|
31
|
+
'vibe': self._handle_vibe
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
def execute(self) -> Optional[io.BytesIO]:
|
|
@@ -91,3 +99,10 @@ class CLI:
|
|
|
91
99
|
|
|
92
100
|
return None
|
|
93
101
|
|
|
102
|
+
def _handle_vibe(self) -> None:
|
|
103
|
+
if len(self.commands) == 3:
|
|
104
|
+
if self.commands[2] == "start":
|
|
105
|
+
self.service.vibe(True)
|
|
106
|
+
if self.commands[2] == "stop":
|
|
107
|
+
self.service.vibe(False)
|
|
108
|
+
return None
|
|
@@ -90,10 +90,13 @@ class Config:
|
|
|
90
90
|
try:
|
|
91
91
|
with open(context_file_path, 'r') as f:
|
|
92
92
|
context = c.Context(json.load(f))
|
|
93
|
+
logging.debug(f"[ hai ] Loaded context from {context_file_path}")
|
|
93
94
|
return context
|
|
94
95
|
except:
|
|
96
|
+
logging.debug("[ hai ] Unable to open context file not found, creating new")
|
|
95
97
|
return self.new()
|
|
96
98
|
else:
|
|
99
|
+
logging.debug("[ hai ] Context file not found, creating new")
|
|
97
100
|
return self.new()
|
|
98
101
|
|
|
99
102
|
return None
|
|
@@ -101,11 +101,11 @@ class Context:
|
|
|
101
101
|
|
|
102
102
|
|
|
103
103
|
class ContextManager:
|
|
104
|
-
|
|
104
|
+
init_rlock = threading.RLock()
|
|
105
105
|
instance = None
|
|
106
106
|
|
|
107
107
|
def __new__(cls):
|
|
108
|
-
with cls.
|
|
108
|
+
with cls.init_rlock:
|
|
109
109
|
if cls.instance is None:
|
|
110
110
|
cls.instance = super().__new__(cls)
|
|
111
111
|
cls.instance.__init()
|
|
@@ -123,35 +123,6 @@ class ContextManager:
|
|
|
123
123
|
self.config = c.Config()
|
|
124
124
|
self.context = self.get_context()
|
|
125
125
|
|
|
126
|
-
# def __count(self):
|
|
127
|
-
# with self.rlock:
|
|
128
|
-
# encoding = tiktoken.get_encoding(self.encoding_base)
|
|
129
|
-
#
|
|
130
|
-
# self.message_tokens = 0
|
|
131
|
-
# for item in self.context.messages:
|
|
132
|
-
# if "content" in item:
|
|
133
|
-
# self.message_tokens += len(encoding.encode(item["content"]))
|
|
134
|
-
#
|
|
135
|
-
# self.context_tokens = 0
|
|
136
|
-
# for item in self.context.messages:
|
|
137
|
-
# self.context_tokens += len(encoding.encode(json.dumps(item)))
|
|
138
|
-
#
|
|
139
|
-
# self.total_tokens = self.message_tokens + self.context_tokens
|
|
140
|
-
# message = "Context tokens: " + str(self.total_tokens)
|
|
141
|
-
# logging.info(message)
|
|
142
|
-
#
|
|
143
|
-
# if self.total_tokens > self.max_context_length:
|
|
144
|
-
# return True
|
|
145
|
-
#
|
|
146
|
-
# return False
|
|
147
|
-
#
|
|
148
|
-
# def trim(self):
|
|
149
|
-
# with self.rlock:
|
|
150
|
-
# while(self.__count()):
|
|
151
|
-
# self.context.messages.pop(1)
|
|
152
|
-
# message = "Context tokens: " + str(self.total_tokens) + ". Trimming the oldest entries to remain under " + str(self.max_context_length) + " tokens."
|
|
153
|
-
# logging.info(message)
|
|
154
|
-
|
|
155
126
|
def trim(self):
|
|
156
127
|
self.counter.trim(self.context)
|
|
157
128
|
|
|
@@ -175,7 +146,12 @@ class ContextManager:
|
|
|
175
146
|
def append(self, question):
|
|
176
147
|
with self.rlock:
|
|
177
148
|
if not isinstance(question, dict) or 'role' not in question or 'content' not in question:
|
|
178
|
-
raise ValueError("Invalid message format. Expected dict with 'role' and 'content' keys")
|
|
149
|
+
raise ValueError("[ hai ] Invalid message format. Expected dict with 'role' and 'content' keys")
|
|
150
|
+
|
|
151
|
+
# Skip empty messages
|
|
152
|
+
if question['content'].strip() == '':
|
|
153
|
+
logging.warning("[ hai ] Skipping attempt to add empty message")
|
|
154
|
+
return
|
|
179
155
|
|
|
180
156
|
logging.debug(question)
|
|
181
157
|
current_messages = self.context.messages
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import queue as q
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# Singleton Job Queue for sequential streaming jobs in a single process multithread environment
|
|
5
|
+
class JobQueue:
|
|
6
|
+
instance = None
|
|
7
|
+
_queue = None
|
|
8
|
+
_dirty = False
|
|
9
|
+
|
|
10
|
+
def __new__(self):
|
|
11
|
+
if self.instance is None:
|
|
12
|
+
|
|
13
|
+
self.instance = super().__new__(self)
|
|
14
|
+
self._queue = q.Queue()
|
|
15
|
+
|
|
16
|
+
return self.instance
|
|
17
|
+
|
|
18
|
+
# adds a named job to the queue if the queue isn't dirty
|
|
19
|
+
def put(self, function):
|
|
20
|
+
if not self._dirty:
|
|
21
|
+
return self._queue.put(function)
|
|
22
|
+
|
|
23
|
+
def get(self):
|
|
24
|
+
return self._queue.get(self)
|
|
25
|
+
|
|
26
|
+
def qsize(self):
|
|
27
|
+
return self._queue.qsize()
|
|
28
|
+
|
|
29
|
+
# we allow for self correction on a dirty queue if we notice the queue is empty
|
|
30
|
+
def empty(self):
|
|
31
|
+
empty = self._queue.empty()
|
|
32
|
+
if empty:
|
|
33
|
+
self._dirty = False
|
|
34
|
+
return empty
|
|
35
|
+
|
|
36
|
+
def clear(self):
|
|
37
|
+
self._dirty = False
|
|
38
|
+
return self._queue.queue.clear()
|
|
39
|
+
|
|
40
|
+
def list(self):
|
|
41
|
+
return list(self._queue.queue)
|
|
42
|
+
|
|
43
|
+
def is_dirty(self):
|
|
44
|
+
return self._dirty
|
|
45
|
+
|
|
46
|
+
# dirty status toggle
|
|
47
|
+
def dirty(self, is_dirty):
|
|
48
|
+
self._dirty = is_dirty
|
|
49
|
+
return self._dirty
|