配置指南
TxCodeClient 构造参数
TxCodeClient(
api_key: str,
base_url: str = "https://api.openai.com/v1",
model: str = "gpt-4",
agent_type: AgentType = "code",
tools: list[Tool] | None = None,
max_context_tokens: int = 150_000,
max_iterations: int = 50,
system_prompt: str | None = None,
work_dir: str | None = None,
log_enabled: bool = False,
)
配置项详解
api_key(必填)
LLM API 的认证密钥。
client = TxCodeClient(api_key="sk-xxx")
base_url
API 端点地址,默认 https://api.openai.com/v1。
# DeepSeek
client = TxCodeClient(api_key="sk-xxx", base_url="https://api.deepseek.com/v1")
# 本地模型
client = TxCodeClient(api_key="not-needed", base_url="http://localhost:11434/v1")
model
| 模型 | 说明 |
|---|---|
gpt-4 | OpenAI GPT-4 |
gpt-4o | OpenAI GPT-4o(多模态) |
gpt-3.5-turbo | OpenAI GPT-3.5 |
deepseek-chat | DeepSeek V3 |
deepseek-reasoner | DeepSeek R1 |
agent_type
| 值 | 说明 |
|---|---|
"code" | 代码生成与修改 |
"chat" | 对话交流 |
"common" | 通用任务 |
"task" | 任务规划与分解 |
result = await client.chat("帮我分析...", agent_type="task")
tools
自定义工具列表。
from txcode_sdk import Tool
from txcode_sdk.types import ToolResult
def my_execute(params, ctx):
return ToolResult(success=True, output="Done")
my_tool = Tool(name="my_tool", description="My custom tool",
parameters={"type": "object", "properties": {}}, execute=my_execute)
client = TxCodeClient(api_key="sk-xxx", tools=[my_tool])
max_context_tokens
上下文 Token 上限,默认 150_000。超过时触发自动上下文压缩。
max_iterations
最大迭代次数,默认 50。
system_prompt
client = TxCodeClient(api_key="sk-xxx",
system_prompt="你是一个 Python 代码审查专家。")
work_dir
工作目录,影响相对路径解析和会话存储位置。
log_enabled
启用后日志写入 {work_dir}/.txcode/log/txcode_access.log。