GPT-3 gives strange text response [closed] - openai-api

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 9 days ago.
Improve this question
I'm using the code exactly as it is in the tutorial and the text response I always get back is " text: 'package com.example.demo.controller;' "
This is my code, has anyone ever seen this issue?
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
const completion = await openai.createCompletion({
model: "text-davinci-002",
prompt: "Hello world",
});
console.log(completion.data.choices[0].text);

I tried your code and I was getting a similar response.
You are using a previous generation model text-davinici-002. This model is less reliable than the latest model.
You would be better using the latest model text-davinici-003. This is the model that powers ChatGPT (with some other fine-tuning).
When I ran your code using the latest model I got the following response:
Hello, world! Welcome to the world of programming.

Related

Scraping a website returns an unexpected empty value in Node.JS [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I am trying to scrape a player count on a website but my code keeps returning empty. What did I do wrong?
I'm trying to scrape this website: https://www.game-state.com/193.203.39.13:7777/ and the value I want to console.log is Players: x/1000
setInterval(function() {
var url = 'https://www.game-state.com/193.203.39.13:7777/';
request(url, function(err, response, body) {
var $ = cheerio.load(body);
var players = $('.value #players');
var playersText = players.text();
console.log(playersText);
})
}, 300)
Your selector is wrong.
You are selecting any tag with ID players that is inside of a tag with class value. What you want is both checks on the same element. The issue is the space between .value and #players - remove it: .value#players.
A tip: Try it in your browser first... go to the page, open devtools, enter document.querySelector('.value #players') - you'll see it comes back empty. With .value#players it works.
But, since an ID is supposed to be unique, just the ID #players would suffice anyway.

This is my app I need to understand some models issue and want to understand how it work with frontend (MeanStack) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am using two models for my app here are the models
var mongoose=require("mongoose");
var Schema = mongoose.Schema;
var schema = new Schema({
content:{type:String, required:true},
user:{type:mongoose.Types.Objectid, ref:'User'}
});
module.exports=mongoose.model('message',schema);
var mongoose=require("mongoose");
var Schema = mongoose.Schema;
var schema = new Schema({
firstName:{type:String,required:true},
lastName:{type:String,required:true},
password:{type:String,required:true},
email:{type:String, required:true,unique:true},
});
My two questions are as follow:
1 As for the Schema for every field like firstName I make it required: true So When I use Postman if I don't provide the firstName I will get an error that field required. My question is this can anyone give me a little snippet from the front end if I do not provide the firstname it will give me an error but wait this required is on the back end so how can I get the error on frontend if I don't provide the firstname.
2 Actually what I am doing that when some user sends a message so I get his message and from User collection, I get his id name and last name using reference I know how to do it with postman but I am actually confused about how I can do it from frontend using angular2+. Can anyone help me in this regard providing me with a little front end interface or some code snippet with some explanation which can do this operation?
so it looks like you're probably a bit new to full-stack development, no worries both of these are quite straight forward.
Validation of fields in the frontend and backend
You should be validating input on both the frontend and the backend. On the frontend, you can make use of Angular to check if a field is null or empty, or even run regex checks to see if it's the valid format you expect. How you do this will greatly depend on what your frontend HTML is like. If you want further advise on this I'd suggest opening a new question specifically to address this on the frontend. However, you will find many answers if you just search Stackoverflow for "angular 7 validate input".
To validate on the backend, you will likely want some code that sits inside your express.js endpoint handler. You can check the value that comes through the body, do any checks against it. If it passes then continue on to create your database record, if it doesn't then return an error. If your application is sufficiently large you may also wish to run checks closer to your database models but for now validating at the edge may get you far enough if it's a very small application.
Here is an example of the sort of express.js validation you might use:
router.post("/message", (req, res, next) => {
if (!req.body.firstName) {
return res.status(400).json({error: "a meaningful error message"});
}
// The validation has passed, do whatever you want now
});
Frontend HTTP requests in angular 2+
Making a HTTP call in angular 2 is reasonably straight forward and the documentation provides a full guide on making http calls which I would suggest following.
If you have specific questions or issues with it then feel free to come back and open another question, but since you've not provided the code of your current attempt it's hard to give an answer which will fit your code.

How promises work in Typescript - I have error in mysql [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I'm working in an Angular 8.3 app with Node 10.17 and Mysql.
When I try to send information in JSON to the Backend I got an error in promises and I don't know what to do.
I've already investigated and I can't find the error
My code
In Angular Component.TS
async entrar(): Promise<void>
{
const datosJSON = JSON.stringify(
{
NombreP: "Fulanito",
ApellidoPa: "Perengano",
ApellidoMa: "merengano",
Calle: "ejemplo",
Numero: "9235",
Colonia: "ejemplo",
Municipio: "ejemplo",
CP: new Number(1234),
NumSeg: "595625634",
FechaNacimiento: "1234-56-78"
}
);
console.log(datosJSON)
await this.http.post('http://localhost:3000/alumnos/persona', datosJSON ).subscribe((data) =>{
this.datos= data;
console.log(this.datos);
})
}
Welcome to StackOVerflow!
The more details you give, the more accurate the answers you get.
I'm seeing a lot of misconceptions here:
You should not JSON.stringify your object, because then you'll be converting your object into a string. Usually in the POST request you just send the object as it is or in some other scenarios you can create a FormData
Observables are not Promises
You are not returning anything and certainly not a Promise.
Don't subscribe on your Service, if you really really need a promise here, consider:
return this.http.post('http://localhost:3000/alumnos/persona', datosJSON).toPromise()
Probably you don't need async/await here
this.datos = await this.http.post('http://localhost:3000/alumnos/persona', datosJSON ).toPromise();
In your case the data variable inside the subscribe method is returned when the observable is converted to Promise and awaited

The Sails.js controller action is called twice during every HTTP request [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I wrote the following example controller using Sails.js:
userController.js
module.exports = {
test: function(req, res){
console.log('test')
res.json('test')
}
};
When I run sails.js and send it to that route (user/test), it appears to execute that code twice and outputs test twice in my WebStorm debug window:
"test"
"test"
How do I keep Sails.js from executing the same code twice?
I couldn't reproduce your issue. I tried really hard to reproduce it.
I created the same controller you have in your question, and I ran the code -- but not in WebStorm, I ran it from the command line. Since you're using console.log("test"), I should be able to see the console output test twice if your code is doing what you're saying it's doing, however, I couldn't get that to happen:
As you can see from the screenshot, the console output test once, and the webbrowser output a response of test, which exactly matches the code you've given:
module.exports = {
test: function(req, res){
console.log('test') //output test to console
res.json('test') //output test to the response
}
};
I can't reproduce the issue as you've shown it; and there's no indication that controller is getting executed twice.

syntax error unexpected string [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have difficulty to solve this string problem
contentString = '<div id="infoHead">Drag me for new coordinates.</br></div>'+results[1].formatted_address+'<div id="latlng">'+
'Latitude: '+dmsLat+'</br>'+'Longitude: '+dmsLng+'</div>'+'</br>'+'<a href="//www.youtube.com/embed/Mzja4le8htk"'
+ 'style="width=420px; height=315px"'
+ 'onclick=' + '"window.open(this.href,'rockclimbing','left=400,top=250,width=420,height=315,toolbar=1,resizable=0');return false;"'
+ '>Click here for more details</a>'
For example through this code:
'"window.open(this.href,'rockclimbing','left=400,top=250,width=420,height=315,toolbar=1,resizable=0');return false;"'
it's show some error where rockclimbing and start from left until sizeable=0 cannot put single quatotion.
So how to solve this problem?
I can't provide the link since this is my second project. Any kind of help I'm really appreciated.
You need to escape the inner quotes:
'"window.open(this.href,\'rockclimbing\',\'left=400,top=250,width=420,height=315,toolbar=1,resizable=0\');return false;"'
Otherwise the single quote before rockclimbing terminates the string.
I will show you how to find your errors.
I am only including our example up to the first error.
As you move this piece into your environment this error should go away, provided
results[1].formatted_address
can be converted to a string.
Move in more and more of your original code as you fix your errors.
Good Luck!
Code Wrapped in Exception Handler for Error Reporting
try {
contentString = '<div id="infoHead">Drag me for new coordinates.</br></div>'
+results[1].formatted_address;
} catch(exception) {
console.log(exception.stack);
}
Console Log Output for Error Diagnosis
ReferenceError: results is not defined
at <anonymous>:2:84
at Object.InjectedScript._evaluateOn (<anonymous>:580:39)
at Object.InjectedScript._evaluateAndWrap (<anonymous>:539:52)
at Object.InjectedScript.evaluate (<anonymous>:458:21)

Resources