Virtuální asistenti a přístup k datům

Building Chatbots in Python

Alan Nichol

Co-founder and CTO, Rasa

Virtuální asistenti

  • Běžné případy použití chatbotů:
    • Plánování schůzky
    • Rezervace letu
    • Hledání restaurace
  • Vyžadují informace o vnějším světě
  • Potřebují pracovat s databázemi nebo API
Building Chatbots in Python

Základy SQL

name pricerange area rating
Bill's Burgers hi east 3
Moe's Plaice low north 3
Sushi Corner mid center 3

SELECT * from restaurants;
SELECT name, rating from restaurants;
SELECT name from restaurants 
WHERE area = 'center' AND pricerange = 'hi';
Building Chatbots in Python

SQLite s Pythonem

import sqlite3

conn = sqlite3.connect('hotels.db')
c = conn.cursor()
c.execute("SELECT * FROM hotels WHERE area='south' and pricerange='hi'")
<sqlite3.Cursor at 0x10cd5a960>
c.fetchall()
[('Grand Hotel', 'hi', 'south', 5)]
Building Chatbots in Python

SQL injection

# Bad Idea
query = "SELECT name from restaurant where area='{}'".format(area)
c.execute(query)

# Better t = (area,price) c.execute('SELECT * FROM hotels WHERE area=? and price=?', t)
Building Chatbots in Python

Pojďme si to procvičit!

Building Chatbots in Python

Preparing Video For Download...