migrate-honcho
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseHoncho Python SDK Migration (v1.6.0 → v2.0.0)
Honcho Python SDK 迁移指南(v1.6.0 → v2.0.0)
Overview
概述
This skill migrates code from Python SDK v1.6.0 to v2.0.0 (required for Honcho 3.0.0+).
honchoKey breaking changes:
- /
AsyncHoncho/AsyncPeerremoved → useAsyncSessionaccessor.aio - "Observation" → "Conclusion" terminology
- class removed (returns
Representationnow)str - /
get_config→set_config/get_configurationset_configuration - Streaming via instead of
chat_stream()chat(stream=True) - removed
poll_deriver_status() - property removed
.core
本技能可将 Python SDK从v1.6.0版本迁移至v2.0.0版本(Honcho 3.0.0+版本要求使用该SDK版本)。
honcho主要破坏性变更:
- /
AsyncHoncho/AsyncPeer已移除 → 使用AsyncSession访问器.aio - "Observation" 术语替换为 "Conclusion"
- 类已移除(现在返回
Representation类型)str - /
get_config替换为set_config/get_configurationset_configuration - 通过实现流式传输,替代
chat_stream()chat(stream=True) - 已移除
poll_deriver_status() - 属性已移除
.core
Quick Migration
快速迁移步骤
1. Update async architecture
1. 更新异步架构
python
undefinedpython
undefinedBefore
旧代码
from honcho import AsyncHoncho, AsyncPeer, AsyncSession
async_client = AsyncHoncho()
peer = await async_client.peer("user-123")
response = await peer.chat("query")
from honcho import AsyncHoncho, AsyncPeer, AsyncSession
async_client = AsyncHoncho()
peer = await async_client.peer("user-123")
response = await peer.chat("query")
After
新代码
from honcho import Honcho
client = Honcho()
peer = await client.aio.peer("user-123")
response = await peer.aio.chat("query")
from honcho import Honcho
client = Honcho()
peer = await client.aio.peer("user-123")
response = await peer.aio.chat("query")
Async iteration
异步迭代
async for p in client.aio.peers():
print(p.id)
undefinedasync for p in client.aio.peers():
print(p.id)
undefined2. Replace observations with conclusions
2. 替换Observations为Conclusions
python
undefinedpython
undefinedBefore
旧代码
from honcho import Observation, ObservationScope, AsyncObservationScope
scope = peer.observations
scope = peer.observations_of("other-peer")
rep = scope.get_representation()
from honcho import Observation, ObservationScope, AsyncObservationScope
scope = peer.observations
scope = peer.observations_of("other-peer")
rep = scope.get_representation()
After
新代码
from honcho import Conclusion, ConclusionScope, ConclusionScopeAio
scope = peer.conclusions
scope = peer.conclusions_of("other-peer")
rep = scope.representation() # Returns str
undefinedfrom honcho import Conclusion, ConclusionScope, ConclusionScopeAio
scope = peer.conclusions
scope = peer.conclusions_of("other-peer")
rep = scope.representation() # 返回str类型
undefined3. Update representation handling
3. 更新Representation处理逻辑
python
undefinedpython
undefinedBefore
旧代码
from honcho import Representation, ExplicitObservation, DeductiveObservation
rep: Representation = peer.working_rep()
print(rep.explicit)
print(rep.deductive)
if rep.is_empty():
print("No observations")
from honcho import Representation, ExplicitObservation, DeductiveObservation
rep: Representation = peer.working_rep()
print(rep.explicit)
print(rep.deductive)
if rep.is_empty():
print("无观测数据")
After
新代码
rep: str = peer.representation()
print(rep) # Just a string now
if not rep:
print("No conclusions")
undefinedrep: str = peer.representation()
print(rep) # 现在仅返回字符串
if not rep:
print("无结论数据")
undefined4. Rename configuration methods
4. 重命名配置方法
python
undefinedpython
undefinedBefore
旧代码
config = peer.get_config()
peer.set_config({"observe_me": False})
session.get_config()
client.get_config()
config = peer.get_config()
peer.set_config({"observe_me": False})
session.get_config()
client.get_config()
After
新代码
from honcho.api_types import PeerConfig, SessionConfiguration, WorkspaceConfiguration
config = peer.get_configuration()
peer.set_configuration(PeerConfig(observe_me=False))
session.get_configuration()
client.get_configuration()
undefinedfrom honcho.api_types import PeerConfig, SessionConfiguration, WorkspaceConfiguration
config = peer.get_configuration()
peer.set_configuration(PeerConfig(observe_me=False))
session.get_configuration()
client.get_configuration()
undefined5. Update method names
5. 更新方法名称
python
undefinedpython
undefinedBefore
旧代码
peer.working_rep()
peer.get_context()
peer.get_sessions()
session.get_context()
session.get_summaries()
session.get_messages()
session.get_peers()
session.get_peer_config()
client.get_peers()
client.get_sessions()
client.get_workspaces()
peer.working_rep()
peer.get_context()
peer.get_sessions()
session.get_context()
session.get_summaries()
session.get_messages()
session.get_peers()
session.get_peer_config()
client.get_peers()
client.get_sessions()
client.get_workspaces()
After
新代码
peer.representation()
peer.context()
peer.sessions()
session.context()
session.summaries()
session.messages()
session.peers()
session.get_peer_configuration()
client.peers()
client.sessions()
client.workspaces()
undefinedpeer.representation()
peer.context()
peer.sessions()
session.context()
session.summaries()
session.messages()
session.peers()
session.get_peer_configuration()
client.peers()
client.sessions()
client.workspaces()
undefined6. Update streaming
6. 更新流式传输逻辑
python
undefinedpython
undefinedBefore
旧代码
response = peer.chat("query", stream=True)
for chunk in response:
print(chunk, end="")
response = peer.chat("query", stream=True)
for chunk in response:
print(chunk, end="")
After
新代码
stream = peer.chat_stream("query")
for chunk in stream:
print(chunk, end="")
undefinedstream = peer.chat_stream("query")
for chunk in stream:
print(chunk, end="")
undefined7. Update queue status (formerly deriver)
7. 更新队列状态(原Deriver状态)
python
undefinedpython
undefinedBefore
旧代码
from honcho_core.types import DeriverStatus
status = client.get_deriver_status()
status = client.poll_deriver_status(timeout=300.0) # Removed!
from honcho_core.types import DeriverStatus
status = client.get_deriver_status()
status = client.poll_deriver_status(timeout=300.0) # 已移除!
After
新代码
from honcho.api_types import QueueStatusResponse
status = client.queue_status()
from honcho.api_types import QueueStatusResponse
status = client.queue_status()
poll_deriver_status removed - implement polling manually if needed
poll_deriver_status已移除 - 如需轮询请自行实现
undefinedundefined8. Update representation parameters
8. 更新Representation参数
python
undefinedpython
undefinedBefore
旧代码
rep = peer.working_rep(
include_most_derived=True,
max_observations=50
)
rep = peer.working_rep(
include_most_derived=True,
max_observations=50
)
After
新代码
rep = peer.representation(
include_most_frequent=True,
max_conclusions=50
)
undefinedrep = peer.representation(
include_most_frequent=True,
max_conclusions=50
)
undefined9. Move update_message to session
9. 将update_message方法迁移至Session
python
undefinedpython
undefinedBefore
旧代码
updated = client.update_message(message=msg, metadata={"key": "value"}, session="sess-id")
updated = client.update_message(message=msg, metadata={"key": "value"}, session="sess-id")
After
新代码
updated = session.update_message(message=msg, metadata={"key": "value"})
undefinedupdated = session.update_message(message=msg, metadata={"key": "value"})
undefined10. Update card() return type
10. 更新card()返回类型
python
undefinedpython
undefinedBefore
旧代码
card: str = peer.card() # Returns str
card: str = peer.card() # 返回str类型
After
新代码
card: list[str] | None = peer.card() # Returns list[str] | None
if card:
print("\n".join(card))
undefinedcard: list[str] | None = peer.card() # 返回list[str] | None类型
if card:
print("\n".join(card))
undefinedQuick Reference Table
快速参考对照表
| v1.6.0 | v2.0.0 |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| (removed) |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| (removed) |
| v1.6.0 | v2.0.0 |
|---|---|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| (已移除) |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| (已移除) |
Detailed Reference
详细参考
For comprehensive details on each change, see:
- DETAILED-CHANGES.md - Full API change documentation
- MIGRATION-CHECKLIST.md - Step-by-step checklist
如需了解每个变更的完整细节,请查看:
- DETAILED-CHANGES.md - 完整API变更文档
- MIGRATION-CHECKLIST.md - 分步迁移清单
New Exception Types
新异常类型
python
from honcho import (
HonchoError,
APIError,
BadRequestError,
AuthenticationError,
PermissionDeniedError,
NotFoundError,
ConflictError,
UnprocessableEntityError,
RateLimitError,
ServerError,
TimeoutError,
ConnectionError,
)python
from honcho import (
HonchoError,
APIError,
BadRequestError,
AuthenticationError,
PermissionDeniedError,
NotFoundError,
ConflictError,
UnprocessableEntityError,
RateLimitError,
ServerError,
TimeoutError,
ConnectionError,
)New Import Locations
新导入路径
python
undefinedpython
undefinedConfiguration types
配置类型
from honcho.api_types import (
PeerConfig,
SessionConfiguration,
WorkspaceConfiguration,
SessionPeerConfig,
QueueStatusResponse,
PeerContextResponse,
)
from honcho.api_types import (
PeerConfig,
SessionConfiguration,
WorkspaceConfiguration,
SessionPeerConfig,
QueueStatusResponse,
PeerContextResponse,
)
Async type hints
异步类型提示
from honcho import HonchoAio, PeerAio, SessionAio
from honcho import HonchoAio, PeerAio, SessionAio
Message types (note: Params is plural now)
消息类型(注意:Params现在为复数形式)
from honcho import Message, MessageCreateParams
undefinedfrom honcho import Message, MessageCreateParams
undefined