-
Notifications
You must be signed in to change notification settings - Fork 4
/
GPT3Chatbot_Tynski.js
93 lines (55 loc) · 2.68 KB
/
GPT3Chatbot_Tynski.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
'use strict';
const axios = require('axios');
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
//console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
//console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
async function rhymingWordHandler(agent) {
try{
const echoText = agent.parameters.echoText;
//agent.add(echoText);
const fromdatabase = await axios.get("https://theaioracle-db93.restdb.io/rest/convo/yourdatabaseentry",{
headers:
{ 'cache-control': 'no-cache',
'x-apikey': 'yourapikey' },
json: true});
//agent.add(JSON.stringify(fromdatabase.data.context));
//console.log(JSON.stringify(fromdatabase.data.context));
var togpt3 = fromdatabase.data.context;
const fromgpt3 = await axios.post("https://api.openai.com/v1/engines/davinci/completions",{
prompt: togpt3 + "\nYou:" + echoText + "\nHeather:",
max_tokens: 75,
temperature: 0.7,
top_p: 1,
n: 1,
stream: false,
logprobs: null,
stop: "\n"
},{
headers:
{ 'Authorization': `yourgpt3key` }});
agent.add(fromgpt3.data.choices[0].text);
var responsefromgpt3 = fromgpt3.data.choices[0].text;
const todatabase = await axios.put( "https://theaioracle-db93.restdb.io/rest/convo/yourdatabaseentry",
{context: togpt3 + "\nYou:"+ echoText + "\nHeather:" + responsefromgpt3 },
{headers:
{ 'cache-control': 'no-cache',
'x-apikey': 'yourkey' }});
//agent.add(responsefromgpt3);
return fromdatabase,fromgpt3,todatabase;
}
catch (err) {
console.error(err);
}
}
let intentMap = new Map();
//intentMap.set('Default Welcome Intent', welcome);
//intentMap.set('Default Fallback Intent', fallback);
intentMap.set('RhymingWord', rhymingWordHandler);
//intentMap.set('looping test', loopingHandler);
agent.handleRequest(intentMap);
});