minor: tweak prompt wording, improve OAI history compression
This commit is contained in:
2
ga.py
2
ga.py
@@ -278,7 +278,7 @@ class GenericAgentHandler(BaseHandler):
|
||||
summary = f"调用工具{tool_name}, args: {args}"
|
||||
if tool_name == 'no_tool': summary = "直接回答了用户问题"
|
||||
if type(ret.next_prompt) is str:
|
||||
ret.next_prompt += "\nPROTOCOL_VIOLATION: 上一轮遗漏了<summary>。 我已根据物理动作自动补全。请务必在下次回复中记得<summary>协议。"
|
||||
ret.next_prompt += "\nPROTOCOL_VIOLATION: 上一轮遗漏了<summary>。 已根据物理动作自动补全。请务必在下次回复中记得<summary>协议。"
|
||||
self.history_info.append('[Agent] ' + smart_format(summary, max_str_len=100))
|
||||
|
||||
def do_code_run(self, args, response):
|
||||
|
||||
13
llmcore.py
13
llmcore.py
@@ -419,7 +419,7 @@ class NativeOAISession:
|
||||
def __init__(self, cfg):
|
||||
self.api_key = cfg['apikey']; self.api_base = cfg['apibase'].rstrip('/')
|
||||
self.default_model = cfg.get('model', 'gpt-4o')
|
||||
self.context_win = cfg.get('context_win', 24000)
|
||||
self.context_win = cfg.get('context_win', 28000)
|
||||
proxy = cfg.get('proxy')
|
||||
self.proxies = {"http": proxy, "https": proxy} if proxy else None
|
||||
self.history = []; self.system = None; self.lock = threading.Lock()
|
||||
@@ -470,10 +470,13 @@ class NativeOAISession:
|
||||
elif isinstance(msg, list): msg = {"role": "user", "content": msg}
|
||||
with self.lock:
|
||||
self.history.append(msg)
|
||||
while len(self.history) > 2:
|
||||
cost = sum(len(json.dumps(m, ensure_ascii=False)) for m in self.history) + len(self.system or '')
|
||||
if cost <= self.context_win * 4: break
|
||||
self.history.pop(0); self.history.pop(0)
|
||||
compress_history_tags(self.history)
|
||||
cost = sum(len(json.dumps(m, ensure_ascii=False)) for m in self.history)
|
||||
if cost > self.context_win * 3:
|
||||
target = self.context_win * 3 * 0.6
|
||||
while len(self.history) > 2 and cost > target:
|
||||
self.history.pop(0); self.history.pop(0)
|
||||
cost = sum(len(json.dumps(m, ensure_ascii=False)) for m in self.history)
|
||||
messages = list(self.history)
|
||||
content_blocks = None
|
||||
gen = self.raw_ask(messages, tools, self.system, model)
|
||||
|
||||
Reference in New Issue
Block a user