File size: 7,820 Bytes
40fd3fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
# API Documentation - Burme-Coder-Max

## Overview

**burme-coder-max** is a Myanmar AI coding agent that provides programming assistance in Burmese language with code examples.

---

## Core Module API

### CoderAgent

Main AI agent for generating coding responses.

```python
from core.agent import CoderAgent

agent = CoderAgent(
    model: str = "gpt-4",           # AI model to use
    temperature: float = 0.7,        # Response creativity
    max_tokens: int = 2048,         # Max response length
    knowledge_dir: Optional[str] = None  # Knowledge base directory
)
```

#### Methods

| Method | Description | Returns |
|--------|-------------|---------|
| `generate_response(instruction, context)` | Generate code response | `Dict` with session_id, response, timestamp |
| `set_system_prompt(prompt)` | Set custom system prompt | `None` |
| `get_trajectory()` | Get conversation for training | `Dict` |
| `save_trajectory(path)` | Save trajectory to file | `None` |
| `reset()` | Reset agent state | `None` |

#### Response Format

```python
{
    "session_id": str,
    "instruction": str,
    "response": str,
    "timestamp": float,
    "model": str
}
```

---

### CodeExecutor

Execute code in various languages.

```python
from core.executor import CodeExecutor

executor = CodeExecutor(
    timeout: int = 30,    # Execution timeout in seconds
    sandbox: bool = True  # Enable sandbox mode
)
```

#### Methods

| Method | Description | Returns |
|--------|-------------|---------|
| `execute(code, language)` | Execute code | `ExecutionResult` |
| `validate_syntax(code, language)` | Check syntax | `Tuple[bool, Optional[str]]` |

#### ExecutionResult

```python
@dataclass
class ExecutionResult:
    success: bool           # Execution success
    output: str            # Execution output
    error: Optional[str]   # Error message
    execution_time: float  # Time taken
```

---

### ResponseValidator

Validate AI generated responses.

```python
from core.validator import ResponseValidator

validator = ResponseValidator()
```

#### Methods

| Method | Description | Returns |
|--------|-------------|---------|
| `validate(response, instruction)` | Validate single response | `ValidationResult` |
| `validate_multiple(responses, instruction)` | Validate multiple | `List[ValidationResult]` |

#### ResponseQuality

```python
class ResponseQuality(Enum):
    EXCELLENT = "excellent"
    GOOD = "good"
    ADEQUATE = "adequate"
    POOR = "poor"
    INVALID = "invalid"
```

---

## Knowledge Module API

### LocalKB

Local knowledge base for markdown files.

```python
from knowledge import LocalKB

kb = LocalKB(base_dir: Optional[str] = None)
```

#### Methods

| Method | Description | Returns |
|--------|-------------|---------|
| `search(query, category)` | Search knowledge | `List[Dict]` |
| `get_content(topic)` | Get topic content | `Optional[str]` |
| `get_all_topics()` | List all topics | `List[str]` |
| `get_random_entry()` | Get random entry | `Optional[Dict]` |

#### Search Result Format

```python
{
    "source": str,      # File name
    "line": int,        # Line number
    "snippet": str,     # Match snippet
    "relevance": float  # Relevance score (0-1)
}
```

---

### WebUpdater

Update knowledge from web sources.

```python
from knowledge import WebUpdater

updater = WebUpdater(cache_dir: Optional[str] = None)
```

#### Methods

| Method | Description | Returns |
|--------|-------------|---------|
| `fetch_content(source)` | Fetch single source | `Optional[str]` |
| `fetch_all()` | Fetch all sources | `Dict[str, str]` |
| `update_markdown_files(path, force)` | Update files | `List[str]` |
| `scrape_url(url, selectors)` | Scrape URL | `Optional[str]` |

---

## Animations Module API

### Spinner

Loading spinner animation.

```python
from animations import Spinner

with Spinner("Loading..."):
    do_something()
```

### ProgressBar

Progress bar for iterations.

