猿问

Botframework V4:Python Cosmos DB 配置

我目前正在尝试使用 CosmosDB 作为状态存储,但是当机器人尝试在 CosmosDB 中保存状态时遇到了一些问题。


下面是我使用 CosmosDB 作为中间件的代码


LOOP = asyncio.get_event_loop()

APP = Flask(__name__)

APP.config.update(VaultConfig.get_config())

APP.wsgi_app = BotTelemetryMiddleware(APP.wsgi_app)

PORT = APP.config["Settings"]["Port"]

INSTRUMENTATION_KEY = APP.config['Settings']["appinsight_instrumentation_key"]

TELEMETRY_CLIENT = ApplicationInsightsTelemetryClient(INSTRUMENTATION_KEY)

SETTINGS = BotFrameworkAdapterSettings(

    APP.config["Settings"]["AppId"], APP.config["Settings"]["AppPassword"]

)


cosmos_config = APP.config['COSMOS']

# Create CosmosStorage and ConversationState

cosmos = CosmosDbStorage(CosmosDbConfig(endpoint=cosmos_config['endpoint'], masterkey=cosmos_config['masterKey'],

                                         database=cosmos_config['database'], container=cosmos_config['container'], partition_key='/id'))

# Create MemoryStorage, UserState and ConversationState



USER_STATE = UserState(cosmos)

CONVERSATION_STATE = ConversationState(cosmos)

ADAPTER = BotFrameworkAdapter(SETTINGS)

ADAPTER.on_turn_error = on_error

我收到的错误:


Traceback (most recent call last):

  File "/bot/venv/lib/python3.7/site-packages/botbuilder/core/bot_adapter.py", line 95, in run_pipeline

    context, callback

  File "/bot/venv/lib/python3.7/site-packages/botbuilder/core/middleware_set.py", line 69, in receive_activity_with_status

    return await self.receive_activity_internal(context, callback)

  File "/bot/venv/lib/python3.7/site-packages/botbuilder/core/middleware_set.py", line 79, in receive_activity_internal

    return await callback(context)

  File "/bot/main.py", line 146, in aux_func

    await BOT.on_turn(turn_context)

  File "/bot/bots/dialog_bot.py", line 46, in on_turn

    await self.conversation_state.save_changes(turn_context, False)

尝试修改此文件 /bot/venv/lib/python3.7/site-packages/botbuilder/azure/cosmosdb_storage.py 以获取临时补丁似乎让我陷入了一个兔子洞,这使得 CosmosDB 似乎没有完全实现/经测试可以使用。我这样做对吗?


当前没有可使用的样本。


明月笑刀无情
浏览 100回答 1
1回答

慕哥9229398

CosmosDB 已通过以下提交修复:https ://github.com/microsoft/botbuilder-python/commit/843edfc1f4c563d58ba639b23f2bb019bdbc381b
随时随地看视频慕课网APP

相关分类

Python
我要回答