How to integrate chatGpt from openAi to CRM system with vue js - vue.js

My boss wants to integrate ChatGPT from OpenAI into the CRM system we are building, so he gave me an API key. What he wanted was to use ChatGpt to become a chatbot for the system. For example, the chatbot will ask the customer for information and input it into the CRM, among other things.
I tried the one that ChatGpt sent me, which is a sent request to their API, but the problem is that the user will be the one asking the question and not the chat bot.
`async getResponseFromAPI() {
const prompt = this.request
const response = await axios.post(
'https://api.openai.com/v1/engines/davinci/completions',
{
prompt,
max_tokens: 265,
n: 1,
temperature: 0.5,
top_p: 1,
frequency_penalty: 0.0,
presence_penalty: 0.6,
stop: [" Human:", " AI:"]
},
{
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer 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'
}
}
);
this.response = response.data.choices[0].text;
}`
tried this but the response are abit not what i wanted

Related

Upload a file to an IPFS node from Google Apps Script

I'm trying to upload a file to an IPFS node using Google Apps Script (GAS) without success.
However, I was able to upload a file successfully using Postman. Unfortunately Postman only gives back the source code snippet closest to GAS as a JavaScript - Fetch code, which is not working as is in GAS.
In GAS, the authentication part is working and I know that because if I'm changing the bearer token, then I'm getting invalid credentials error instead of "Invalid request format".
Test code attached where I'm getting the "Invalid request format" error from the server.
For testing purpose, the file which needs to be uploaded, could be created on the fly with the script, but has to be one from Google Drive eventually.
function test() {
let myHeaders = {'Authorization': 'Bearer ...'};
let fileBlob = Utilities.newBlob('Hello!', 'text/plain', 'TestFile.txt');
let formdata = {'file': fileBlob,
'pinataMetadata': {'name': 'TestFileNewName.txt','keyvalues': {'MetaData1': 'Test1', 'MetaData2': 'Test2'}},
'pinataOptions': {'cidVersion': 0}};
let requestOptions = {
method: 'post',
headers: myHeaders,
papyload: formdata,
muteHttpExceptions: true
};
let url = "https://api.pinata.cloud/pinning/pinFileToIPFS";
let response = UrlFetchApp.fetch(url, requestOptions);
let responeText = JSON.parse(response.getContentText());
Logger.log(responeText);
}
If your access token of Bearer ... is the valid value for using the API, how about the following modification? From the official document, I thought that in the case of your formdata, the values of pinataMetadata and pinataOptions might be required to be the string type.
From:
let formdata = {'file': fileBlob,
'pinataMetadata': {'name': 'TestFileNewName.txt','keyvalues': {'MetaData1': 'Test1', 'MetaData2': 'Test2'}},
'pinataOptions': {'cidVersion': 0}};
To:
let formdata = {
'file': fileBlob,
'pinataMetadata': JSON.stringify({ 'name': 'TestFileNewName.txt', 'keyvalues': { 'MetaData1': 'Test1', 'MetaData2': 'Test2' } }),
'pinataOptions': JSON.stringify({ 'cidVersion': 0 })
};
And also, please modify papyload: formdata, to payload: formdata,. This has already been mentioned by
TheMaster's comment.
References:
Pin File
fetch(url, params)

People api of People.get doesn't get names, photos for other user

Dear Google People API developers,
I am using https://developers.google.com/people/api/rest/v1/people/get api, but it couldn't get other user information of names, photos and etc., using resourceName="people/account_id".
But I could get my profile information of names, photos and etc when I use resourceName="people/me"
I have also tried both web and flutter, it is the same result.
{
"resourceName": "people/110971898718679553920",
"etag": "%EgYBAgMuNz0aBAECBQc=",
"photos": [
{
"metadata": {
"primary": true,
"source": {
"type": "PROFILE",
"id": "110971898718679553920"
}
},
"url": "https://lh3.googleusercontent.com/a-/AOh14GgB8WckrOhYHm-R_Y6hugAEu7XxQ-ktNsmzYUQW=s100",
"default": true
}
]
}
How can I get that information?
My code sample as below
Calling people API by library
Future<Person> getPersonDetails(String peopleId) async {
final GoogleAuthClient googleAuthClient =
await GoogleProvider.provideGoogleAuthClient();
final PeopleServiceApi peopleServiceApi =
peopleDataProvider.getPeopleApi(googleAuthClient);
Person person = await peopleServiceApi.people
.get(peopleId, personFields: '(names,photos,urls,emailAddresses)');
return person;
}
Calling People API by HttpClient
Future<http.Response> getByPeopleAPI(String accountId) async {
GoogleSignInAccount googleSignInAccount =
await GoogleProvider.provideGoogleSignInAccount();
GoogleSignInAuthentication googleSignInAuthentication =
await googleSignInAccount.authentication;
http.Client _client = http.Client();
_client.get(
Uri.parse(
"https://people.googleapis.com/v1/$accountId?personFields=names,photos"),
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': 'Bearer ${googleSignInAuthentication.accessToken}',
},
).then((value) {
print(value?.body.toString());
});
}
Note: I got people/account_id from google activity API's of actor attribute.
I am looking forward to your support and reply.
Thank you very much in advance!
I've noticed this too in a few parts of the newer People API. The people.listDirecory endpoint seems broken. The older deprecated olderContacts.list works better but is deprecated.
Oddly enough people.searchDirectoryPeople works as expected and shows every field in readMask but you need to provide a search (no wildcard option apparently). Calling people.listDirectoryPeople with exactly the same readMask omits most fields. I'm not sure if there's a different scope required for people.listDirectoryPeople or what but it seems there's definitely something wrong with this api as documented - unless someone can point out another doc we're missing somewhere?

HTTP Response Error with Post to LinkedIn using Share API v2

I am trying to post a Share to LinkedIn using OAuth v2 - I have got authorisation correctly and have the appropriate access keys.
This code is supposed to share a link on LinkedIn, but for some reason it's not working - I'm not sure why. Can anyone help?
this is my request body:
{
"distribution": {
"linkedInDistributionTarget": {}
},
"owner": "urn:li:person:XXXXXX",
"subject": "Test Share Subject",
"text": {
"text": "Hello !"
}
And this my call API shares :
publishPostLink(body : any, token : any){
this.headers = new HttpHeaders(
{
'Content-Type': 'application/json',
'Authorization':'Bearer '+token,
'cache-control': 'no-cache',
'X-Restli-Protocol-Version':'2.0.0', });
return this.http.post("https://api.linkedin.com/v2/shares" , body, {headers: this.headers});}
I get this issue:
I've already installed the Moesif CORS and it didn't worked
I fixed the error using this post..
it should use REST API from the backend and not from frontend
http://localhost is an insecure request origin so its not supportted in many cases.
Try using tunneling software like Ngork https://ngrok.com/

Github API v3, post issues / authentication

I am working on a project making a Kanban board using the Github API v3.
I have no problem with get methods, but when it comes to post methods i get a 404 response, and from what i read in the documentation, this seems to be a authentication error.
I am using personal token for authentication, and have successfully posted through postman, but when i try to post through my own application i get the error.
Link to project if anyone's interested : https://github.com/ericyounger/Kanban-Electron
Below is the code used for posting to github.
Might there be a problem with my code below? Or might it be settings in relation with the token?
postIssue(json){
let packed = this.packPost(json);
return Axios.post(`https://api.github.com/repos/${this.user}/${this.repo}/issues`, packed);
}
packPost(json) {
return {
method: "POST",
headers: {
"Authorization": `token ${this.tokenAuth}`,
"Content-Type": "application/json"
},
body: JSON.stringify({title: json.title})
};
}
This is what i receive:
{message: "Not Found", documentation_url: "https://developer.github.com/v3/issues/#create-an-issue"}
message: "Not Found"
documentation_url: "https://developer.github.com/v3/issues/#create-an-issue"
Console log error message
Without seeing any detailed logs, my first attempt would be to set body to not send the string representation of the body
body: {title: json.title}
This did the trick :)
postIssue(json){
const headers = {
'Content-Type': 'application/json',
'Accept': 'application/vnd.github.v3.raw',
"Authorization": `token ${this.tokenAuth}`,
};
return Axios.post(`https://api.github.com/repos/${this.user}/${this.repo}/issues`, json , {headers: headers});
}

Getting Code 400 using Dialogflow on API request

this is my very first time using Dialogflow, so probably my mistake is very stupid.
here is my problem:
1) I created a sample agent "small-talk'.
2) I enabled the Webhook in the fulfilment section. I setup the URL of the web server making the request and the auth (username, password) of the that web server.
3) I uploaded a simple webpage on that web server with an API request that looks like this one below (this is the sample json referenced in their guide):
axios({
method: 'POST',
url: 'https://api.dialogflow.com/v1/query?v=20150910',
headers: {
'Authorization': 'Bearer ad7829588896432caa8940a291b66f84',
'Content-Type': 'application/json',
},
body: {
"contexts": [
"shop"
],
"lang": "en",
"query": "I need apples",
"sessionId": "12345",
"timezone": "America/New_York"
}
})
.then((response) => {
console.log(response);
})
.catch((error) => {
console.log(error);
})
I keep getting this error:
Cannot parse json. Please validate your json. Code: 400"
The only thing I can thing of, is that I noticed that Dialogflow is now working with the API V2 enabled by default in the agent settings and it seems there is no selection to V1 available anymore. But maybe this has nothing to do with my problem.
Thanks in advance!
Solved it!
In the json request, instead of
body: {...}
I replaced it with
data: {...}
Probably it was obvious, but I am an absolute newbie on these things!
By the way, Google has shutdown Dialogflow V1 starting from 12th July 2021 as per this URL - https://cloud.google.com/dialogflow/docs/release-notes#June_15_2021
In case you are getting http response code 400 (bad request), it means that it is time to migrate :-)