Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rasa API #3066

Closed
wochinge opened this issue Feb 5, 2019 · 7 comments
Closed

Rasa API #3066

wochinge opened this issue Feb 5, 2019 · 7 comments
Assignees

Comments

@wochinge
Copy link
Contributor

wochinge commented Feb 5, 2019

Suggested API commands:

a python API to use the Rasa tools within e.g. ipython notebooks

Goal

  • don't expose internal stuff (agent, file loading etc)
  • be consistent between core / nlu

Changes to Rasa Stack

import rasa

rasa.train(config=..., data=...) # train core + nlu
rasa.run(config=...) # run core + nlu
rasa.test(config=..., data=...) # test core + nlu

rasa.model.load(path=...) -> Model # load core + nlu model
rasa.model.persist(core=..., nlu=..., path=...) # persist core + nlu model

rasa.data.load(...) # load core + nlu data, return tuple
rasa.data.load_stories(...) # load core data
rasa.data.load_messages(...) # load nlu data

rasa.config.load(domain=..., config=..., credentials=..., endpoints=...)

rasa.jupyter.chat() # chat with the bot within in a jupyter notebook

Changes to Core and NLU

Modules

  • rename rasa_nlu.run to rasa_nlu.shell
  • rename rasa_nlu.server to rasa_nlu.run
  • rename evaluate scripts to test
  • add a module rasa.remote which covers all the remote stuff
  • add a module rasa.local which covers the interaction with the local server

Training

  • rename rasa_nlu.train.do_train() to rasa_nlu.train.train()
  • pass filepath to rasa_nlu.train.do_train() instead of file ✅
  • rename rasa_core.train.train_dialogue_model() to rasa_core.train.train()

Testing

  • create method rasa_nlu.test.cross_validate() which can be called with file paths etc and creates the agent inside
  • create method rasa_core.test.test() which can be called with file paths etc and creates the agent inside ✅
  • create method rasa_core.test.compare() (compare multiple policies) ✅

Resulting Jupyter notebooks

Both should be possible: Demonstrating Rasa Core, NLU separately and showing them as one

import rasa_nlu

nlu_data = "..."
nlu_config = "..."

rasa_nlu.train(...)
rasa_nlu.test(...)

import rasa_core

stories = "..."
domain = "..."
policies = "..."
rasa_core.train(...)
rasa_core.test()

import rasa
rasa.jupyter.chat()
import rasa

nlu_data = "..."
stories = "..."
domain = "..."
config = "..."

rasa.train(...)
rasa.test(...)
rasa.jupyter.chat(...)
@wochinge wochinge self-assigned this Feb 5, 2019
@MetcalfeTom
Copy link
Contributor

Since you want to implement rasa.train() and rasa.test(), is it also possible to rename these other functions? rasa_nlu.train() would be a lot better than rasa_nlu.train.train() and same with test()

@tmbo
Copy link
Member

tmbo commented Feb 6, 2019

Considering the scripts in NLU:

  • the current "run" (which starts a shell to try out nlu messages) script should be comparable to the core cmdline mode
  • server.py should just contain the server

There are a couple more concepts that we should support:

  • loading data
  • persisting / loading a model

@wochinge
Copy link
Contributor Author

wochinge commented Feb 6, 2019

  • the current "run" (which starts a shell to try out nlu messages) script should be comparable to the core cmdline mode

So you suggest to leave the module names as they are?

@tmbo
Copy link
Member

tmbo commented Feb 6, 2019

well, not sure whatever you think makes it most consistent

@wochinge
Copy link
Contributor Author

wochinge commented Feb 7, 2019

Updated the issue according to Tom's suggestion:

  • added rasa.data module
  • added rasa.local module
  • added rasa.model module
  • decided not to rename the nlu modules run and server since this would lead to a lot of breaking things

@howl-anderson
Copy link
Contributor

Nice Job! Few comments about it:

Maybe we can add features to Rasa Python API to make it more easily integrated with (independent from) service container (HTTP server, RPC (grpc / thrift / protobf) server) or directly used in python interpreter (such as python interaction session and jupyter notebook). ideally, it look like this:

import rasa

# nlu_model can be local data object, agent to remote service or dummy object for debug
nlu_model = rasa.model.nlu.load(path='...')  # load NLU model from local

core_model = rasa.model.core.load(path='...', nlu_entry=nlu_model)

# in python, user can use rasa by
result = core_model.eval('I want book a hotel in LA tomorrow')
print(result)  # output: OK. I booked xxx hotel for you
print(core_model.current_states)  # view current internal states, very useful for real time debug
print(nlu_model.current_states)  # view current internal states, very useful for real time debug

# in jupyter notebook, user can use rasa by
jupyter_wrapper = rasa.jupyter.wrap_core(core_entry=core_model)
result = jupyter_wrapper.eval('I want book a hotel in LA tomorrow')
print(result)  # output jupyter friendly message: OK. I booked xxx hotel for you
print(jupyter_wrapper.current_states)  # view current internal states, display friendly for jupyter

# wrap it for start a http service
http_server = rasa.service.http(core_entry=core_model)
http_server.serve_forever(port='80', host='0.0.0.0')

# wrap it for start a grpc service
grpc_server = rasa.service.grpc(core_entry=core_model)
grpc_server.serve_forever(port='9090', host='0.0.0.0')

@suenpun
Copy link

suenpun commented Feb 27, 2019

great! I am using gRPC now , realy need this RPC features! Looking forward to it!@howl-anderson @tmbo

@wochinge wochinge reopened this Mar 6, 2019
@wochinge wochinge closed this as completed Mar 6, 2019
@tmbo tmbo transferred this issue from RasaHQ/rasa_stack Mar 13, 2019
@tmbo tmbo transferred this issue from RasaHQ/rasa_core Mar 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants