开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
main
分支 (1)
main
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
项目仓库所选许可证以仓库主分支所使用许可证为准
main
分支 (1)
main
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
main
分支 (1)
main
MiniCode-Python
/
minicode
/
mock_model.py
MiniCode-Python
/
minicode
/
mock_model.py
mock_model.py 5.23 KB
一键复制 编辑 原始数据 按行查看 历史
QUSETIONS 提交于 2026年04月11日 11:07 +08:00 . Complete Python parity and task tracking fixes
from __future__ import annotations
import time
from minicode.types import AgentStep
def _last_user_message(messages):
return next((message["content"] for message in reversed(messages) if message["role"] == "user"), "")
def _last_tool_message(messages):
return next((message for message in reversed(messages) if message["role"] == "tool_result"), None)
def _latest_assistant_call(messages):
call = next((message for message in reversed(messages) if message["role"] == "assistant_tool_call"), None)
return call["toolName"] if call else None
class MockModelAdapter:
def next(self, messages, on_stream_chunk=None):
tool_message = _last_tool_message(messages)
if tool_message and tool_message["role"] == "tool_result":
last_call = _latest_assistant_call(messages)
if last_call == "list_files":
return AgentStep(type="assistant", content=f"Directory contents:\n\n{tool_message['content']}")
if last_call == "read_file":
return AgentStep(type="assistant", content=f"File contents:\n\n{tool_message['content']}")
if last_call in {"write_file", "edit_file", "modify_file", "patch_file"}:
return AgentStep(type="assistant", content=tool_message["content"])
return AgentStep(type="assistant", content=f"I received the tool result:\n\n{tool_message['content']}")
user_text = _last_user_message(messages).strip()
tool_id = f"mock-{int(time.time() * 1000)}"
if user_text == "/tools":
return AgentStep(
type="assistant",
content="Available tools: ask_user, list_files, grep_files, read_file, write_file, edit_file, patch_file, run_command",
)
if user_text.startswith("/ls"):
directory = user_text.replace("/ls", "", 1).strip()
return AgentStep(
type="tool_calls",
calls=[{"id": tool_id, "toolName": "list_files", "input": {"path": directory} if directory else {}}],
)
if user_text.startswith("/grep "):
payload = user_text[len("/grep ") :].strip()
pattern, _, search_path = payload.partition("::")
return AgentStep(
type="tool_calls",
calls=[
{
"id": tool_id,
"toolName": "grep_files",
"input": {"pattern": pattern.strip(), "path": search_path.strip() or None},
}
],
)
if user_text.startswith("/read "):
return AgentStep(
type="tool_calls",
calls=[{"id": tool_id, "toolName": "read_file", "input": {"path": user_text[len('/read ') :].strip()}}],
)
if user_text.startswith("/cmd "):
payload = user_text[len("/cmd ") :].strip()
return AgentStep(type="tool_calls", calls=[{"id": tool_id, "toolName": "run_command", "input": {"command": payload}}])
if user_text.startswith("/write "):
payload = user_text[len("/write ") :]
target_path, separator, content = payload.partition("::")
if not separator:
return AgentStep(type="assistant", content="Usage: /write <path>::<content>")
return AgentStep(
type="tool_calls",
calls=[{"id": tool_id, "toolName": "write_file", "input": {"path": target_path.strip(), "content": content}}],
)
if user_text.startswith("/edit "):
payload = user_text[len("/edit ") :]
parts = payload.split("::")
if len(parts) != 3:
return AgentStep(type="assistant", content="Usage: /edit <path>::<search>::<replace>")
target_path, search, replace = parts
return AgentStep(
type="tool_calls",
calls=[{"id": tool_id, "toolName": "edit_file", "input": {"path": target_path.strip(), "search": search, "replace": replace}}],
)
if user_text.startswith("/patch "):
payload = user_text[len("/patch ") :]
parts = payload.split("::")
if len(parts) < 3 or len(parts) % 2 == 0:
return AgentStep(type="assistant", content="Usage: /patch <path>::<search1>::<replace1>::<search2>::<replace2> ...")
target_path, *ops = parts
replacements = []
for index in range(0, len(ops), 2):
replacements.append({"search": ops[index], "replace": ops[index + 1]})
return AgentStep(
type="tool_calls",
calls=[{"id": tool_id, "toolName": "patch_file", "input": {"path": target_path.strip(), "replacements": replacements}}],
)
return AgentStep(
type="assistant",
content="\n".join(
[
"This is a minimal MiniCode Python shell.",
"You can try:",
"/tools",
"/ls",
"/grep pattern::src",
"/read README.md",
"/cmd pwd",
"/write notes.txt::hello",
"/edit notes.txt::hello::hello world",
]
),
)
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yyyac/MiniCode-Python.git
git@gitee.com:yyyac/MiniCode-Python.git
yyyac
MiniCode-Python
MiniCode-Python
main
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /