Created
May 11, 2023 06:56
-
-
Save ScytheDraven47/f70cc4b2b3453b864ef51b46392e844f to your computer and use it in GitHub Desktop.
Gist Created in Script Kit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Name: Ask Bard | |
// Shortcode: bard | |
import '@johnlindquist/kit' | |
import { Bard } from 'googlebard' | |
const bardCookie = await env('BARD_COOKIE', { | |
hint: md( | |
`Log in to [https://bard.google.com](https://bard.google.com) then retrieve your "__Secure-1PSID" cookie from your browser's Developer Tools -> Storage tab` | |
), | |
}) | |
const { conversationNames, write } = await db('ask-bard-conversation-names', { | |
conversationNames: [], | |
}) | |
const conversationId = await arg( | |
{ | |
placeholder: 'Select a conversation', | |
strict: false, | |
shortcuts: [ | |
{ | |
name: 'Skip', | |
key: 'ctrl+enter', | |
onPress: () => submit(null), | |
bar: 'right', | |
}, | |
], | |
}, | |
conversationNames | |
) | |
if (conversationId) { | |
if (!conversationNames.includes(conversationId)) { | |
conversationNames.push(conversationId) | |
write() | |
} | |
} | |
const bot = new Bard(`__Secure-1PSID=${bardCookie}`) | |
await chat({ | |
name: `Ask Bard - ${conversationId || 'tmp'}`, | |
onSubmit: async (prompt) => { | |
let response | |
if (conversationId) { | |
response = await bot.ask(prompt, conversationId) | |
} else { | |
response = await bot.ask(prompt) | |
} | |
chat.addMessage(response) | |
}, | |
}) | |
// Simulating response streaming | |
// await bot.askStream( | |
// (res) => { | |
// inspect(res, 'ask-bard-response-stream') | |
// }, | |
// prompt, | |
// conversationId | |
// ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment