0

我正在尝试从 Rasa-x 对我的亚马逊海王星数据库进行简单查询。

这是我的actions.py中的代码:

class ActionQueryDietary(Action):
    def name(self) -> Text:
        return "action_query_dietary"

    def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        available = False
        restaurant = "XXXX"
        dietaryQuestion=tracker.get_slot('dietaryQuestion')
        g, remoteConn = kb.openConnection()

        dietary = kb.getDietary(g, restaurant, dietaryQuestion)

        if(dietary=="Yes"):
            available = True
        
        if(available==True):
            dispatcher.utter_message(text="According to our knowledge base, {} is on the menu").format(dietaryQuestion)
        else:
            dispatcher.utter_message(text="Sorry, according to our knowledge base, we don't have this option on the menu")
        kb.closeConnection(remoteConn)
        return []

这是来自知识库.py 的代码:

def getDietary(g, restaurant, dietary):
    properties = queryRestaurantProperties(g, restaurant)
    result = properties[dietary]
    print(result)
    return result

但是对知识库的任何查询都会导致此错误:

2020-10-22T18:01:22.347345241Z   File "/opt/venv/lib/python3.7/site-packages/sanic/app.py", line 973, in handle_request
2020-10-22T18:01:22.347351643Z     response = await response
2020-10-22T18:01:22.347357446Z   File "/app/rasa_sdk/endpoint.py", line 102, in webhook
2020-10-22T18:01:22.347363522Z     result = await executor.run(action_call)
2020-10-22T18:01:22.347369398Z   File "/app/rasa_sdk/executor.py", line 392, in run
2020-10-22T18:01:22.347375473Z     events = action(dispatcher, tracker, domain)
2020-10-22T18:01:22.347381348Z   File "/app/actions/actions.py", line 33, in run
2020-10-22T18:01:22.347387063Z     dietary = kb.getDietary(g, restaurant, dietaryQuestion)
2020-10-22T18:01:22.347392835Z   File "/app/actions/knowledgebase.py", line 117, in getDietary
2020-10-22T18:01:22.347399112Z     properties = queryRestaurantProperties(g, restaurant)
2020-10-22T18:01:22.347405111Z   File "/app/actions/knowledgebase.py", line 86, in queryRestaurantProperties
2020-10-22T18:01:22.347411869Z     result = g.V().has('name', restaurant).valueMap().next()
2020-10-22T18:01:22.347418048Z   File "/opt/venv/lib/python3.7/site-packages/gremlin_python/process/traversal.py", line 89, in next
2020-10-22T18:01:22.347424293Z     return self.__next__()
2020-10-22T18:01:22.347430069Z   File "/opt/venv/lib/python3.7/site-packages/gremlin_python/process/traversal.py", line 48, in __next__
2020-10-22T18:01:22.347436333Z     self.traversal_strategies.apply_strategies(self)
2020-10-22T18:01:22.347441940Z   File "/opt/venv/lib/python3.7/site-packages/gremlin_python/process/traversal.py", line 573, in apply_strategies
2020-10-22T18:01:22.347447667Z     traversal_strategy.apply(traversal)
2020-10-22T18:01:22.347453031Z   File "/opt/venv/lib/python3.7/site-packages/gremlin_python/driver/remote_connection.py", line 149, in apply
2020-10-22T18:01:22.347459352Z     remote_traversal = self.remote_connection.submit(traversal.bytecode)
2020-10-22T18:01:22.347465069Z   File "/opt/venv/lib/python3.7/site-packages/gremlin_python/driver/driver_remote_connection.py", line 55, in submit
2020-10-22T18:01:22.347486749Z     result_set = self._client.submit(bytecode)
2020-10-22T18:01:22.347493788Z   File "/opt/venv/lib/python3.7/site-packages/gremlin_python/driver/client.py", line 127, in submit
2020-10-22T18:01:22.347499424Z     return self.submitAsync(message, bindings=bindings).result()
2020-10-22T18:01:22.347505093Z   File "/opt/venv/lib/python3.7/site-packages/gremlin_python/driver/client.py", line 146, in submitAsync
2020-10-22T18:01:22.347511092Z     return conn.write(message)
2020-10-22T18:01:22.347516610Z   File "/opt/venv/lib/python3.7/site-packages/gremlin_python/driver/connection.py", line 55, in write
2020-10-22T18:01:22.347522673Z     self.connect()
2020-10-22T18:01:22.347529987Z   File "/opt/venv/lib/python3.7/site-packages/gremlin_python/driver/connection.py", line 45, in connect
2020-10-22T18:01:22.347536097Z     self._transport.connect(self._url, self._headers)
2020-10-22T18:01:22.347542222Z   File "/opt/venv/lib/python3.7/site-packages/gremlin_python/driver/tornado/transport.py", line 36, in connect
2020-10-22T18:01:22.347547822Z     lambda: websocket.websocket_connect(url))
2020-10-22T18:01:22.347553477Z   File "/opt/venv/lib/python3.7/site-packages/tornado/ioloop.py", line 571, in run_sync
2020-10-22T18:01:22.347559295Z     self.start()
2020-10-22T18:01:22.347564864Z   File "/opt/venv/lib/python3.7/site-packages/tornado/platform/asyncio.py", line 132, in start
2020-10-22T18:01:22.347570978Z     self.asyncio_loop.run_forever()
2020-10-22T18:01:22.347576693Z   File "uvloop/loop.pyx", line 1351, in uvloop.loop.Loop.run_forever
2020-10-22T18:01:22.347582342Z   File "uvloop/loop.pyx", line 484, in uvloop.loop.Loop._run
2020-10-22T18:01:22.347588222Z RuntimeError: Cannot run the event loop while another loop is running

我尝试使用nest_asyncio.apply,但这导致了这个错误:

ValueError: Can't patch loop of type <class 'uvloop.Loop'>

根据文档,这只是一个规则。

所以我真的不知道如何进行?

4

1 回答 1

1

在上面添加我的评论作为答案。在某些情况下,有必要降低正在使用的 Tornado 版本。如果在其他人尝试创建事件循环时,事件循环已经在运行,您有时会遇到一些问题。目前,使用 Gremlin Python 降级到 Tornado 4.5.1 应该可以解决任何问题。

于 2020-10-22T20:55:03.150 回答