hcli-hai 3.1.0__tar.gz → 3.3.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.1.0/hcli_hai.egg-info → hcli_hai-3.3.0}/PKG-INFO +12 -5
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/README.rst +5 -1
- hcli_hai-3.3.0/hcli_hai/__main__.py +61 -0
- hcli_hai-3.3.0/hcli_hai/cli/ai.py +241 -0
- hcli_hai-3.3.0/hcli_hai/cli/behavior.py +134 -0
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/hcli_hai/cli/cli.py +18 -1
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/hcli_hai/cli/config.py +3 -0
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/hcli_hai/cli/context.py +39 -3
- hcli_hai-3.3.0/hcli_hai/cli/jobqueue.py +49 -0
- hcli_hai-3.3.0/hcli_hai/cli/runner.py +137 -0
- hcli_hai-3.3.0/hcli_hai/cli/service.py +89 -0
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/hcli_hai/cli/template.json +106 -0
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/hcli_hai/data/hcli_hai.1 +1 -1
- hcli_hai-3.3.0/hcli_hai/package.py +5 -0
- {hcli_hai-3.1.0 → hcli_hai-3.3.0/hcli_hai.egg-info}/PKG-INFO +12 -5
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/hcli_hai.egg-info/SOURCES.txt +4 -0
- hcli_hai-3.3.0/hcli_hai.egg-info/requires.txt +4 -0
- hcli_hai-3.3.0/requirements.txt +4 -0
- hcli_hai-3.1.0/hcli_hai/__main__.py +0 -44
- hcli_hai-3.1.0/hcli_hai/cli/ai.py +0 -192
- hcli_hai-3.1.0/hcli_hai/package.py +0 -3
- hcli_hai-3.1.0/hcli_hai.egg-info/requires.txt +0 -2
- hcli_hai-3.1.0/requirements.txt +0 -2
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/LICENSE.txt +0 -0
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/MANIFEST.in +0 -0
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/hcli_hai/__init__.py +0 -0
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/hcli_hai/cli/__init__.py +0 -0
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/hcli_hai/cli/logger.py +0 -0
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/hcli_hai/cli/model.py +0 -0
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/hcli_hai/cli/utils/formatting.py +0 -0
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/hcli_hai/cli/utils/hutils.py +0 -0
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/hcli_hai/cli/utils/summary.py +0 -0
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/hcli_hai/config.py +0 -0
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/hcli_hai/hutils.py +0 -0
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/hcli_hai.egg-info/dependency_links.txt +0 -0
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/hcli_hai.egg-info/entry_points.txt +0 -0
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/hcli_hai.egg-info/top_level.txt +0 -0
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/pyproject.toml +0 -0
- {hcli_hai-3.1.0 → hcli_hai-3.3.0}/setup.cfg +0 -0
- {hcli_hai-3.1.0 → hcli_hai-3.3.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.
|
|
3
|
+
Version: 3.3.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
|
-----
|
|
@@ -94,11 +99,13 @@ To Do
|
|
|
94
99
|
- Context blending to mary different contexts.
|
|
95
100
|
- Automatic context compression to yield a more substantial memory footprint per context window.
|
|
96
101
|
- A shell mode for the AI HCLI (hai) to enable shell CLI execution per sought goal.
|
|
102
|
+
- Changing context while vibing is tenuous and can be disgraceful. It should be thought about.
|
|
103
|
+
- Changing the vibing behavior should be made possible; it is currently locked in to HCLI integration and planning.
|
|
97
104
|
|
|
98
105
|
Bugs
|
|
99
106
|
----
|
|
100
107
|
|
|
101
|
-
|
|
108
|
+
TBD
|
|
102
109
|
|
|
103
110
|
.. |build status| image:: https://circleci.com/gh/cometaj2/hcli_hai.svg?style=shield
|
|
104
111
|
: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
|
-----
|
|
@@ -74,11 +76,13 @@ To Do
|
|
|
74
76
|
- Context blending to mary different contexts.
|
|
75
77
|
- Automatic context compression to yield a more substantial memory footprint per context window.
|
|
76
78
|
- A shell mode for the AI HCLI (hai) to enable shell CLI execution per sought goal.
|
|
79
|
+
- Changing context while vibing is tenuous and can be disgraceful. It should be thought about.
|
|
80
|
+
- Changing the vibing behavior should be made possible; it is currently locked in to HCLI integration and planning.
|
|
77
81
|
|
|
78
82
|
Bugs
|
|
79
83
|
----
|
|
80
84
|
|
|
81
|
-
|
|
85
|
+
TBD
|
|
82
86
|
|
|
83
87
|
.. |build status| image:: https://circleci.com/gh/cometaj2/hcli_hai.svg?style=shield
|
|
84
88
|
: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])
|
|
@@ -0,0 +1,241 @@
|
|
|
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
|
+
# add an additional message to the chat context and request a response for it with the LLM.
|
|
44
|
+
def chat(self, inputstream):
|
|
45
|
+
with self.rlock:
|
|
46
|
+
if self.config.model is not None:
|
|
47
|
+
inputstream = inputstream.read().decode('utf-8')
|
|
48
|
+
if inputstream != "":
|
|
49
|
+
inputstream = inputstream.rstrip()
|
|
50
|
+
question = { "role" : "user", "content" : inputstream }
|
|
51
|
+
self.contextmgr.append(question)
|
|
52
|
+
self.contextmgr.trim()
|
|
53
|
+
|
|
54
|
+
tokens = self.contextmgr.counter.get_stats(self.contextmgr.context)
|
|
55
|
+
logging.info("[ hai ] Request - total context tokens: " + str(tokens['total_tokens']))
|
|
56
|
+
|
|
57
|
+
if self.contextmgr.counter.total_tokens != 0:
|
|
58
|
+
try:
|
|
59
|
+
client = Anthropic(api_key=os.environ.get("ANTHROPIC_API_KEY"))
|
|
60
|
+
|
|
61
|
+
# Separate system message from user messages
|
|
62
|
+
model = models[self.config.model]
|
|
63
|
+
system_message = next((msg["content"] for msg in self.contextmgr.messages() if msg["role"] == "system"), "")
|
|
64
|
+
user_messages = [msg for msg in self.contextmgr.messages() if msg["role"] != "system"]
|
|
65
|
+
|
|
66
|
+
response = client.messages.create(
|
|
67
|
+
**model,
|
|
68
|
+
system=system_message,
|
|
69
|
+
messages=user_messages
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
logging.debug(response)
|
|
73
|
+
|
|
74
|
+
except Exception as e:
|
|
75
|
+
logging.error(traceback.format_exc())
|
|
76
|
+
return None
|
|
77
|
+
else:
|
|
78
|
+
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."
|
|
79
|
+
logging.warning(warning)
|
|
80
|
+
self.contextmgr.save()
|
|
81
|
+
|
|
82
|
+
return warning
|
|
83
|
+
|
|
84
|
+
output_response = response
|
|
85
|
+
|
|
86
|
+
# Extract the text content from the response
|
|
87
|
+
output_content = " ".join([block.text for block in output_response.content if block.type == 'text'])
|
|
88
|
+
|
|
89
|
+
self.contextmgr.append({ "role" : output_response.role, "content" : output_content})
|
|
90
|
+
|
|
91
|
+
tokens = self.contextmgr.counter.get_stats(self.contextmgr.context)
|
|
92
|
+
logging.info("[ hai ] Response - total context tokens: " + str(tokens['total_tokens']))
|
|
93
|
+
|
|
94
|
+
output = output_content
|
|
95
|
+
|
|
96
|
+
self.contextmgr.generate_title()
|
|
97
|
+
self.contextmgr.save()
|
|
98
|
+
|
|
99
|
+
return output
|
|
100
|
+
else:
|
|
101
|
+
warning = "[ hai ] No model selected. Select one from the list of models."
|
|
102
|
+
logging.warning(warning)
|
|
103
|
+
return warning
|
|
104
|
+
|
|
105
|
+
# get the current context as json output
|
|
106
|
+
def get_context(self):
|
|
107
|
+
with self.rlock:
|
|
108
|
+
return self.contextmgr.get_context()
|
|
109
|
+
|
|
110
|
+
# get the current context as text output
|
|
111
|
+
def get_readable_context(self):
|
|
112
|
+
with self.rlock:
|
|
113
|
+
return self.contextmgr.get_readable_context()
|
|
114
|
+
|
|
115
|
+
# clear the current context (clean slate)
|
|
116
|
+
def clear(self):
|
|
117
|
+
with self.rlock:
|
|
118
|
+
self.contextmgr.clear()
|
|
119
|
+
|
|
120
|
+
# set the persistent context behavior (system prompt)
|
|
121
|
+
def behavior(self, inputstream):
|
|
122
|
+
with self.rlock:
|
|
123
|
+
self.contextmgr.behavior(inputstream)
|
|
124
|
+
|
|
125
|
+
# list all contexts
|
|
126
|
+
def ls(self):
|
|
127
|
+
with self.rlock:
|
|
128
|
+
contexts = []
|
|
129
|
+
share = self.config.dot_hai_context
|
|
130
|
+
|
|
131
|
+
# Iterate through all items in the folder
|
|
132
|
+
for item in os.listdir(share):
|
|
133
|
+
item_path = os.path.join(share, item)
|
|
134
|
+
# Check if the item is a directory
|
|
135
|
+
if os.path.isdir(item_path):
|
|
136
|
+
|
|
137
|
+
context_file = os.path.join(item_path, 'context.json')
|
|
138
|
+
if os.path.exists(context_file):
|
|
139
|
+
try:
|
|
140
|
+
with open(context_file, 'r') as f:
|
|
141
|
+
context = c.Context(json.load(f))
|
|
142
|
+
title = context.title
|
|
143
|
+
name = context.name
|
|
144
|
+
update_time = os.path.getmtime(context_file)
|
|
145
|
+
contexts.append({
|
|
146
|
+
'context_id': item,
|
|
147
|
+
'title': title,
|
|
148
|
+
'name': name,
|
|
149
|
+
'update_time': update_time
|
|
150
|
+
})
|
|
151
|
+
except json.JSONDecodeError:
|
|
152
|
+
# If there's an error reading the JSON, just use the directory name
|
|
153
|
+
contexts.append({
|
|
154
|
+
'context_id': item,
|
|
155
|
+
'title': 'N/A',
|
|
156
|
+
'name': 'N/A',
|
|
157
|
+
'update_time': os.path.getmtime(context_file) if os.path.exists(context_file) else 0
|
|
158
|
+
})
|
|
159
|
+
else:
|
|
160
|
+
# If context.json doesn't exist, use the directory name only
|
|
161
|
+
contexts.append({
|
|
162
|
+
'context_id': item,
|
|
163
|
+
'title': 'N/A',
|
|
164
|
+
'name': 'N/A',
|
|
165
|
+
'update_time': 0
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
# Sort contexts by creation time, newest at the bottom of the list
|
|
169
|
+
sorted_contexts = sorted(contexts, key=lambda x: x['update_time'], reverse=False)
|
|
170
|
+
|
|
171
|
+
# Format the creation time and remove it from the final output
|
|
172
|
+
for context in sorted_contexts:
|
|
173
|
+
context['update_time'] = datetime.fromtimestamp(context['update_time']).strftime('%Y-%m-%d %H:%M:%S')
|
|
174
|
+
|
|
175
|
+
return sorted_contexts
|
|
176
|
+
|
|
177
|
+
# set the current context
|
|
178
|
+
def set(self, context_id):
|
|
179
|
+
with self.rlock:
|
|
180
|
+
contexts = self.ls()
|
|
181
|
+
context_ids = [context['context_id'] for context in contexts]
|
|
182
|
+
if context_id in context_ids:
|
|
183
|
+
self.contextmgr.set(context_id)
|
|
184
|
+
else:
|
|
185
|
+
logging.warning(context_id)
|
|
186
|
+
logging.warning("[ hai ] Provided context id is not found in available contexts.")
|
|
187
|
+
|
|
188
|
+
# create a new context
|
|
189
|
+
def new(self):
|
|
190
|
+
with self.rlock:
|
|
191
|
+
if os.path.exists(self.config.dot_hai_config_file):
|
|
192
|
+
os.remove(self.config.dot_hai_config_file)
|
|
193
|
+
self.config.init()
|
|
194
|
+
self.contextmgr.init()
|
|
195
|
+
|
|
196
|
+
return self.current()
|
|
197
|
+
|
|
198
|
+
# delete the current context
|
|
199
|
+
def rm(self, context_id):
|
|
200
|
+
with self.rlock:
|
|
201
|
+
context_folder = os.path.join(self.config.dot_hai_context, context_id)
|
|
202
|
+
if os.path.exists(context_folder):
|
|
203
|
+
shutil.rmtree(context_folder)
|
|
204
|
+
logging.info("[ hai ] Removed " + context_folder)
|
|
205
|
+
|
|
206
|
+
# get the current context ID
|
|
207
|
+
def current(self):
|
|
208
|
+
with self.rlock:
|
|
209
|
+
return self.config.context
|
|
210
|
+
|
|
211
|
+
# list available models
|
|
212
|
+
def list_models(self):
|
|
213
|
+
with self.rlock:
|
|
214
|
+
return self.config.list_models()
|
|
215
|
+
|
|
216
|
+
# get the model to use
|
|
217
|
+
def model(self):
|
|
218
|
+
with self.rlock:
|
|
219
|
+
return self.config.model
|
|
220
|
+
|
|
221
|
+
# set the model to use
|
|
222
|
+
def set_model(self, model):
|
|
223
|
+
with self.rlock:
|
|
224
|
+
models = self.list_models()
|
|
225
|
+
if model in models:
|
|
226
|
+
self.config.model = model
|
|
227
|
+
|
|
228
|
+
# get the context name
|
|
229
|
+
def name(self):
|
|
230
|
+
with self.rlock:
|
|
231
|
+
return self.contextmgr.name()
|
|
232
|
+
|
|
233
|
+
# set the context name
|
|
234
|
+
def set_name(self, name):
|
|
235
|
+
with self.rlock:
|
|
236
|
+
self.contextmgr.set_name(name)
|
|
237
|
+
|
|
238
|
+
# output current plan as status
|
|
239
|
+
def status(self):
|
|
240
|
+
with self.rlock:
|
|
241
|
+
return self.contextmgr.status()
|
|
@@ -0,0 +1,134 @@
|
|
|
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
|
+
- If your task is accomplished per your original plan, STOP by no longer outputting a plan.
|
|
21
|
+
- Be 100% correct and complete.
|
|
22
|
+
|
|
23
|
+
Note: Focus solely on the technical implementation. Ignore any mentions of human tasks or non-technical aspects.
|
|
24
|
+
|
|
25
|
+
Do not create a plan if no HCLI external tool integration is needed.
|
|
26
|
+
|
|
27
|
+
Encoded in XML tags, here is what you will be given:
|
|
28
|
+
TEMPLATE: A high level template of an example formatted response
|
|
29
|
+
INSTRUCTIONS: Guidelines to generate the formatted response
|
|
30
|
+
FORMAT: Instructions on how to format your response.
|
|
31
|
+
|
|
32
|
+
Encoded in XML tags, here is what you will output:
|
|
33
|
+
PLAN: A detailed plan to accomplish the task.
|
|
34
|
+
|
|
35
|
+
Not encoded in XML tags, unconststrained otherwise, here is what you may output after the XML plan tag:
|
|
36
|
+
ANYTHING: Unconstrained output.
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
# Template
|
|
41
|
+
|
|
42
|
+
## Constraints:
|
|
43
|
+
|
|
44
|
+
1. Only output one plan per response.
|
|
45
|
+
1. Only output one task per plan
|
|
46
|
+
2. Only output one list per plan.
|
|
47
|
+
3. Only output steps in a list.
|
|
48
|
+
4. Only output one hcli XML tag per plan.
|
|
49
|
+
|
|
50
|
+
## Example
|
|
51
|
+
|
|
52
|
+
no text here.
|
|
53
|
+
|
|
54
|
+
<plan>
|
|
55
|
+
<task>__TASK_GOAL__</task>
|
|
56
|
+
<list>
|
|
57
|
+
<step>__FIRST_STEP__</step>
|
|
58
|
+
<step>__SECOND_STEP__</step>
|
|
59
|
+
<step>__THIRD_STEP__</step>
|
|
60
|
+
<list>
|
|
61
|
+
<hcli>__CLI_INTEGRATION_COMMANDS__</hcli>
|
|
62
|
+
</plan>
|
|
63
|
+
|
|
64
|
+
unconstrained text here.
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
# Instructions
|
|
69
|
+
|
|
70
|
+
<instructions>
|
|
71
|
+
|
|
72
|
+
1. You should first look at the list of available hcli tools with "huckle cli ls".
|
|
73
|
+
2. If you need to manipulate hcli tools (e.g. remove, install, configure, etc.), you should use "huckle help"
|
|
74
|
+
3. You will only output a plan if you haven't reached your goal.
|
|
75
|
+
4. Reaching your goal means completing each and every step in the original plan.
|
|
76
|
+
5. When you have reached your goal you must NOT output a plan and you must simply output an unconstrained response.
|
|
77
|
+
6. Do not volunteer to demonstrate usage. Stick to the original task and plan.
|
|
78
|
+
7. Be strict in your implementation of the plan.
|
|
79
|
+
|
|
80
|
+
</instructions>
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
# Format
|
|
85
|
+
|
|
86
|
+
<format>
|
|
87
|
+
|
|
88
|
+
Format your response within the plan XML tags as follows:
|
|
89
|
+
|
|
90
|
+
<plan>
|
|
91
|
+
|
|
92
|
+
## Constraints
|
|
93
|
+
|
|
94
|
+
1. Present the overarching task so that you may know what your target is.
|
|
95
|
+
2. Present your plan as a list of remaining numbered steps.
|
|
96
|
+
3. After the list of numbered steps, you will output a hcli XML Tags.
|
|
97
|
+
|
|
98
|
+
## Task
|
|
99
|
+
|
|
100
|
+
For example:
|
|
101
|
+
<task>this is the task I'm trying to accomplish</task>
|
|
102
|
+
|
|
103
|
+
## List
|
|
104
|
+
|
|
105
|
+
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.
|
|
106
|
+
|
|
107
|
+
for example:
|
|
108
|
+
<list>
|
|
109
|
+
<step>1. first step</step>
|
|
110
|
+
<step>2. second step</step>
|
|
111
|
+
<step>3. third step</step>
|
|
112
|
+
<list>
|
|
113
|
+
|
|
114
|
+
## HCLI
|
|
115
|
+
|
|
116
|
+
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:
|
|
117
|
+
1. HCLI Tools: huckle cli ls
|
|
118
|
+
2. Huckle help: huckle help
|
|
119
|
+
3. HCLI Tool help: hcli_tool help
|
|
120
|
+
4. Command help: hcli_tool command help
|
|
121
|
+
|
|
122
|
+
hcli_tool is expected to be a tool listed from huckle cli ls.
|
|
123
|
+
|
|
124
|
+
For example:
|
|
125
|
+
<hcli>huckle cli ls</hcli>
|
|
126
|
+
|
|
127
|
+
</plan>
|
|
128
|
+
|
|
129
|
+
## Unconstrained
|
|
130
|
+
|
|
131
|
+
Unconststrained output here otherwise, as needed.
|
|
132
|
+
|
|
133
|
+
</format>
|
|
134
|
+
"""
|
|
@@ -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,12 @@ 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
|
+
elif self.commands[2] == "stop":
|
|
107
|
+
self.service.vibe(False)
|
|
108
|
+
elif self.commands[2] == "status":
|
|
109
|
+
return io.BytesIO(self.ai.status().encode('utf-8'))
|
|
110
|
+
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
|
|
@@ -14,6 +14,28 @@ from utils import summary as s
|
|
|
14
14
|
logging = logger.Logger()
|
|
15
15
|
|
|
16
16
|
|
|
17
|
+
# Singleton Plan class to hold the ephemeral plan
|
|
18
|
+
class Plan:
|
|
19
|
+
_instance = None
|
|
20
|
+
_rlock = threading.RLock()
|
|
21
|
+
|
|
22
|
+
def __new__(cls):
|
|
23
|
+
with cls._rlock:
|
|
24
|
+
if cls._instance is None:
|
|
25
|
+
cls._instance = super().__new__(cls)
|
|
26
|
+
cls._instance._plan = ""
|
|
27
|
+
return cls._instance
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def plan(self):
|
|
31
|
+
with self._rlock:
|
|
32
|
+
return self._plan
|
|
33
|
+
|
|
34
|
+
@plan.setter
|
|
35
|
+
def plan(self, value):
|
|
36
|
+
with self._rlock:
|
|
37
|
+
self._plan = value
|
|
38
|
+
|
|
17
39
|
# We create a default context and allow for it to be initialized in a few different ways to facilitate initialization from file
|
|
18
40
|
class Context:
|
|
19
41
|
|
|
@@ -101,11 +123,11 @@ class Context:
|
|
|
101
123
|
|
|
102
124
|
|
|
103
125
|
class ContextManager:
|
|
104
|
-
|
|
126
|
+
init_rlock = threading.RLock()
|
|
105
127
|
instance = None
|
|
106
128
|
|
|
107
129
|
def __new__(cls):
|
|
108
|
-
with cls.
|
|
130
|
+
with cls.init_rlock:
|
|
109
131
|
if cls.instance is None:
|
|
110
132
|
cls.instance = super().__new__(cls)
|
|
111
133
|
cls.instance.__init()
|
|
@@ -122,6 +144,7 @@ class ContextManager:
|
|
|
122
144
|
self.counter = TrimCounter()
|
|
123
145
|
self.config = c.Config()
|
|
124
146
|
self.context = self.get_context()
|
|
147
|
+
self.plan = Plan()
|
|
125
148
|
|
|
126
149
|
def trim(self):
|
|
127
150
|
self.counter.trim(self.context)
|
|
@@ -146,7 +169,12 @@ class ContextManager:
|
|
|
146
169
|
def append(self, question):
|
|
147
170
|
with self.rlock:
|
|
148
171
|
if not isinstance(question, dict) or 'role' not in question or 'content' not in question:
|
|
149
|
-
raise ValueError("Invalid message format. Expected dict with 'role' and 'content' keys")
|
|
172
|
+
raise ValueError("[ hai ] Invalid message format. Expected dict with 'role' and 'content' keys")
|
|
173
|
+
|
|
174
|
+
# Skip empty messages
|
|
175
|
+
if question['content'].strip() == '':
|
|
176
|
+
logging.warning("[ hai ] Skipping attempt to add empty message")
|
|
177
|
+
return
|
|
150
178
|
|
|
151
179
|
logging.debug(question)
|
|
152
180
|
current_messages = self.context.messages
|
|
@@ -229,6 +257,14 @@ class ContextManager:
|
|
|
229
257
|
|
|
230
258
|
return self.context.title
|
|
231
259
|
|
|
260
|
+
def set_status(self, plan):
|
|
261
|
+
with self.rlock:
|
|
262
|
+
self.plan.plan = plan
|
|
263
|
+
|
|
264
|
+
def status(self):
|
|
265
|
+
with self.rlock:
|
|
266
|
+
return self.plan.plan
|
|
267
|
+
|
|
232
268
|
class TrimCounter:
|
|
233
269
|
def __init__(self):
|
|
234
270
|
self.encoding_base = "cl100k_base"
|
|
@@ -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
|