Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google That #22

Closed
appatalks opened this issue Mar 31, 2023 · 2 comments
Closed

Google That #22

appatalks opened this issue Mar 31, 2023 · 2 comments

Comments

@appatalks
Copy link
Owner

Not sure if this is where I like it... May revisit:

chatgpt-turbo.js

// Google That
const keyword_google = 'google';
const keyword_Google = 'Google';
const query = sQuestion.replace(/google|Google/g, '').trim();

let googleContents; 
if (sQuestion.includes(keyword_google) || sQuestion.includes(keyword_Google)) {

const apiUrl = `https://www.googleapis.com/customsearch/v1?key=${GOOGLE_SEARCH_KEY}&cx=${GOOGLE_SEARCH_ID}&q=${encodeURIComponent(query)}`;
    fetch(apiUrl)
	      .then(response => response.json())
	      .then(data => {
  	  	 // googleContents = data.items.map(item => item.title);
	 googleContents = data.items.map(item => {
	   return {
		     title: item.title,
		     link: item.link
	   };
	 });
             newMessages.push({ role: 'user', content: "Google search results for " + query + ": " + JSON.stringify(googleContents) + sQuestion.replace(/\n/g, '') });

  		// Append the new messages to the existing messages in localStorage
      	let existingMessages = JSON.parse(localStorage.getItem("messages")) || [];
  		existingMessages = existingMessages.concat(newMessages);
      	localStorage.setItem("messages", JSON.stringify(existingMessages));

		// Retrieve messages from local storage
	    var cStoredMessages = localStorage.getItem("messages");
	    kMessages = cStoredMessages ? JSON.parse(cStoredMessages) : [];

		// API Payload
	    var data = {
	        model: sModel,
	        messages: kMessages,
	        max_tokens: iMaxTokens,
	        temperature:  dTemperature,
	        frequency_penalty: eFrequency_penalty,
	        presence_penalty: cPresence_penalty,
	        stop: hStop
	    }

	    // Sending API Payload
	    oHttp.send(JSON.stringify(data));
	    // console.log("chatgpt-turbo.js Line 232" + JSON.stringify(data));

	    // Relay Send to Screen
	    if (txtOutput.value != "") txtOutput.value += "\n";
	    txtOutput.value += "You: " + sQuestion;
	    txtMsg.value = "";
				      });
	return;
	}
@appatalks
Copy link
Owner Author

Like this part:

         newMessages.push({ role: 'user', content: "Google search results for " + query + ": " + JSON.stringify(googleContents) + sQuestion.replace(/\n/g, '') });

a) Not sure if using the query and the question here make sense.
b) I couldn't get it to quite work right if I didn't replicate the API call outside the others, like weather, date, etc.

@appatalks
Copy link
Owner Author

Happy with state for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant