Skip to content

Commit 68c76b8

Browse files
committed
Python Examples for Context SDK
1 parent 7e6a4c0 commit 68c76b8

File tree

22 files changed

+2978
-0
lines changed

22 files changed

+2978
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Context Examples
2+
3+
Examples demonstrating the Auggie SDK's context modes and AI-powered code analysis.
4+
5+
## Prerequisites
6+
7+
1. **Python 3.9+** - Required to run the examples
8+
2. **Auggie CLI** - Required for FileSystem Context examples
9+
```bash
10+
pip install auggie
11+
# or
12+
npm install -g @augmentcode/auggie
13+
```
14+
3. **Authentication** - Required for all examples
15+
```bash
16+
auggie login
17+
```
18+
This creates a session file at `~/.augment/session.json` with your API token.
19+
20+
Alternatively, you can set environment variables:
21+
```bash
22+
export AUGMENT_API_TOKEN=your_token_here
23+
export AUGMENT_API_URL=https://staging-shard-0.api.augmentcode.com/
24+
```
25+
26+
## Examples
27+
28+
### [Direct Context](./direct_context/)
29+
API-based indexing with semantic search and AI Q&A.
30+
31+
**Run it:**
32+
```bash
33+
python direct_context/main.py
34+
```
35+
36+
### [FileSystem Context](./filesystem_context/)
37+
Local directory search via MCP protocol.
38+
39+
**Important:** The FileSystem Context indexes all files in the workspace directory. To avoid timeouts when indexing large directories (like `node_modules/`), consider adding a `.gitignore` or `.augmentignore` file that excludes them. The auggie CLI respects both `.gitignore` and `.augmentignore` patterns during indexing.
40+
41+
**Run it:**
42+
```bash
43+
python filesystem_context/main.py
44+
```
45+
46+
### [File Search Server](./file_search_server/)
47+
REST API for semantic file search with AI summarization.
48+
49+
**Run it:**
50+
```bash
51+
python file_search_server/main.py [workspace-directory]
52+
```
53+
54+
Then query the API:
55+
```bash
56+
curl "http://localhost:3000/search?q=python"
57+
```
58+
59+
### [Prompt Enhancer Server](./prompt_enhancer_server/)
60+
HTTP server that enhances prompts with codebase context.
61+
62+
**Run it:**
63+
```bash
64+
python prompt_enhancer_server/main.py [workspace-directory]
65+
```
66+
67+
Then enhance prompts:
68+
```bash
69+
curl -X POST http://localhost:3001/enhance \
70+
-H "Content-Type: application/json" \
71+
-d '{"prompt": "fix the login bug"}'
72+
```
73+
74+
### [GitHub Action Indexer](./github_action_indexer/)
75+
Index GitHub repositories for semantic search.
76+
77+
This example has its own requirements.txt and dependencies.
78+
79+
**Setup:**
80+
```bash
81+
cd github_action_indexer
82+
pip install -r requirements.txt
83+
```
84+
85+
**Run it:**
86+
```bash
87+
python src/main.py
88+
python src/search.py "your query"
89+
```
90+
91+
See [github_action_indexer/README.md](./github_action_indexer/README.md) for more details.
92+
93+
## Troubleshooting
94+
95+
### MCP Timeout in FileSystem Context
96+
97+
**Problem:** The FileSystem Context example times out during indexing.
98+
99+
**Cause:** The workspace directory contains too many files (e.g., `node_modules/` with 45,000+ files).
100+
101+
**Solution:** Create a `.gitignore` or `.augmentignore` file in the workspace directory to exclude large directories:
102+
103+
```bash
104+
# .gitignore or .augmentignore
105+
node_modules/
106+
dist/
107+
*.log
108+
.DS_Store
109+
__pycache__/
110+
*.pyc
111+
```
112+
113+
The auggie CLI respects both `.gitignore` and `.augmentignore` patterns and will skip excluded files during indexing.
114+
115+
### Authentication Errors
116+
117+
**Problem:** `Error: API key is required for search_and_ask()`
118+
119+
**Cause:** The SDK cannot find your authentication credentials.
120+
121+
**Solution:** Run `auggie login` to authenticate, or set the `AUGMENT_API_TOKEN` and `AUGMENT_API_URL` environment variables.
122+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Direct Context Example
2+
3+
API-based indexing with semantic search, AI Q&A, and state persistence.
4+
5+
## Usage
6+
7+
```bash
8+
# Authenticate
9+
auggie login
10+
11+
# Run the example
12+
python examples/context/direct_context/main.py
13+
```
14+
15+
## What It Does
16+
17+
- Creates a Direct Context instance
18+
- Adds sample files to the index
19+
- Performs semantic searches
20+
- Uses `search_and_ask()` for AI-powered Q&A
21+
- Generates documentation
22+
- Exports/imports context state
23+
24+
## Key Features
25+
26+
- **`search()`**: Semantic search returning formatted code snippets
27+
- **`search_and_ask()`**: One-step AI Q&A about indexed code
28+
- **State persistence**: Export/import index for reuse
29+

0 commit comments

Comments
 (0)