txcode-sdk 0.6.0__tar.gz → 0.7.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.
- {txcode_sdk-0.6.0/src/txcode_sdk.egg-info → txcode_sdk-0.7.0}/PKG-INFO +1 -1
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/pyproject.toml +1 -1
- txcode_sdk-0.6.0/src/txcode_sdk/provider/openai_provider.py → txcode_sdk-0.7.0/src/txcode_sdk/provider/base.py +159 -225
- txcode_sdk-0.7.0/src/txcode_sdk/provider/deepseek_provider.py +121 -0
- txcode_sdk-0.7.0/src/txcode_sdk/provider/openai_provider.py +94 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0/src/txcode_sdk.egg-info}/PKG-INFO +1 -1
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk.egg-info/SOURCES.txt +1 -0
- txcode_sdk-0.7.0/tests/test_deepseek_provider.py +161 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_provider_model.py +4 -6
- txcode_sdk-0.6.0/src/txcode_sdk/provider/base.py +0 -38
- txcode_sdk-0.6.0/src/txcode_sdk/provider/deepseek_provider.py +0 -13
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/LICENSE +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/README.md +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/setup.cfg +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/setup.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/example/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/example/code_example.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/example/code_session.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/example/code_tool.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/example/constants.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/example/query_session.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/example/ws_server.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/_compat/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/_compat/dataclasses.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/_compat/resources.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/base_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/chat/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/chat/agent_tool.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/chat/chat_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/chat/prompts/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/chat/prompts/role.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/code/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/code/agent_tool.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/code/code_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/code/prompts/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/code/prompts/role.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/common/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/common/common_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/common/prompt/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/common/prompt/role.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/design/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/design/agent_tool.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/design/design_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/design/prompts/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/design/prompts/role.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/discuss/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/discuss/agent_tool.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/discuss/discuss_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/discuss/prompts/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/discuss/prompts/role.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/dream/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/dream/agent_tool.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/dream/dream_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/dream/prompts/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/dream/prompts/role.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/mem/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/mem/agent_tool.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/mem/mem_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/mem/prompts/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/mem/prompts/role.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/name/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/name/name_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/name/prompts/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/name/prompts/role.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/plan/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/plan/agent_tool.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/plan/plan_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/plan/prompts/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/plan/prompts/role.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/shell/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/shell/agent_tool.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/shell/prompts/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/shell/prompts/role.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/shell/shell_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/skill/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/skill/agent_tool.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/skill/prompts/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/skill/prompts/role.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/skill/skill_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/summarizer/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/summarizer/prompts/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/summarizer/prompts/role.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/summarizer/summarizer_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/task/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/task/agent_tool.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/task/prompts/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/task/prompts/role.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/task/task_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/test/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/test/agent_tool.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/test/prompts/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/test/prompts/role.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/test/test_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/agent/tool_registry.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/client.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/compact/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/compact/compressor.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/hooks/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/hooks/handlers/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/hooks/handlers/base.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/hooks/handlers/memory.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/hooks/processor.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/hooks/queue.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/hooks/types.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/provider/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/provider/router.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/provider/txcode_ai.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/server/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/server/__main__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/server/config_store.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/server/handler.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/server/http.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/server/hub_client.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/server/json_store.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/server/plan_code.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/server/project_manager.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/server/provider_config.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/server/server.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/server/skill_manager.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/server/spec_manager.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/server/websocket.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/server/zip_utils.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/session/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/session/manager.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/skills/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/specs/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/tools/__init__.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/tools/bash.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/tools/bash_tool.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/tools/edit_file.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/tools/edit_file.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/tools/glob.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/tools/glob_tool.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/tools/grep.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/tools/grep_tool.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/tools/memory_tool.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/tools/read_file.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/tools/read_file.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/tools/todo_read.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/tools/todo_read.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/tools/todo_write.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/tools/todo_write.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/tools/web_shell_exec.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/tools/web_shell_exec.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/tools/write_file.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/tools/write_file.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk/types.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk.egg-info/dependency_links.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk.egg-info/entry_points.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/src/txcode_sdk.egg-info/top_level.txt +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_cli.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_client.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_compat.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_design_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_discuss_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_dream_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_http_api.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_http_ext_api.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_json_store.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_name_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_plan_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_project_manager.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_provider_config.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_session.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_session_query.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_shell_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_skill_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_test_agent.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_tools.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_txcode_ai.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_websocket_protocol.py +0 -0
- {txcode_sdk-0.6.0 → txcode_sdk-0.7.0}/tests/test_ws_server.py +0 -0
|
@@ -1,225 +1,159 @@
|
|
|
1
|
-
"""
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
from
|
|
11
|
-
from
|
|
12
|
-
from
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
def
|
|
56
|
-
""
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
formatted["content"] = content
|
|
161
|
-
|
|
162
|
-
if msg.name:
|
|
163
|
-
formatted["name"] = msg.name
|
|
164
|
-
if msg.tool_call_id:
|
|
165
|
-
formatted["tool_call_id"] = msg.tool_call_id
|
|
166
|
-
if msg.tool_calls:
|
|
167
|
-
formatted["tool_calls"] = msg.tool_calls
|
|
168
|
-
if msg.reasoning_content:
|
|
169
|
-
formatted["reasoning_content"] = msg.reasoning_content
|
|
170
|
-
return formatted
|
|
171
|
-
|
|
172
|
-
async def _resolve_content_images(self, content: Union[str, list]) -> Union[str, list]:
|
|
173
|
-
if isinstance(content, str):
|
|
174
|
-
return content
|
|
175
|
-
resolved: list = []
|
|
176
|
-
for c in content:
|
|
177
|
-
if isinstance(c, ImageContent):
|
|
178
|
-
resolved.append(ImageContent(url=_resolve_image_url(c.image_url["url"])).to_dict())
|
|
179
|
-
elif hasattr(c, "to_dict"):
|
|
180
|
-
resolved.append(c.to_dict())
|
|
181
|
-
else:
|
|
182
|
-
resolved.append(c)
|
|
183
|
-
return resolved
|
|
184
|
-
|
|
185
|
-
def _parse_response(self, response: dict) -> ProviderResponse:
|
|
186
|
-
choices = response.get("choices") or []
|
|
187
|
-
if not choices:
|
|
188
|
-
raise RuntimeError("Invalid response: no choices")
|
|
189
|
-
choice = choices[0]
|
|
190
|
-
msg = choice.get("message") or {}
|
|
191
|
-
|
|
192
|
-
usage = None
|
|
193
|
-
usage_data = response.get("usage")
|
|
194
|
-
if usage_data:
|
|
195
|
-
usage = TokenUsage(
|
|
196
|
-
prompt_tokens=usage_data.get("prompt_tokens", 0),
|
|
197
|
-
completion_tokens=usage_data.get("completion_tokens", 0),
|
|
198
|
-
total_tokens=usage_data.get("total_tokens", 0),
|
|
199
|
-
)
|
|
200
|
-
|
|
201
|
-
result = ProviderResponse(
|
|
202
|
-
content=msg.get("content") or "",
|
|
203
|
-
finish_reason=choice.get("finish_reason") or "stop",
|
|
204
|
-
usage=usage,
|
|
205
|
-
)
|
|
206
|
-
|
|
207
|
-
reasoning = msg.get("reasoning_content") or response.get("reasoning")
|
|
208
|
-
if reasoning:
|
|
209
|
-
result.reasoning = reasoning
|
|
210
|
-
|
|
211
|
-
tool_calls = msg.get("tool_calls")
|
|
212
|
-
if tool_calls:
|
|
213
|
-
result.tool_calls = [
|
|
214
|
-
{
|
|
215
|
-
"id": tc.get("id", ""),
|
|
216
|
-
"type": tc.get("type", "function"),
|
|
217
|
-
"function": {
|
|
218
|
-
"name": (tc.get("function") or {}).get("name", ""),
|
|
219
|
-
"arguments": (tc.get("function") or {}).get("arguments", ""),
|
|
220
|
-
},
|
|
221
|
-
}
|
|
222
|
-
for tc in tool_calls
|
|
223
|
-
]
|
|
224
|
-
|
|
225
|
-
return result
|
|
1
|
+
"""BaseProvider 抽象基类(ReAct 循环的 Provider 接口 + 公共实现)。
|
|
2
|
+
|
|
3
|
+
公共能力(get_model/set_model/get_base_url/日志/消息格式化/响应解析)在此实现,
|
|
4
|
+
OpenAIProvider 与 DeepSeekProvider 等具体 Provider 继承本类,仅保留各自的请求差异。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import base64
|
|
8
|
+
import json
|
|
9
|
+
import mimetypes
|
|
10
|
+
from abc import ABC, abstractmethod
|
|
11
|
+
from datetime import datetime, timezone
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from typing import Any, AsyncGenerator, Dict, List, Optional, Union
|
|
14
|
+
|
|
15
|
+
from ..types import ChatMessage, ImageContent, ProviderResponse, TokenUsage
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _resolve_image_url(url: str) -> str:
|
|
19
|
+
if url.startswith("data:"):
|
|
20
|
+
return url
|
|
21
|
+
path = Path(url)
|
|
22
|
+
if path.is_file():
|
|
23
|
+
mime_type, _ = mimetypes.guess_type(str(path))
|
|
24
|
+
mime_type = mime_type or "image/png"
|
|
25
|
+
with open(path, "rb") as f:
|
|
26
|
+
b64 = base64.b64encode(f.read()).decode("utf-8")
|
|
27
|
+
return f"data:{mime_type};base64,{b64}"
|
|
28
|
+
return url
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class BaseProvider(ABC):
|
|
32
|
+
def __init__(self, base_url: str = "", model: str = ""):
|
|
33
|
+
self._base_url = base_url
|
|
34
|
+
self._model = model
|
|
35
|
+
|
|
36
|
+
@abstractmethod
|
|
37
|
+
async def chat(
|
|
38
|
+
self,
|
|
39
|
+
messages: List[ChatMessage],
|
|
40
|
+
tools: Optional[List[dict]] = None,
|
|
41
|
+
abort_signal: Any = None,
|
|
42
|
+
log_context: Optional[dict] = None,
|
|
43
|
+
) -> ProviderResponse:
|
|
44
|
+
...
|
|
45
|
+
|
|
46
|
+
@abstractmethod
|
|
47
|
+
async def chat_stream(
|
|
48
|
+
self,
|
|
49
|
+
messages: List[ChatMessage],
|
|
50
|
+
tools: Optional[List[dict]] = None,
|
|
51
|
+
abort_signal: Any = None,
|
|
52
|
+
) -> AsyncGenerator[str, None]:
|
|
53
|
+
...
|
|
54
|
+
|
|
55
|
+
def get_model(self) -> str:
|
|
56
|
+
return getattr(self, "_model", "")
|
|
57
|
+
|
|
58
|
+
def get_base_url(self) -> str:
|
|
59
|
+
return getattr(self, "_base_url", "")
|
|
60
|
+
|
|
61
|
+
def set_model(self, model: str):
|
|
62
|
+
"""运行期切换模型(base_url/api_key 不变,子类公共实现)。"""
|
|
63
|
+
self._model = model
|
|
64
|
+
|
|
65
|
+
def _write_log(self, log_context: dict, event: str, extra: dict):
|
|
66
|
+
work_dir = log_context.get("work_dir", ".")
|
|
67
|
+
log_dir = Path(work_dir) / ".txcode" / "log"
|
|
68
|
+
log_dir.mkdir(parents=True, exist_ok=True)
|
|
69
|
+
entry = {
|
|
70
|
+
"timestamp": datetime.now(timezone.utc).isoformat(),
|
|
71
|
+
"session_id": log_context.get("session_id", ""),
|
|
72
|
+
"agent_type": log_context.get("agent_type", ""),
|
|
73
|
+
"iteration": log_context.get("iteration", 0),
|
|
74
|
+
"event": event,
|
|
75
|
+
**extra,
|
|
76
|
+
}
|
|
77
|
+
with open(log_dir / "txcode_access.log", "a", encoding="utf-8") as f:
|
|
78
|
+
f.write(json.dumps(entry, ensure_ascii=False, indent=2) + "\n")
|
|
79
|
+
|
|
80
|
+
async def _resolve_messages(self, messages: List[ChatMessage]) -> List[dict]:
|
|
81
|
+
resolved: List[dict] = []
|
|
82
|
+
for msg in messages:
|
|
83
|
+
formatted = self._format_message(msg)
|
|
84
|
+
formatted["content"] = await self._resolve_content_images(msg.content)
|
|
85
|
+
resolved.append(formatted)
|
|
86
|
+
return resolved
|
|
87
|
+
|
|
88
|
+
def _format_message(self, msg: ChatMessage) -> dict:
|
|
89
|
+
formatted: dict = {"role": msg.role}
|
|
90
|
+
content = msg.content
|
|
91
|
+
if isinstance(content, list):
|
|
92
|
+
formatted["content"] = [c.to_dict() if hasattr(c, "to_dict") else c for c in content]
|
|
93
|
+
else:
|
|
94
|
+
formatted["content"] = content
|
|
95
|
+
|
|
96
|
+
if msg.name:
|
|
97
|
+
formatted["name"] = msg.name
|
|
98
|
+
if msg.tool_call_id:
|
|
99
|
+
formatted["tool_call_id"] = msg.tool_call_id
|
|
100
|
+
if msg.tool_calls:
|
|
101
|
+
formatted["tool_calls"] = msg.tool_calls
|
|
102
|
+
if msg.reasoning_content:
|
|
103
|
+
formatted["reasoning_content"] = msg.reasoning_content
|
|
104
|
+
return formatted
|
|
105
|
+
|
|
106
|
+
async def _resolve_content_images(self, content: Union[str, list]) -> Union[str, list]:
|
|
107
|
+
if isinstance(content, str):
|
|
108
|
+
return content
|
|
109
|
+
resolved: list = []
|
|
110
|
+
for c in content:
|
|
111
|
+
if isinstance(c, ImageContent):
|
|
112
|
+
resolved.append(ImageContent(url=_resolve_image_url(c.image_url["url"])).to_dict())
|
|
113
|
+
elif hasattr(c, "to_dict"):
|
|
114
|
+
resolved.append(c.to_dict())
|
|
115
|
+
else:
|
|
116
|
+
resolved.append(c)
|
|
117
|
+
return resolved
|
|
118
|
+
|
|
119
|
+
def _parse_response(self, response: dict) -> ProviderResponse:
|
|
120
|
+
choices = response.get("choices") or []
|
|
121
|
+
if not choices:
|
|
122
|
+
raise RuntimeError("Invalid response: no choices")
|
|
123
|
+
choice = choices[0]
|
|
124
|
+
msg = choice.get("message") or {}
|
|
125
|
+
|
|
126
|
+
usage = None
|
|
127
|
+
usage_data = response.get("usage")
|
|
128
|
+
if usage_data:
|
|
129
|
+
usage = TokenUsage(
|
|
130
|
+
prompt_tokens=usage_data.get("prompt_tokens", 0),
|
|
131
|
+
completion_tokens=usage_data.get("completion_tokens", 0),
|
|
132
|
+
total_tokens=usage_data.get("total_tokens", 0),
|
|
133
|
+
)
|
|
134
|
+
|
|
135
|
+
result = ProviderResponse(
|
|
136
|
+
content=msg.get("content") or "",
|
|
137
|
+
finish_reason=choice.get("finish_reason") or "stop",
|
|
138
|
+
usage=usage,
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
reasoning = msg.get("reasoning_content") or response.get("reasoning")
|
|
142
|
+
if reasoning:
|
|
143
|
+
result.reasoning = reasoning
|
|
144
|
+
|
|
145
|
+
tool_calls = msg.get("tool_calls")
|
|
146
|
+
if tool_calls:
|
|
147
|
+
result.tool_calls = [
|
|
148
|
+
{
|
|
149
|
+
"id": tc.get("id", ""),
|
|
150
|
+
"type": tc.get("type", "function"),
|
|
151
|
+
"function": {
|
|
152
|
+
"name": (tc.get("function") or {}).get("name", ""),
|
|
153
|
+
"arguments": (tc.get("function") or {}).get("arguments", ""),
|
|
154
|
+
},
|
|
155
|
+
}
|
|
156
|
+
for tc in tool_calls
|
|
157
|
+
]
|
|
158
|
+
|
|
159
|
+
return result
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"""DeepSeek Provider:对齐 TS 端 deepseek.provider.ts 行为,直接继承 BaseProvider。
|
|
2
|
+
|
|
3
|
+
- chat:开启思考模式(thinking.enabled + reasoning_effort: max),默认 max_tokens 65536
|
|
4
|
+
- chat_stream:关闭思考模式(thinking.disabled),默认 max_tokens 2000
|
|
5
|
+
- assistant 消息无 reasoning_content 时补 "null" 占位,规避 DeepSeek API 校验错误
|
|
6
|
+
- reasoning 提取优先级:msg.reasoning_content → msg.reasoning → response.reasoning → msg.content
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from typing import Any, AsyncGenerator, Dict, List, Optional
|
|
10
|
+
|
|
11
|
+
from ..types import ChatMessage, ProviderResponse
|
|
12
|
+
from .base import BaseProvider
|
|
13
|
+
from .txcode_ai import TxCodeAI
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class DeepSeekProvider(BaseProvider):
|
|
17
|
+
def __init__(
|
|
18
|
+
self,
|
|
19
|
+
api_key: str,
|
|
20
|
+
base_url: str = "https://api.deepseek.com/v1",
|
|
21
|
+
model: str = "deepseek-chat",
|
|
22
|
+
):
|
|
23
|
+
super().__init__(base_url=base_url, model=model)
|
|
24
|
+
self._client = TxCodeAI(
|
|
25
|
+
api_key=api_key,
|
|
26
|
+
base_url=base_url,
|
|
27
|
+
default_headers={
|
|
28
|
+
"HTTP-Referer": "https://www.homecommunity.cn",
|
|
29
|
+
"X-Title": "txcode",
|
|
30
|
+
},
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
async def chat(
|
|
34
|
+
self,
|
|
35
|
+
messages: List[ChatMessage],
|
|
36
|
+
tools: Optional[List[dict]] = None,
|
|
37
|
+
abort_signal: Any = None,
|
|
38
|
+
log_context: Optional[dict] = None,
|
|
39
|
+
) -> ProviderResponse:
|
|
40
|
+
resolved = await self._resolve_messages(messages)
|
|
41
|
+
kwargs: Dict[str, Any] = {
|
|
42
|
+
"model": self._model,
|
|
43
|
+
"messages": resolved,
|
|
44
|
+
"max_tokens": 65536,
|
|
45
|
+
"thinking": {"type": "enabled"},
|
|
46
|
+
"reasoning_effort": "max",
|
|
47
|
+
}
|
|
48
|
+
if tools:
|
|
49
|
+
kwargs["tools"] = tools
|
|
50
|
+
kwargs["tool_choice"] = "auto"
|
|
51
|
+
|
|
52
|
+
if log_context:
|
|
53
|
+
self._write_log(log_context, "request", {
|
|
54
|
+
"model": self._model,
|
|
55
|
+
"messages": resolved,
|
|
56
|
+
"tools": tools or [],
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
response = await self._client.chat_completions(**kwargs)
|
|
60
|
+
parsed = self._parse_response(response)
|
|
61
|
+
|
|
62
|
+
if log_context:
|
|
63
|
+
self._write_log(log_context, "response", {
|
|
64
|
+
"model": self._model,
|
|
65
|
+
"finish_reason": parsed.finish_reason,
|
|
66
|
+
"content": parsed.content or "",
|
|
67
|
+
"tool_calls": parsed.tool_calls or [],
|
|
68
|
+
"usage": {
|
|
69
|
+
"prompt_tokens": parsed.usage.prompt_tokens,
|
|
70
|
+
"completion_tokens": parsed.usage.completion_tokens,
|
|
71
|
+
"total_tokens": parsed.usage.total_tokens,
|
|
72
|
+
} if parsed.usage else None,
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
return parsed
|
|
76
|
+
|
|
77
|
+
async def chat_stream(
|
|
78
|
+
self,
|
|
79
|
+
messages: List[ChatMessage],
|
|
80
|
+
tools: Optional[List[dict]] = None,
|
|
81
|
+
abort_signal: Any = None,
|
|
82
|
+
) -> AsyncGenerator[str, None]:
|
|
83
|
+
resolved = await self._resolve_messages(messages)
|
|
84
|
+
kwargs: Dict[str, Any] = {
|
|
85
|
+
"model": self._model,
|
|
86
|
+
"messages": resolved,
|
|
87
|
+
"max_tokens": 2000,
|
|
88
|
+
"stream": True,
|
|
89
|
+
"thinking": {"type": "disabled"},
|
|
90
|
+
}
|
|
91
|
+
if tools:
|
|
92
|
+
kwargs["tools"] = tools
|
|
93
|
+
|
|
94
|
+
async for chunk in self._client.chat_completions_stream(**kwargs):
|
|
95
|
+
choices = chunk.get("choices") or []
|
|
96
|
+
if not choices:
|
|
97
|
+
continue
|
|
98
|
+
delta = choices[0].get("delta") or {}
|
|
99
|
+
content = delta.get("content")
|
|
100
|
+
if content:
|
|
101
|
+
yield content
|
|
102
|
+
|
|
103
|
+
def _format_message(self, msg: ChatMessage) -> dict:
|
|
104
|
+
formatted = super()._format_message(msg)
|
|
105
|
+
if msg.role == "assistant" and not formatted.get("reasoning_content"):
|
|
106
|
+
formatted["reasoning_content"] = "null"
|
|
107
|
+
return formatted
|
|
108
|
+
|
|
109
|
+
def _parse_response(self, response: dict) -> ProviderResponse:
|
|
110
|
+
result = super()._parse_response(response)
|
|
111
|
+
choice = (response.get("choices") or [{}])[0]
|
|
112
|
+
msg = choice.get("message") or {}
|
|
113
|
+
reasoning = (
|
|
114
|
+
msg.get("reasoning_content")
|
|
115
|
+
or msg.get("reasoning")
|
|
116
|
+
or response.get("reasoning")
|
|
117
|
+
or (msg.get("content") or "")
|
|
118
|
+
)
|
|
119
|
+
if reasoning:
|
|
120
|
+
result.reasoning = reasoning
|
|
121
|
+
return result
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"""OpenAI Provider:基于自研 TxCodeAI(urllib)实现,零 openai SDK 依赖。"""
|
|
2
|
+
|
|
3
|
+
from typing import Any, AsyncGenerator, Dict, List, Optional
|
|
4
|
+
|
|
5
|
+
from ..types import ChatMessage, ProviderResponse
|
|
6
|
+
from .base import BaseProvider
|
|
7
|
+
from .txcode_ai import TxCodeAI
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class OpenAIProvider(BaseProvider):
|
|
11
|
+
def __init__(
|
|
12
|
+
self,
|
|
13
|
+
api_key: str,
|
|
14
|
+
base_url: str = "https://api.openai.com/v1",
|
|
15
|
+
model: str = "gpt-4",
|
|
16
|
+
):
|
|
17
|
+
super().__init__(base_url=base_url, model=model)
|
|
18
|
+
self._client = TxCodeAI(
|
|
19
|
+
api_key=api_key,
|
|
20
|
+
base_url=base_url,
|
|
21
|
+
default_headers={
|
|
22
|
+
"HTTP-Referer": "https://www.homecommunity.cn",
|
|
23
|
+
"X-Title": "txcode",
|
|
24
|
+
},
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
async def chat(
|
|
28
|
+
self,
|
|
29
|
+
messages: List[ChatMessage],
|
|
30
|
+
tools: Optional[List[dict]] = None,
|
|
31
|
+
abort_signal: Any = None,
|
|
32
|
+
log_context: Optional[dict] = None,
|
|
33
|
+
) -> ProviderResponse:
|
|
34
|
+
resolved = await self._resolve_messages(messages)
|
|
35
|
+
kwargs: Dict[str, Any] = {
|
|
36
|
+
"model": self._model,
|
|
37
|
+
"messages": resolved,
|
|
38
|
+
"temperature": 0.7,
|
|
39
|
+
"max_tokens": 65536,
|
|
40
|
+
}
|
|
41
|
+
if tools:
|
|
42
|
+
kwargs["tools"] = tools
|
|
43
|
+
kwargs["tool_choice"] = "auto"
|
|
44
|
+
|
|
45
|
+
if log_context:
|
|
46
|
+
self._write_log(log_context, "request", {
|
|
47
|
+
"model": self._model,
|
|
48
|
+
"messages": resolved,
|
|
49
|
+
"tools": tools or [],
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
response = await self._client.chat_completions(**kwargs)
|
|
53
|
+
parsed = self._parse_response(response)
|
|
54
|
+
|
|
55
|
+
if log_context:
|
|
56
|
+
self._write_log(log_context, "response", {
|
|
57
|
+
"model": self._model,
|
|
58
|
+
"finish_reason": parsed.finish_reason,
|
|
59
|
+
"content": parsed.content or "",
|
|
60
|
+
"tool_calls": parsed.tool_calls or [],
|
|
61
|
+
"usage": {
|
|
62
|
+
"prompt_tokens": parsed.usage.prompt_tokens,
|
|
63
|
+
"completion_tokens": parsed.usage.completion_tokens,
|
|
64
|
+
"total_tokens": parsed.usage.total_tokens,
|
|
65
|
+
} if parsed.usage else None,
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
return parsed
|
|
69
|
+
|
|
70
|
+
async def chat_stream(
|
|
71
|
+
self,
|
|
72
|
+
messages: List[ChatMessage],
|
|
73
|
+
tools: Optional[List[dict]] = None,
|
|
74
|
+
abort_signal: Any = None,
|
|
75
|
+
) -> AsyncGenerator[str, None]:
|
|
76
|
+
resolved = await self._resolve_messages(messages)
|
|
77
|
+
kwargs: Dict[str, Any] = {
|
|
78
|
+
"model": self._model,
|
|
79
|
+
"messages": resolved,
|
|
80
|
+
"temperature": 0.7,
|
|
81
|
+
"max_tokens": 65536,
|
|
82
|
+
"stream": True,
|
|
83
|
+
}
|
|
84
|
+
if tools:
|
|
85
|
+
kwargs["tools"] = tools
|
|
86
|
+
|
|
87
|
+
async for chunk in self._client.chat_completions_stream(**kwargs):
|
|
88
|
+
choices = chunk.get("choices") or []
|
|
89
|
+
if not choices:
|
|
90
|
+
continue
|
|
91
|
+
delta = choices[0].get("delta") or {}
|
|
92
|
+
content = delta.get("content")
|
|
93
|
+
if content:
|
|
94
|
+
yield content
|