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

CC-Fall'22(vn2065) #1

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions AI Customer Service API-first-build-swagger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
---
swagger: "2.0"
info:
description: "AI Customer Service application, built during the Cloud and Big Data\
\ course at New York University."
version: "1.0.0"
title: "AI Customer Service API"
host: "e0gqi81ueh.execute-api.us-east-1.amazonaws.com"
basePath: "/first-build"
schemes:
- "https"
paths:
/chatbot:
post:
tags:
- "NLU"
summary: "The endpoint for the Natural Language Understanding API."
description: "This API takes in one or more messages from the client and returns\n\
one or more messages as a response. The API leverages the NLP\nbackend functionality,\
\ paired with state and profile information\nand returns a context-aware reply.\n"
operationId: "sendMessage"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- in: "body"
name: "BotRequest"
required: true
schema:
$ref: "#/definitions/BotRequest"
responses:
"200":
description: "A Chatbot response"
schema:
$ref: "#/definitions/BotResponse"
headers:
Access-Control-Allow-Origin:
type: "string"
"500":
description: "Unexpected error"
schema:
$ref: "#/definitions/Error"
"403":
description: "Unauthorized"
schema:
$ref: "#/definitions/Error"
options:
tags:
- "NLU"
summary: "The endpoint for the Natural Language Understanding API."
description: "This endpoints checks the API allowed methods.\n"
operationId: "checkMethods"
consumes:
- "application/json"
produces:
- "application/json"
parameters:
- in: "body"
name: "BotRequest"
required: true
schema:
$ref: "#/definitions/BotRequest"
responses:
"200":
description: "A Chatbot response"
schema:
$ref: "#/definitions/BotResponse"
headers:
Access-Control-Allow-Origin:
type: "string"
Access-Control-Allow-Methods:
type: "string"
Access-Control-Allow-Headers:
type: "string"
"500":
description: "Unexpected error"
schema:
$ref: "#/definitions/Error"
"403":
description: "Unauthorized"
schema:
$ref: "#/definitions/Error"
definitions:
BotRequest:
type: "object"
properties:
messages:
type: "array"
items:
$ref: "#/definitions/Message"
Message:
type: "object"
properties:
type:
type: "string"
unstructured:
$ref: "#/definitions/UnstructuredMessage"
UnstructuredMessage:
type: "object"
properties:
id:
type: "string"
text:
type: "string"
timestamp:
type: "string"
format: "datetime"
BotResponse:
type: "object"
properties:
messages:
type: "array"
items:
$ref: "#/definitions/Message"
Error:
type: "object"
properties:
code:
type: "integer"
format: "int32"
message:
type: "string"
44 changes: 22 additions & 22 deletions assets/js/sdk/apigClient.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ apigClientFactory.newClient = function (config) {
config.sessionToken = '';
}
if(config.region === undefined) {
config.region = 'us-east-2';
config.region = 'us-east-1';
}
//If defaultContentType is not defined then default to application/json
if(config.defaultContentType === undefined) {
Expand All @@ -51,9 +51,9 @@ apigClientFactory.newClient = function (config) {
config.defaultAcceptType = 'application/json';
}


// extract endpoint and path from url
var invokeUrl = 'https://abc123.execute-api.us-east-1.amazonaws.com/v1';
var invokeUrl = 'https://e0gqi81ueh.execute-api.us-east-1.amazonaws.com/first-build';
var endpoint = /(^https?:\/\/[^\/]+)/g.exec(invokeUrl)[1];
var pathComponent = invokeUrl.substring(endpoint.length);

Expand All @@ -80,44 +80,44 @@ apigClientFactory.newClient = function (config) {
};

var apiGatewayClient = apiGateway.core.apiGatewayClientFactory.newClient(simpleHttpClientConfig, sigV4ClientConfig);



apigClient.chatbotPost = function (params, body, additionalParams) {
if(additionalParams === undefined) { additionalParams = {}; }

apiGateway.core.utils.assertParametersDefined(params, ['body'], ['body']);

var nluPostRequest = {
var chatbotPostRequest = {
verb: 'post'.toUpperCase(),
path: pathComponent + uritemplate('/chatbot').expand(apiGateway.core.utils.parseParametersToObject(params, [])),
headers: apiGateway.core.utils.parseParametersToObject(params, []),
queryParams: apiGateway.core.utils.parseParametersToObject(params, []),
body: body
};


return apiGatewayClient.makeRequest(nluPostRequest, authType, additionalParams, config.apiKey);
return apiGatewayClient.makeRequest(chatbotPostRequest, authType, additionalParams, config.apiKey);
};


apigClient.chatbotOptions = function (params, body, additionalParams) {
if(additionalParams === undefined) { additionalParams = {}; }

apiGateway.core.utils.assertParametersDefined(params, [], ['body']);

var nluOptionsRequest = {
apiGateway.core.utils.assertParametersDefined(params, ['body'], ['body']);
var chatbotOptionsRequest = {
verb: 'options'.toUpperCase(),
path: pathComponent + uritemplate('/chatbot').expand(apiGateway.core.utils.parseParametersToObject(params, [])),
headers: apiGateway.core.utils.parseParametersToObject(params, []),
queryParams: apiGateway.core.utils.parseParametersToObject(params, []),
body: body
};


return apiGatewayClient.makeRequest(nluOptionsRequest, authType, additionalParams, config.apiKey);
return apiGatewayClient.makeRequest(chatbotOptionsRequest, authType, additionalParams, config.apiKey);
};


return apigClient;
};
31 changes: 31 additions & 0 deletions dynamoDBstreamtoES.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import boto3
import requests
from requests_aws4auth import AWS4Auth

region = 'us-east-1' # e.g. us-east
service = 'es'
credentials = boto3.Session().get_credentials()
awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, region, service, session_token=credentials.token)

host = 'https://search-search-qwd3x3xfvps2llb4wwmiibd66q.us-east-1.es.amazonaws.com' # the OpenSearch Service domain, with https://
index = 'restaurants'
type = 'restaurant'
url = host + '/' + index + '/' + type + '/'

headers = { "Content-Type": "application/json" }

def lambda_handler(event, context):
count = 0
for record in event['Records']:
# Get the primary key for use as the OpenSearch ID
id = record['dynamodb']['Keys']['id']['S']

if record['eventName'] == 'REMOVE':
r = requests.delete(url + id, auth=awsauth)
else:
document = record['dynamodb']['NewImage']
r = requests.put(url + id, auth=awsauth, json=document, headers=headers)
print(r.content,document,url+id,awsauth)
count += 1
print("success")
return str(count) + ' records processed.'
24 changes: 24 additions & 0 deletions lambda_function.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import json
def lambda_handler(event, context):
# TODO implement
message_string = {
"messages": [
{
"type": "unstructured",
"unstructured": {
"id": "string",
"text": "Application under development. Search functionality will be implemented in Assignment 2",
"timestamp": "string"
}
}
]
}
return {
'statusCode': 200,
'headers': {
'Access-Control-Allow-Headers': 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'OPTIONS,POST'
},
'body': json.dumps(message_string)
}
22 changes: 22 additions & 0 deletions lf0dining.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import json
import boto3
client = boto3.client('lex-runtime')
def lambda_handler(event, context):
usertext=event["messages"][0]["unstructured"]["text"]
response = client.post_text(
botName='diningbot',
botAlias='diningbot',
userId='1234567890',
sessionAttributes={
},
requestAttributes={
},
inputText=usertext,
activeContexts=[
]
)
print(response["message"])
return {
'statusCode': 200,
'messages': [{'type': 'unstructured', 'unstructured': {'text': response["message"]}}]
}
Loading