|
import requests |
|
|
|
chat_history = [] |
|
|
|
API_URL = "API_ENDPOINT_URL" |
|
headers = { |
|
"Accept" : "application/json", |
|
"Authorization": "Bearer API_KEY", |
|
"Content-Type": "application/json" |
|
} |
|
|
|
def query(payload): |
|
response = requests.post(API_URL, headers=headers, json=payload) |
|
return response.json() |
|
|
|
def chat(user_q): |
|
try: |
|
chat_history.append(user_q) |
|
output = query({ |
|
"inputs": chat_history, |
|
"parameters": {} |
|
}) |
|
generated_reply = output[0]['generated_reply'] |
|
chat_history.append(generated_reply) |
|
except Exception as ex: |
|
print(ex) |
|
chat(user_q) |
|
|
|
return generated_reply |
|
|
|
|
|
user_q = '<user>: What are the most visited places in Dublin?' |
|
reply = chat(user_q) |
|
|
|
user_q = '<user>: Which place is the oldest?' |
|
reply = chat(user_q) |
|
|
|
user_q = '<user>: Who built it?' |
|
reply = chat(user_q) |
|
|
|
user_q = '<user>: Do you recommend any other places to visit?' |
|
reply = chat(user_q) |
|
|
|
user_q = '<user>: What is the average budget for a one-week visit?' |
|
reply = chat(user_q) |
|
|
|
|
|
print(chat_history) |
|
|