Skip to content

Instantly share code, notes, and snippets.

@ScytheDraven47
Created May 11, 2023 06:56
Show Gist options
  • Save ScytheDraven47/f70cc4b2b3453b864ef51b46392e844f to your computer and use it in GitHub Desktop.
Save ScytheDraven47/f70cc4b2b3453b864ef51b46392e844f to your computer and use it in GitHub Desktop.
Gist Created in Script Kit
// 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