Davinci can't not be a therapist ;)

Hi
I have set up dialogflow to interface via telegram and webhook using code run on repl.it.
Here is the code:


const express = require("express");
require("actions-on-google")
// require('dotenv').config();
const axios = require('axios');
const { WebhookClient } = require("dialogflow-fulfillment");
const app = express();
app.post("/dialogflow", express.json(), (req, res) => {
    const agent = new WebhookClient({ request: req, response: res });
    let intentMap = new Map();
    intentMap.set("Default Welcome Intent", welcome);
    intentMap.set("Default Fallback Intent", queryGPT);
    agent.handleRequest(intentMap);
  
    function welcome(agent) {
      agent.add('Hi');
  }
  
  async function queryGPT(agent) {
      // agent.add('Sorry! I am unable to understand this at the moment. I am still learning humans. You can pick any of the service that might help me.');
      const instance = axios.create({
        baseURL: 'https://api.openai.com/v1/',
        headers: { Authorization: `Bearer ${process.env.OPENAI_API_KEY}` },
      });
    
      const dialog = [
        `The following is a conversation with an AI assistant that can have meaningful conversations with users. The assistant is helpful, empathic, and friendly. Its objective is to make the user feel better by feeling heard. With each response, the AI assisstant prompts the user to continue the conversation in a natural way.
AI: Hello, I am your personal mental health AI assistant. How are you doing today?`,
      ];
      let query = agent.query;
      console.log('querytext ', query)
      dialog.push(`User: ${query}`);
      dialog.push('AI:');
      // agent.add(`you said ${query}`)
    
      const completionParmas = {
        prompt: dialog.join('\n'),
        max_tokens: 60,
        temperature: 0.85,
        n: 1,
        stream: false,
        logprobs: null,
        echo: false,
        stop: '\n',
      };
    
      try {
        const result = await instance.post('/engines/davinci/completions', completionParmas);
        const botResponse = result.data.choices[0].text.trim();
        agent.add(botResponse);
      } catch (err) {
        console.log(err);
        agent.add('Sorry. Something went wrong. Can you say that again?');
      }
    
  }
});
const port = 3000;
app.listen(port, () => console.log(`App listening on port ${port}!`))

it speaks only about mental health though (by the way, this is not a trivial thing to play around with )

Is there a way to get curie to speak or at least the generalist davinci?

I am still on free account.

Thank you.

I’ve only ever had a paid account, but I think this should still work for you:

Here’s the API doc that shows you how to use different models.

Essentially you’d just be adding in a new parameter to const completionParmas

model: text-curie-001,

Hi
thank you for your answer.
I have tried the following: const completionParmas = {model: “text-curie-001”,
prompt: dialog.join(‘\n’),
max_tokens: 60,
temperature: 0.85,
n: 1,
stream: false,
logprobs: null,
echo: false,
stop: ‘\n’,
};

but the model stops talking.

here is the complete working therapist code

// mental health 
const express = require("express");
require("actions-on-google")
// require('dotenv').config();
const axios = require('axios');
const { WebhookClient } = require("dialogflow-fulfillment");
const app = express();
app.post("/dialogflow", express.json(), (req, res) => {
    const agent = new WebhookClient({ request: req, response: res });
    let intentMap = new Map();
    intentMap.set("Default Welcome Intent", welcome);
    intentMap.set("Default Fallback Intent", queryGPT);
    agent.handleRequest(intentMap);
  
    function welcome(agent) {
      agent.add('Hi');
  }
  
  async function queryGPT(agent) {
      // agent.add('Sorry! I am unable to understand this at the moment. I am still learning humans. You can pick any of the service that might help me.');
      const instance = axios.create({
        baseURL: 'https://api.openai.com/v1/',
        headers: { Authorization: `Bearer ${process.env.OPENAI_API_KEY}` },
      });
    
      const dialog = [
        `The following is a conversation with an AI assistant that can have meaningful conversations with users. The assistant is helpful, empathic, and friendly. Its objective is to make the user feel better by feeling heard. With each response, the AI assisstant prompts the user to continue the conversation in a natural way.
AI: Hello, I am your personal mental health AI assistant. How are you doing today?`,
      ];
      let query = agent.query;
      console.log('querytext ', query)
      dialog.push(`User: ${query}`);
      dialog.push('AI:');
      // agent.add(`you said ${query}`)
    
      const completionParmas = {
        prompt: dialog.join('\n'),
        max_tokens: 60,
        temperature: 0.85,
        n: 1,
        stream: false,
        logprobs: null,
        echo: false,
        stop: '\n',
      };
    
      try {
        const result = await instance.post('/engines/davinci/completions', completionParmas);
        const botResponse = result.data.choices[0].text.trim();
        agent.add(botResponse);
      } catch (err) {
        console.log(err);
        agent.add('Sorry. Something went wrong. Can you say that again?');
      }
    
  }
});
const port = 3000;
app.listen(port, () => console.log(`App listening on port ${port}!`))
Davinci can’t not be a therapist ;)

This is correct. All GPT models (at this point in time in the technology maturity cycle) should NOT be used as “therapists”, “doctors providing advice” , etc.

These GPT Chatbots are powerful “autocompletion engines” which predict language, not too dissimilar to your text auto-completion feature in some of your apps when you type.

They are not AI expert systems and nor should they be used as expert systems.

Everything “technical” or “critical” which is generated by these OpenAI GPT models MUST be validated and confirmed.

This fact is also in the T&Cs of OpenAI, BTW.

Still, the responses the above code prompts are strictly in shrink register, and it is not clear which line is setting this up that way.
help would be much appreciated.

No luck so far.
Hint: hit control+c anytime to enter REPL.
App listening on port 3000!
querytext test
/home/runner/nodeonreplit/index.js:38
model: text-curie-001,
^

ReferenceError: text is not defined
at queryGPT (/home/runner/nodeonreplit/index.js:38:16)
at WebhookClient.handleRequest (/home/runner/nodeonreplit/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:313:44)
at /home/runner/nodeonreplit/index.js:13:11
at Layer.handle [as handle_request] (/home/runner/nodeonreplit/node_modules/express/lib/router/layer.js:95:5)
at next (/home/runner/nodeonreplit/node_modules/express/lib/router/route.js:144:13)
at /home/runner/nodeonreplit/node_modules/body-parser/lib/read.js:137:5
at AsyncResource.runInAsyncScope (node:async_hooks:203:9)
at invokeCallback (/home/runner/nodeonreplit/node_modules/raw-body/index.js:231:16)
at done (/home/runner/nodeonreplit/node_modules/raw-body/index.js:220:7)

Node.js v18.12.1
repl process died unexpectedly: exit status 1

(To exit, press Ctrl+C again or Ctrl+D or type .exit)

I have tried text-davinci001, as well as 2 and 3. 001 does not get any answers, 002 returns the above error and 003 the same.