```code
from animations import ProgressBar

for i in ProgressBar(range(100), description="Downloading"):
    process(i)
```

### TypingEffect

Typewriter-style text animation.

```python
from animations import TypingEffect

effect = TypingEffect("Hello World", delay=0.05)
effect.animate()
```

### ParticleBurst

Celebration particle effect.

```python
from animations import ParticleBurst

burst = ParticleBurst(count=50)
burst.explode()
```

---

## Thanking Module API

### ThankYou

Simple thank you display.

```python
from ui.thanking import ThankYou

ThankYou.show()                    # Random message
ThankYou.show("Custom message")    # Custom message
ThankYou.show_with_emoji("⭐")     # With emoji
```

### Appreciation

Detailed appreciation display.

```python
from ui.thanking import Appreciation

Appreciation.show(topic="Python")           # With topic
Appreciation.show_banner("Developer")      # Banner style
Appreciation.show_stacked(["Python", "JS"]) # Multiple topics
```

### CreditDisplay

Credits and attribution.

```python
from ui.thanking import CreditDisplay

CreditDisplay.show()       # Full credits
CreditDisplay.show_simple()  # Simple credits
```

---

## CLI Commands API

### ask

```bash
burme-coder ask "instruction" [OPTIONS]

Options:
  --model TEXT       AI model (default: gpt-4)
  --verbose         Verbose output
  --output, -o      Output file
```

### interactive

```bash
burme-coder interactive
```

Interactive commands:
- `exit` - Quit
- `clear` - Clear history
- `history` - Show history
- `help` - Show help
- `/search <query>` - Search knowledge
- `/model <name>` - Switch model
- `/reset` - Reset agent

### train

```bash
burme-coder train --data ./data/trajectories [OPTIONS]

Options:
  --epochs INT      Number of epochs (default: 10)
  --batch-size INT  Batch size (default: 4)
```

### eval

```bash
burme-coder eval --data ./data/trajectories [--verbose]
```

---

## Configuration

### Environment Variables

| Variable | Description | Default |
|----------|-------------|---------|
| `OPENAI_API_KEY` | OpenAI API key | - |
| `ANTHROPIC_API_KEY` | Anthropic API key | - |
| `ANIMATION_SPEED` | Animation delay | 0.05 |
| `ANIMATION_COLOR` | Enable colors | true |
| `CACHE_DIR` | Cache directory | ~/.burme_coder/cache |
| `CACHE_TTL` | Cache TTL (seconds) | 3600 |
| `LOG_LEVEL` | Logging level | INFO |

### .env File

```bash
# Copy from example
cp .env.example .env

# Edit with your settings
nano .env
```

---

## Error Handling

### Common Errors

| Error | Cause | Solution |
|-------|-------|----------|
| `SyntaxError` | Invalid code syntax | Check code syntax |
| `TimeoutError` | Execution timeout | Increase timeout |
| `ImportError` | Missing dependencies | Install requirements |
| `APIError` | API key invalid | Verify API key |

### Error Response Format

```python
{
    "error": {
        "code": str,      # Error code
        "message": str,   # Error message
        "details": dict   # Additional details
    }
}
```

---

## Examples

### Basic Usage

```python
from core.agent import CoderAgent
from core.validator import ResponseValidator

# Initialize
agent = CoderAgent(model="gpt-4")
validator = ResponseValidator()

# Generate response
response = agent.generate_response("Python decorator hta ya")

# Validate
result = validator.validate(response["response"], "decorator")
print(f"Quality: {result.quality.value}")
```

### With Animations

```python
from core.agent import CoderAgent
from animations import Spinner

with Spinner("Generating response..."):
    agent = CoderAgent()
    response = agent.generate_response("test")
```

### With Knowledge Base

```python
from core.agent import CoderAgent
from knowledge import LocalKB

kb = LocalKB()
results = kb.search("python decorators")

agent = CoderAgent(knowledge_dir="./data/knowledge")
response = agent.generate_response("decorator")
```