Skip to Main Content

AI Services

Announcement

For appeals, questions and feedback, please email oracle-forums_moderators_us@oracle.com

Confiqure chatgpt in oracle digital assistant

user-z0m0uFeb 21 2023

I am trying to connect ODA with Chatgpt 3 model using bots-node-sdk where to pass action value , how to connect it to Dailog flow. i am gives services.js file below .

const OracleBot = require('@oracle/bots-node-sdk');

const { WebhookClient, WebhookEvent } = OracleBot.Middleware;

const express = require('express');

const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({

apiKey:"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",

});

const openai = new OpenAIApi(configuration);

const textGeneration = async (prompt) => {

try {

const response = await openai.createCompletion({

  model: 'text-davinci-003',

  prompt: \`Human: ${prompt}\\nAI: \`,

  temperature: 0.9,

  max\_tokens: 500,

  top\_p: 1,

  frequency\_penalty: 0,

  presence\_penalty: 0.6,

  stop: \['Human:', 'AI:'\]

});




return {

  status: 1,

  response: \`${response.data.choices\[0\].text}\`

};

} catch (error) {

return {

  status: 0,

  response: ''

};

}

};

module.exports = (app) => {

const logger = console;

// initialize the application with OracleBot

OracleBot.init(app, {

logger,

});

// add webhook integration

const webhook = new WebhookClient({

channel: {

  url: "https://oda-bcc256cc19504eca90d871ebbfc81ea5-da2.data.digitalassistant.oci.oraclecloud.com/connectors/v2/listeners/webhook/channels/8d90520b-f6ed-46b5-be51-e41f5ec82501",

  secret: "0M8w2YsSt8titIpRziqXcKdu8yqO5Edu",

}

});

// Add webhook event handlers (optional)

webhook

.on(WebhookEvent.ERROR, err => logger.error('Error:', err.message))

.on(WebhookEvent.MESSAGE\_SENT, message => logger.info('Message to bot:', message))

.on(WebhookEvent.MESSAGE\_RECEIVED, message => {

  // message was received from bot. forward to messaging client.

  logger.info('Message from bot:', message);

  // TODO: implement send to client...

});

// Create endpoint for bot webhook channel configurtion (Outgoing URI)

// NOTE: webhook.receiver also supports using a callback as a replacement for WebhookEvent.MESSAGE_RECEIVED.

// - Useful in cases where custom validations, etc need to be performed.

app.post('/bot/message', async (req, res) => {

const action = req.body.queryResult.action;

const queryText = req.body.queryResult.queryText;




if (action === 'input.unknown') {

  const result = await textGeneration(queryText);

  if (result.status === 1) {

    res.send({

      fulfillmentMessages: \[{ text: { text: \[result.response\] } }\]

    });

  } else {

    res.send({

      fulfillmentMessages: \[{ text: { text: \["Sorry, I'm not able to help with that."\] } }\]

    });

  }

} else {

  res.send({

    fulfillmentMessages: \[{ text: { text: \[\`No handler for the action ${action}.\`\] } }\]

  });

}

});

// Integrate with messaging client according to their specific SDKs, etc.

app.post('/bot/webhook', (req, res) => {

const user = req.body.userId;

const message = req.body.messagePayload;




// Send the message to the bot webhook channel

  webhook.send(message, user)

  .then(() => res.send('ok'), e => res.status(400).end(e.message));

});

}

Please help me to solve this.

Comments
Post Details
Added on Feb 21 2023
0 comments
495 views