Skip to content
This repository has been archived by the owner on Aug 12, 2022. It is now read-only.

Commit

Permalink
Remove recast name
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Selent committed Dec 12, 2018
1 parent 727d57a commit 8b51c04
Show file tree
Hide file tree
Showing 47 changed files with 139 additions and 139 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2016 RecastAI
Copyright (c) 2016 SAP Conversational AI

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
36 changes: 18 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[logo]: https://cdn.recast.ai/brand/recast-ai-logo-inline.png "Recast.AI"
[logo]: https://cdn.cai.tool.sap/brand/sapcai/sap-cai-black.svg "SAP Conversational AI"

![alt text][logo]

# Recast.AI - SDK Python
# SAP Conversational AI - SDK Python

Recast.AI official SDK in Python
SAP Conversational AI official SDK in Python

## Overview

This module is a wrapper around the [Recast.AI](https://recast.ai) API, and allows you to:
* [Analyse your text](https://github.com/RecastAI/SDK-python/wiki/01-Analyse-Text)
* [Manage a conversation](https://github.com/RecastAI/SDK-python/wiki/02-Manage-conversation)
* [Receive and send messages](https://github.com/RecastAI/SDK-python/wiki/03-Receive-and-send-messages)
This module is a wrapper around the [SAP Conversational AI](https://cai.tool.sap) API, and allows you to:
* [Analyse your text](https://github.com/SAPConversationalAI/SDK-python/wiki/01-Analyse-Text)
* [Manage a conversation](https://github.com/SAPConversationalAI/SDK-python/wiki/02-Manage-conversation)
* [Receive and send messages](https://github.com/SAPConversationalAI/SDK-python/wiki/03-Receive-and-send-messages)

## Installation

Expand All @@ -20,7 +20,7 @@ This module is a wrapper around the [Recast.AI](https://recast.ai) API, and allo
Install from PyPi using [pip](http://www.pip-installer.org/en/latest/), a
package manager for Python.

pip install recastai
pip install sapcai

Don't have pip installed? Try installing it, by running this from the command
line:
Expand All @@ -30,32 +30,32 @@ line:
#### With the source code

You can [download the source code
(ZIP)](https://github.com/recastAI/SDK-python/zipball/master "Recast.AI-python
source code") for `RecastAI-python`, and then run:
(ZIP)](https://github.com/SAPConversationalAI/SDK-python/zipball/master "SAP Conversational AI-python
source code") for `SAPConversationalAI-python`, and then run:

python setup.py install

You may need to run the above commands with `sudo`.

This library supports both `python 2.7+` and `python 3.5+`.

You can now use the sdk in your code.
You can now use the SDK in your code.

## Usage

Using the entire SDK:
```python
import recastai
import sapcai

client = recastai.Client('YOUR_TOKEN')
client = sapcai.Client('YOUR_TOKEN')

client.request.analyse_text('Hi')
client.connect.broadcast_message('Hi')
```

Extracting one single API:
```python
from recastai import Request, Connect
from sapcai import Request, Connect

request = Request('YOUR_TOKEN')
request.analyse_text('Hi')
Expand All @@ -66,19 +66,19 @@ connect.broadcast_message('Hi')

## More

You can view the whole API reference at [man.recast.ai](https://man.recast.ai).
You can view the whole API reference at [cai.tool.sap/docs/api-reference](https://cai.tool.sap/docs/api-reference).


## Author

Paul Renvoisé, paul.renvoise@recast.ai, [@paulrenvoise](https://twitter.com/paulrenvoise)
Paul Renvoisé, paul.renvoise@sap.com, [@paulrenvoise](https://twitter.com/paulrenvoise)

You can follow us on Twitter at [@recastai](https://twitter.com/recastai) for updates and releases.
You can follow us on Twitter at [@sapcai](https://twitter.com/sapcai) for updates and releases.


## License

Copyright (c) [2018] [Recast.AI](https://recast.ai)
Copyright (c) [2018] [SAP Conversational AI](https://cai.tool.sap)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 0 additions & 6 deletions recastai/apis/build/utils.py

This file was deleted.

7 changes: 0 additions & 7 deletions recastai/apis/connect/utils.py

This file was deleted.

5 changes: 0 additions & 5 deletions recastai/apis/errors.py

This file was deleted.

16 changes: 0 additions & 16 deletions recastai/utils.py

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 11 additions & 11 deletions recastai/apis/build/build.py → sapcai/apis/build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .dialog_conversation import DialogConversation
from .dialog_response import DialogResponse

from ..errors import RecastError
from ..errors import SapcaiError


class Build:
Expand Down Expand Up @@ -43,32 +43,32 @@ def dialog(self, msg, conversation_id, language=None, **options):

response = requests.post('{}/dialog'.format(Utils.BUILD_ENDPOINT), json=params, headers=self.headers(), proxies=proxy)
if response.status_code != requests.codes.ok:
raise RecastError(response.json().get('message'))
raise SapcaiError(response.json().get('message'))
json = response.json()['results']
return DialogResponse(json['messages'], json['conversation'], json['nlp'], json['logs'])

@token_required
def update_conversation(self, user, bot, conversation_id, opts):
def update_conversation(self, user, bot, version, conversation_id, opts):
if 'memory' in opts and type(opts['memory']) is not dict:
raise ValueError('Memory parameter must be a dict')
url = '{}/users/{}/bots/{}/builders/v1/conversation_states/{}'.format(Utils.BUILD_ENDPOINT, user, bot, conversation_id)
url = '{}/users/{}/bots/{}/versions/${}/builder/v1/conversation_states/{}'.format(Utils.BUILD_ENDPOINT, user, bot, version, conversation_id)
response = requests.put(url, json=opts, headers=self.headers())
if response.status_code != requests.codes.ok:
raise RecastError(response.json().get('message'))
raise SapcaiError(response.json().get('message'))
return DialogConversation(response.json()['results'])

@token_required
def delete_conversation(self, user, bot, conversation_id):
url = '{}/users/{}/bots/{}/builders/v1/conversation_states/{}'.format(Utils.BUILD_ENDPOINT, user, bot, conversation_id)
def delete_conversation(self, user, bot, version, conversation_id):
url = '{}/users/{}/bots/{}/versions/${}/builder/v1/conversation_states/{}'.format(Utils.BUILD_ENDPOINT, user, bot, version, conversation_id)
response = requests.delete(url, headers=self.headers())
if response.status_code != requests.codes.no_content:
raise RecastError(response.json().get('message'))
raise SapcaiError(response.json().get('message'))
return True

@token_required
def get_conversation(self, user, bot, conversation_id):
url = '{}/users/{}/bots/{}/builders/v1/conversation_states/{}'.format(Utils.BUILD_ENDPOINT, user, bot, conversation_id)
def get_conversation(self, user, bot, version, conversation_id):
url = '{}/users/{}/bots/{}/versions/${}/builder/v1/conversation_states/{}'.format(Utils.BUILD_ENDPOINT, user, bot, version, conversation_id)
response = requests.get(url, headers=self.headers())
if response.status_code != requests.codes.ok:
raise RecastError(response.json().get('message'))
raise SapcaiError(response.json().get('message'))
return DialogConversation(response.json()['results'])
File renamed without changes.
6 changes: 6 additions & 0 deletions sapcai/apis/build/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# coding: utf-8


class Utils():
"""Endpoints"""
BUILD_ENDPOINT = 'https://api.cai.tool.sap/build/v1'
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .models import Message as Model
from .utils import Utils

from ..errors import RecastError
from ..errors import SapcaiError


class Message():
Expand All @@ -15,7 +15,7 @@ def parse_message(self, request):
def send_message(self, messages, conversation_id, token=None):
token = token or self.token
if token is None:
raise RecastError("Token is missing")
raise SapcaiError("Token is missing")

url = Utils.CONVERSATION_ENDPOINT % (conversation_id) + '/messages'
response = requests.post(
Expand All @@ -24,14 +24,14 @@ def send_message(self, messages, conversation_id, token=None):
headers={'Authorization': "Token {}".format(token)}
)
if response.status_code != requests.codes.created:
raise RecastError(response.json().get('message'))
raise SapcaiError(response.json().get('message'))

return response

def broadcast_message(self, messages, token=None):
token = token or self.token
if token is None:
raise RecastError("Token is missing")
raise SapcaiError("Token is missing")

url = Utils.MESSAGE_ENDPOINT % ('')
response = requests.post(
Expand All @@ -40,6 +40,6 @@ def broadcast_message(self, messages, token=None):
headers={'Authorization': "Token {}".format(token)}
)
if response.status_code != requests.codes.created:
raise RecastError(response.json().get('message'))
raise SapcaiError(response.json().get('message'))

return response
7 changes: 7 additions & 0 deletions sapcai/apis/connect/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# coding: utf-8


class Utils():
"""Endpoints"""
CONVERSATION_ENDPOINT = 'https://api.cai.tool.sap/connect/v1/conversations/%s'
MESSAGE_ENDPOINT = 'https://api.cai.tool.sap/connect/v1/messages/%s'
5 changes: 5 additions & 0 deletions sapcai/apis/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# coding: utf-8


class SapcaiError(RuntimeError):
pass
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from .models import Response
from .utils import Utils

from ..errors import RecastError
from ..errors import SapcaiError


class Analyse():
def analyse_text(self, text, token=None, language=None):
token = token or self.token
if token is None:
raise RecastError("Token is missing")
raise SapcaiError("Token is missing")

language = language or self.language

Expand All @@ -27,6 +27,6 @@ def analyse_text(self, text, token=None, language=None):
headers={'Authorization': "Token {}".format(token)}
)
if response.status_code != requests.codes.ok:
raise RecastError(response.json().get('message', ''))
raise SapcaiError(response.json().get('message', ''))

return Response(response.json()['results'])
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
from .models import Conversation
from .utils import Utils

from ..errors import RecastError
from ..errors import SapcaiError


class Converse():
def converse_text(self, text, token=None, language=None, conversation_token=None, memory=None):
token = token or self.token
if token is None:
raise RecastError("Token is missing")
raise SapcaiError("Token is missing")

language = language or self.language

Expand All @@ -31,14 +31,14 @@ def converse_text(self, text, token=None, language=None, conversation_token=None
headers={'Authorization': "Token {}".format(token)}
)
if response.status_code != requests.codes.ok:
raise RecastError(response.json().get('message', ''))
raise SapcaiError(response.json().get('message', ''))

return Conversation(response, token)

def converse_file(self, filename, token=None, language=None, conversation_token=None, memory=None):
token = token or self.token
if token is None:
raise RecastError("Token is missing")
raise SapcaiError("Token is missing")

language = language or self.language

Expand All @@ -58,6 +58,6 @@ def converse_file(self, filename, token=None, language=None, conversation_token=
headers={'Authorization': "Token {}".format(token)}
)
if response.status_code != requests.codes.ok:
raise RecastError(response.json().get('message', ''))
raise SapcaiError(response.json().get('message', ''))

return Conversation(response)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from ..utils import Utils

from ...errors import RecastError
from ...errors import SapcaiError


class Conversation():
Expand Down Expand Up @@ -98,7 +98,7 @@ def set_memory(self, memory):
headers={'Authorization': "Token {}".format(self.token)}
)
if response.status_code != requests.codes.ok:
raise RecastError(response.json().get('message', ''))
raise SapcaiError(response.json().get('message', ''))

response = response.json()
response = response['results']
Expand All @@ -114,7 +114,7 @@ def reset_memory(self, key=None):
headers={'Authorization': "Token {}".format(self.token)}
)
if response.status_code != requests.codes.ok:
raise RecastError(response.json().get('message', ''))
raise SapcaiError(response.json().get('message', ''))

response = response.json()
response = response['results']
Expand All @@ -128,7 +128,7 @@ def reset_conversation(self):
headers={'Authorization': "Token {}".format(self.token)}
)
if response.status_code != requests.codes.ok:
raise RecastError(response.json().get('message', ''))
raise SapcaiError(response.json().get('message', ''))

response = response.json()
response = response['results']
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

class Utils():
"""Endpoints"""
REQUEST_ENDPOINT = 'https://api.recast.ai/v2/request'
CONVERSE_ENDPOINT = 'https://api.recast.ai/v2/converse'
REQUEST_ENDPOINT = 'https://api.cai.tool.sap/v2/request'
CONVERSE_ENDPOINT = 'https://api.cai.tool.sap/v2/converse'

"""Act constants"""
ACT_ASSERT = 'assert'
Expand Down
File renamed without changes.
16 changes: 16 additions & 0 deletions sapcai/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# coding: utf-8


class Utils():
"""Versioning"""
MAJOR = '3'
MINOR = '0'
MICRO = '0'
VERSION = "%s.%s.%s" % (MAJOR, MINOR, MICRO)

"""Endpoints"""
TRAIN_ENDPOINT = 'https://api.cai.tool.sap/v2/'
CONNECT_ENDPOINT = 'https://api.cai.tool.sap/connect/v1/'
HOST_ENDPOINT = 'https://api.cai.tool.sap/host/v1/'
REQUEST_ENDPOINT = 'https://api.cai.tool.sap/v2/'
MONITOR_ENDPOINT = 'https://api.cai.tool.sap/monitor/v1/'
Loading

0 comments on commit 8b51c04

Please sign in to comment.