-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixing missing type + renaming weather to quickstart, adding template
- Loading branch information
Showing
4 changed files
with
46 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
from wit import Wit | ||
|
||
# Quickstart example | ||
# See https://wit.ai/l5t/Quickstart | ||
|
||
access_token = 'YOUR_ACCESS_TOKEN' | ||
|
||
def first_entity_value(entities, entity): | ||
if entity not in entities: | ||
return None | ||
val = entities[entity][0]['value'] | ||
if not val: | ||
return None | ||
return val['value'] if isinstance(val, dict) else val | ||
|
||
def say(session_id, msg): | ||
print(msg) | ||
|
||
def merge(context, entities): | ||
new_context = dict(context) | ||
loc = first_entity_value(entities, 'location') | ||
if loc: | ||
new_context['loc'] = loc | ||
return new_context | ||
|
||
def error(session_id, msg): | ||
print('Oops, I don\'t know what to do.') | ||
|
||
def fetch_weather(context): | ||
new_context = dict(context) | ||
new_context['forecast'] = 'sunny' | ||
return new_context | ||
|
||
actions = { | ||
'say': say, | ||
'merge': merge, | ||
'error': error, | ||
'fetch-weather': fetch_weather, | ||
} | ||
client = Wit(access_token, actions) | ||
|
||
session_id = 'my-user-id-42' | ||
client.run_actions(session_id, 'weather in London', {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,7 @@ | |
|
||
setup( | ||
name='wit', | ||
version='3.0', | ||
version='3.1', | ||
description='Wit SDK for Python', | ||
author='The Wit Team', | ||
author_email='[email protected]', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters