File size: 3,491 Bytes
762ef74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24923c7
762ef74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24923c7
 
762ef74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# full.llama.cpp.agent.python

# πŸ¦™ LLaMA Local AI Agent

A **fully offline**, powerful, and extendable AI agent that runs **LLaMA 3/gguf models locally** via `llama.cpp`. Supports **Chat, Document Q&A, Vision (OCR + Image Captioning), Voice (STT & TTS)**, and **Tools** like Python exec, browser search, and email generation β€” all from your machine.

---

## 🧠 Features

- πŸ” LLaMA-3 / GGUF Models (Runs Locally via `llama.cpp`)
- πŸ’¬ Chat Interface with History & Token Auth
- πŸ“„ File Upload + Document Q&A (TXT/PDF)
- 🧰 Tools: Calculator, Python Exec, Joke, Web Search
- πŸ–ΌοΈ Image Captioning + OCR
- πŸ—£οΈ Voice Transcription (Whisper) + Text-to-Speech (TTS)
- πŸ” JWT Auth for Admin/Users
- πŸ“œ Chat Export with Embedding Search
- πŸ“Š Agent Analytics & Logs
- 🧭 ReAct / LangGraph Planning (Coming Soon)

---

## πŸš€ Quick Start

```bash
git clone https://github.com/yourusername/llama-agent
cd llama-agent
docker-compose up --build
```

Then go to `http://localhost:8501` to access the Streamlit UI.

---

## 🧩 Architecture

- `main_api.py`: FastAPI backend (chat, tools, auth, vector store)
- `streamlit_app.py`: Rich UI frontend
- `llama.cpp`: LLM inference backend via `llama_cpp` Python bindings
- `whisper`, `pyttsx3`: Voice STT/TTS
- `duckduckgo_search`, `playwright`: Web tools
- `faiss`, `sentence-transformers`: Vector search
- `PDFMiner`, `Pillow`, `Tesseract`: PDF/Image Processing

---

## πŸ“Έ Screenshots

<p align="center">
  <img src="screenshots/agent-ui.png" width="600" />
  <img src="screenshots/chat-demo.png" width="600" />
</p>

---

## πŸ”§ Tools

### Tool Dispatch Logic

```python
from app.repl_tool import run_code
from app.email_tool import send_email
from app.translation_tool import translate
from app.vision import describe_image

def tool_dispatch(command, args):
    if command == "run_code":
        return run_code(args)
    if command == "send_email":
        return send_email(*args)
    if command == "translate":
        return translate(args)
    if command == "describe_image":
        return describe_image(args)
    return "❌ Unknown command"
```

---

## πŸ› οΈ Logging

```python
import logging

logging.basicConfig(
    filename="agent.log",
    level=logging.INFO,
    format="%(asctime)s | %(levelname)s | %(message)s",
)

def log_event(event: str):
    logging.info(event)
```

---

## πŸ“€ Email Tool

```python
from email.message import EmailMessage
import smtplib, ssl

EMAIL_SENDER = "[email protected]"
EMAIL_PASSWORD = "yourpassword"

def generate_email(recipient_name: str, product_name: str, discount: float):
    return f"""
    Dear {recipient_name},

    Great news! We're excited to offer you a special {discount}% discount on our premium product: {product_name}.

    Visit our site to take advantage of this limited-time offer.

    Best regards,
    Your AI Assistant
    """

def send_email(to, subject, body):
    msg = EmailMessage()
    msg.set_content(body)
    msg["Subject"] = subject
    msg["From"] = EMAIL_SENDER
    msg["To"] = to

    with smtplib.SMTP_SSL("smtp.gmail.com", 465, context=ssl.create_default_context()) as smtp:
        smtp.login(EMAIL_SENDER, EMAIL_PASSWORD)
        smtp.send_message(msg)
    return "βœ… Email sent"
```

---

## πŸ“ License

MIT License β€” Open-source, feel free to extend it.

---

## πŸ™ Credits

- [`llama.cpp`](https://github.com/ggerganov/llama.cpp)
- [`whisper`](https://github.com/openai/whisper)
- [`Streamlit`](https://streamlit.io)