Skip to content

Commit 1a21823

Browse files
committed
fix: README and index
1 parent 21f9fd9 commit 1a21823

File tree

6 files changed

+24
-52
lines changed

6 files changed

+24
-52
lines changed

index.bson.br

325 Bytes
Binary file not shown.

snippets/ai/README.md

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,32 @@
1-
# LLM Command Snippet
1+
# AI Command Snippets
22

3-
This snippet adds an `llm` command to mongosh that provides helpful suggestions or recommendations for MongoDB-related tasks. The query results are generated using Groq API by default, with an option to use other models via Ollama.
3+
> [!CAUTION]
4+
> This is an experimental, early-stage snippet that is not meant for production use.
45
5-
## Prerequisites
6+
This snippet adds a suite of commands accessible with the `ai` command. This includes:
67

7-
```
8-
export GROQ_API_KEY=gsk_XXXXXXX
9-
mongosh
10-
```
11-
12-
## Usage
13-
14-
After installing the snippet, you can use the `llm` command in your MongoDB shell like this:
15-
16-
```javascript
17-
llm("very briefly, just the command, do not use markdown: in mongosh how to get the collections names of current db?");
18-
```
19-
20-
This will output a possible solution to your query, such as `db.getCollectionNames()`.
21-
22-
```javascript
23-
llm("very briefly, just the command, do not use markdown: in mongosh replace all documents of a collection with property {'set':'llm102'} with the new value {'set':'llm101'} in current db?")
24-
```
25-
26-
This will output a possible solution to your query, such as `db.collection.updateMany({ set: 'llm102' }, { $set: { set: 'llm101' } })`.
27-
28-
You can also specify a different model to use with an optional parameter:
29-
```javascript
30-
llm("Your query here", { model: "phi3.5" });
31-
```
32-
This will use the specified model (in this case, 'phi3.5') via Ollama instead of the default Groq API.
33-
34-
## Models
35-
36-
By default, the `llm` command uses the Groq API with the 'llama-3.1-70b-versatile' model. You can use other models by specifying them in the optional parameter:
37-
38-
- Groq API (default): No need to specify, just use `llm("Your query")`.
39-
- Ollama models: Specify the model name, e.g., `llm("Your query", { model: "gemini2" })` or `llm("Your query", { model: "phi3.5" })`.
40-
41-
Note: When using Ollama models, make sure you have Ollama running locally on the default port (11434).
8+
| | | |
9+
|---------|-------------|---------|
10+
| `ai.ask` | Ask questions about MongoDB | `ai.ask how do I run queries in mongosh?` |
11+
| `ai.data` | Generate data-related mongosh commands | `ai.data insert some sample user info` |
12+
| `ai.query` | Generate a MongoDB query | `ai.query find documents where name = "Ada"` |
13+
| `ai.aggregate` | Generate a MongoDB aggregation | `ai.aggregate find documents where name = "Ada"` |
14+
| `ai.collection` | Set the active collection | `ai.collection("users")` |
15+
| `ai.shell` | Generate general mongosh commands | `ai.shell get sharding info` |
16+
| `ai.general` | Ask general questions to your model | `ai.general what is the meaning of life?`
17+
| `ai.config` | Configure the AI commands | `ai.config.set("provider", "ollama")` |
4218

19+
This currently supports 5 different AI providers: `docs, openai | mistral | atlas | ollama` and any model they support. For cloud providers, you can specify the API key with `MONGOSH_AI_API_KEY`.
4320

4421
## Installation
4522

4623
You can install this snippet using the `snippet` command in mongosh:
4724

4825
```javascript
49-
snippet install llm-command
26+
config.set('snippetIndexSourceURLs',
27+
'https://github.com/gagik/mongosh-snippets/raw/refs/heads/ai/index.bson.br;'
28+
+ config.get('snippetIndexSourceURLs') )
29+
snippet install ai
5030
```
5131

5232
## Troubleshooting

snippets/ai/globals.d.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

snippets/ai/helpers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export class LoadingAnimation {
4949
}
5050

5151
export interface CliContext {
52+
ai: unknown;
5253
db: {
5354
_mongo: {
5455
_instanceState: {

snippets/ai/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Config, ConfigSchema } from './config';
77
import { CliContext, wrapAllFunctions } from './helpers';
88
import chalk from 'chalk';
99

10+
1011
class AI {
1112
private readonly replConfig: {
1213
set: (key: string, value: any) => Promise<void>;
@@ -161,6 +162,5 @@ class AI {
161162
}
162163
}
163164

164-
module.exports = (globalThis: any) => {
165-
globalThis.ai = new AI(globalThis);
166-
};
165+
166+
(globalThis as unknown as CliContext).ai = new AI(globalThis as unknown as CliContext);

snippets/ai/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"esModuleInterop": true,
99
"skipLibCheck": true,
1010
"forceConsistentCasingInFileNames": true,
11-
"types": ["./globals.d.ts", "node"],
11+
"types": ["node"],
1212
},
1313
"include": ["index.ts"],
1414
"exclude": ["node_modules", "dist"]

0 commit comments

Comments
 (0)