1
我想獲取任何項目的股票價格。我有一個功能getPrice
它返回該項目的價格。我正在嘗試使用wit ai
。 這是我試過的。在python中調用動作函數api
from wit import Wit
def getPrice(request):
#statements
return price
def send(request, response):
print request['text']
print('Sending to user...', response['text'])
actions = {
'send': send,
'getPrice':getPrice
}
client = Wit(access_token="<token>", actions=actions)
resp = client.message('what is the stock price of xyz')
print('Result: ' + str(resp))
和我得到的結果是:
Result: {
u 'entities': {
u 'search_query': [{
u 'suggested': True,
u 'confidence': 0.578445451443443,
u 'type': u 'value',
u 'value': u 'stock of xyz'
}],
u 'item': [{
u 'confidence': 0.9613219630126943,
u 'value': u 'xyz'
}]
},
u 'msg_id': u '5ac1a450-7c5d-3190-8666-5d88a1884f94',
u '_text': u 'what is the stock of xyz?'
}
我想博特顯示的價格。我怎樣才能調用這個動作函數?
它給'類型錯誤:列表索引必須是整數,而不是str' – HunterrJ
也' xyz'不是結果。這是我想要獲得的股票。 – HunterrJ
對不起,沒有看到它是一個列表。已更新。 –