Skip to content

Conversation

@gagik
Copy link

@gagik gagik commented May 20, 2025

One can install this snippet using the snippet command in mongosh:

# Set your snippet sources
config.set('snippetIndexSourceURLs',  'https://github.com/gagik/mongosh-snippets/raw/refs/heads/ai/index.bson.br;' + config.get('snippetIndexSourceURLs'))
# Restart mongosh for the change to take effect.
# Install the ai snippet
snippet install ai
# Run `ai` to out the commands!
ai

@gagik gagik marked this pull request as draft May 20, 2025 11:31
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep in mind that this package-lock file has no practical effect 🙂

@gagik gagik marked this pull request as ready for review November 12, 2025 11:45
@gagik
Copy link
Author

gagik commented Nov 12, 2025

This isn't ready to merged, pending better alignment with product, but feel free to try it out!

return text;
}

async processResponse(
Copy link
Author

@gagik gagik Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be worth adding a basic "locking" mechanism to prevent something like

for (var i = 0; i < 10; i++) { ai.ask("what is mongosh?") } 

That said I also find the idea of something like const a = ai.generate("sample document") function quite cool, albeit as thing stands pretty wasteful

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't fully discount this as an option, with a local model this would actually be pretty much just fine, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that said if they're using their own API key, it also poses a risk of accidentally getting them to spend a lot of money.
I can turn this into a configurable option and have it set to only 1 request at a time by default.

# AI Snippets for mongosh

> [!CAUTION]
> This is an experimental, early-stage snippet that is not meant for production use.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, this is kind of true for all snippets we have

/** @internal */
respond(text: string) {
this.thinking.stop();
process.stdout.write(text);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a ticket in mongosh to provide stdin, stdout, stderr streams in mongosh instead of having snippets work with process.* directly? mongosh is generally built in a way where it's not necessarily true that the streams that mongosh reads from and writes to are the process-wide stdio streams, and I'd prefer not to hardcode that expectation in snippets if we don't need to

return text;
}

async processResponse(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't fully discount this as an option, with a local model this would actually be pretty much just fine, right?

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

Successfully merging this pull request may close these issues.

3 participants