Skip to content

Commit 31ab502

Browse files
Merge pull request #114 from MervinPraison/develop
Changing the default DB location
2 parents ec7df62 + 6250c19 commit 31ab502

File tree

8 files changed

+98
-27
lines changed

8 files changed

+98
-27
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM python:3.11-slim
22
WORKDIR /app
33
COPY . .
4-
RUN pip install flask praisonai==0.0.56 gunicorn markdown
4+
RUN pip install flask praisonai==0.0.57 gunicorn markdown
55
EXPOSE 8080
66
CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]

docs/api/praisonai/deploy.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ <h2 id="raises">Raises</h2>
110110
file.write(&#34;FROM python:3.11-slim\n&#34;)
111111
file.write(&#34;WORKDIR /app\n&#34;)
112112
file.write(&#34;COPY . .\n&#34;)
113-
file.write(&#34;RUN pip install flask praisonai==0.0.56 gunicorn markdown\n&#34;)
113+
file.write(&#34;RUN pip install flask praisonai==0.0.57 gunicorn markdown\n&#34;)
114114
file.write(&#34;EXPOSE 8080\n&#34;)
115115
file.write(&#39;CMD [&#34;gunicorn&#34;, &#34;-b&#34;, &#34;0.0.0.0:8080&#34;, &#34;api:app&#34;]\n&#39;)
116116

docs/api/praisonai/ui/context.html

Lines changed: 73 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ <h2 class="section-title" id="header-classes">Classes</h2>
6868
self.max_file_size = max_file_size
6969
self.max_tokens = int(os.getenv(&#34;PRAISONAI_MAX_TOKENS&#34;, max_tokens))
7070
self.ignore_patterns = self.get_ignore_patterns()
71+
self.include_paths = self.get_include_paths()
72+
self.included_files = []
7173

7274
def get_ignore_patterns(self):
7375
&#34;&#34;&#34;
74-
Loads ignore patterns from various sources, prioritizing them in
76+
Loads ignore patterns from various sources, prioritizing them in
7577
the following order:
7678
1. .praisonignore
7779
2. settings.yaml (under code.ignore_files)
@@ -129,6 +131,19 @@ <h2 class="section-title" id="header-classes">Classes</h2>
129131
logger.debug(f&#34;Final ignore patterns: {modified_ignore_patterns}&#34;)
130132
return modified_ignore_patterns
131133

134+
def get_include_paths(self):
135+
include_paths = []
136+
137+
# 1. Load from .praisoninclude
138+
include_file = os.path.join(self.directory, &#39;.praisoninclude&#39;)
139+
if os.path.exists(include_file):
140+
with open(include_file, &#39;r&#39;) as f:
141+
include_paths.extend(
142+
line.strip() for line in f
143+
if line.strip() and not line.startswith(&#39;#&#39;)
144+
)
145+
return include_paths
146+
132147
def should_ignore(self, file_path):
133148
&#34;&#34;&#34;
134149
Check if a file or directory should be ignored based on patterns.
@@ -150,31 +165,65 @@ <h2 class="section-title" id="header-classes">Classes</h2>
150165
any(file_path.endswith(ext) for ext in self.relevant_extensions)
151166

152167
def gather_context(self):
153-
&#34;&#34;&#34;Gather context from relevant files, respecting ignore patterns.&#34;&#34;&#34;
168+
&#34;&#34;&#34;Gather context from relevant files, respecting ignore patterns and include paths.&#34;&#34;&#34;
154169
context = []
155170
total_files = 0
156171
processed_files = 0
157172

158-
for root, dirs, files in os.walk(self.directory):
159-
total_files += len(files)
160-
dirs[:] = [d for d in dirs if not self.should_ignore(os.path.join(root, d))]
161-
for file in files:
162-
file_path = os.path.join(root, file)
163-
if not self.should_ignore(file_path) and self.is_relevant_file(file_path):
173+
if not self.include_paths:
174+
# No include paths specified, process the entire directory
175+
for root, dirs, files in os.walk(self.directory):
176+
total_files += len(files)
177+
dirs[:] = [d for d in dirs if not self.should_ignore(os.path.join(root, d))]
178+
for file in files:
179+
file_path = os.path.join(root, file)
180+
if not self.should_ignore(file_path) and self.is_relevant_file(file_path):
181+
try:
182+
with open(file_path, &#39;r&#39;, encoding=&#39;utf-8&#39;) as f:
183+
content = f.read()
184+
context.append(f&#34;File: {file_path}\n\n{content}\n\n{&#39;=&#39;*50}\n&#34;)
185+
self.included_files.append(Path(file_path).relative_to(self.directory))
186+
except Exception as e:
187+
logger.error(f&#34;Error reading {file_path}: {e}&#34;)
188+
processed_files += 1
189+
print(f&#34;\rProcessed {processed_files}/{total_files} files&#34;, end=&#34;&#34;, flush=True)
190+
else:
191+
# Process specified include paths
192+
for include_path in self.include_paths:
193+
full_path = os.path.join(self.directory, include_path)
194+
if os.path.isdir(full_path):
195+
for root, dirs, files in os.walk(full_path):
196+
total_files += len(files)
197+
dirs[:] = [d for d in dirs if not self.should_ignore(os.path.join(root, d))]
198+
for file in files:
199+
file_path = os.path.join(root, file)
200+
if not self.should_ignore(file_path) and self.is_relevant_file(file_path):
201+
try:
202+
with open(file_path, &#39;r&#39;, encoding=&#39;utf-8&#39;) as f:
203+
content = f.read()
204+
context.append(f&#34;File: {file_path}\n\n{content}\n\n{&#39;=&#39;*50}\n&#34;)
205+
self.included_files.append(Path(file_path).relative_to(self.directory))
206+
except Exception as e:
207+
logger.error(f&#34;Error reading {file_path}: {e}&#34;)
208+
processed_files += 1
209+
print(f&#34;\rProcessed {processed_files}/{total_files} files&#34;, end=&#34;&#34;, flush=True)
210+
elif os.path.isfile(full_path) and self.is_relevant_file(full_path):
164211
try:
165-
with open(file_path, &#39;r&#39;, encoding=&#39;utf-8&#39;) as f:
212+
with open(full_path, &#39;r&#39;, encoding=&#39;utf-8&#39;) as f:
166213
content = f.read()
167-
context.append(f&#34;File: {file_path}\n\n{content}\n\n{&#39;=&#39;*50}\n&#34;)
214+
context.append(f&#34;File: {full_path}\n\n{content}\n\n{&#39;=&#39;*50}\n&#34;)
215+
self.included_files.append(Path(full_path).relative_to(self.directory))
168216
except Exception as e:
169-
logger.error(f&#34;Error reading {file_path}: {e}&#34;)
170-
processed_files += 1
171-
print(f&#34;\rProcessed {processed_files}/{total_files} files&#34;, end=&#34;&#34;, flush=True)
217+
logger.error(f&#34;Error reading {full_path}: {e}&#34;)
218+
processed_files += 1
219+
print(f&#34;\rProcessed {processed_files}/{total_files} files&#34;, end=&#34;&#34;, flush=True)
220+
172221
print() # New line after progress indicator
173222
return &#39;\n&#39;.join(context)
174223

175224
def count_tokens(self, text):
176225
&#34;&#34;&#34;Count tokens using a simple whitespace-based tokenizer.&#34;&#34;&#34;
177-
return len(text.split())
226+
return len(text.split())
178227

179228
def truncate_context(self, context):
180229
&#34;&#34;&#34;Truncate context to stay within the token limit.&#34;&#34;&#34;
@@ -199,12 +248,9 @@ <h2 class="section-title" id="header-classes">Classes</h2>
199248
contents = sorted(path.iterdir())
200249
pointers = [(&#39;└── &#39; if i == len(contents) - 1 else &#39;├── &#39;) for i in range(len(contents))]
201250
for pointer, item in zip(pointers, contents):
202-
# Use should_ignore for consistency
203-
if self.should_ignore(item):
204-
continue
205-
206251
rel_path = item.relative_to(start_dir)
207-
tree.append(f&#34;{prefix}{pointer}{rel_path}&#34;)
252+
if rel_path in self.included_files:
253+
tree.append(f&#34;{prefix}{pointer}{rel_path}&#34;)
208254

209255
if item.is_dir():
210256
add_to_tree(item, prefix + (&#39; &#39; if pointer == &#39;└── &#39; else &#39;│ &#39;))
@@ -236,7 +282,7 @@ <h3>Methods</h3>
236282
<span>def <span class="ident">gather_context</span></span>(<span>self)</span>
237283
</code></dt>
238284
<dd>
239-
<div class="desc"><p>Gather context from relevant files, respecting ignore patterns.</p></div>
285+
<div class="desc"><p>Gather context from relevant files, respecting ignore patterns and include paths.</p></div>
240286
</dd>
241287
<dt id="praisonai.ui.context.ContextGatherer.get_context_tree"><code class="name flex">
242288
<span>def <span class="ident">get_context_tree</span></span>(<span>self)</span>
@@ -256,6 +302,12 @@ <h3>Methods</h3>
256302
4. .gitignore
257303
5. Default patterns</p></div>
258304
</dd>
305+
<dt id="praisonai.ui.context.ContextGatherer.get_include_paths"><code class="name flex">
306+
<span>def <span class="ident">get_include_paths</span></span>(<span>self)</span>
307+
</code></dt>
308+
<dd>
309+
<div class="desc"></div>
310+
</dd>
259311
<dt id="praisonai.ui.context.ContextGatherer.is_relevant_file"><code class="name flex">
260312
<span>def <span class="ident">is_relevant_file</span></span>(<span>self, file_path)</span>
261313
</code></dt>
@@ -316,6 +368,7 @@ <h4><code><a title="praisonai.ui.context.ContextGatherer" href="#praisonai.ui.co
316368
<li><code><a title="praisonai.ui.context.ContextGatherer.gather_context" href="#praisonai.ui.context.ContextGatherer.gather_context">gather_context</a></code></li>
317369
<li><code><a title="praisonai.ui.context.ContextGatherer.get_context_tree" href="#praisonai.ui.context.ContextGatherer.get_context_tree">get_context_tree</a></code></li>
318370
<li><code><a title="praisonai.ui.context.ContextGatherer.get_ignore_patterns" href="#praisonai.ui.context.ContextGatherer.get_ignore_patterns">get_ignore_patterns</a></code></li>
371+
<li><code><a title="praisonai.ui.context.ContextGatherer.get_include_paths" href="#praisonai.ui.context.ContextGatherer.get_include_paths">get_include_paths</a></code></li>
319372
<li><code><a title="praisonai.ui.context.ContextGatherer.is_relevant_file" href="#praisonai.ui.context.ContextGatherer.is_relevant_file">is_relevant_file</a></code></li>
320373
<li><code><a title="praisonai.ui.context.ContextGatherer.run" href="#praisonai.ui.context.ContextGatherer.run">run</a></code></li>
321374
<li><code><a title="praisonai.ui.context.ContextGatherer.save_context" href="#praisonai.ui.context.ContextGatherer.save_context">save_context</a></code></li>

docs/ui/code.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@ PraisonAI Code helps you to interact with your whole codebase using the power of
1010
| **Chat** | Chat with 100+ LLMs, single AI Agent | [https://docs.praison.ai/ui/chat](https://docs.praison.ai/ui/chat) |
1111
| **Code** | Chat with entire Codebase, single AI Agent | [https://docs.praison.ai/ui/code](https://docs.praison.ai/ui/code) |
1212

13+
## Table of Contents
14+
15+
- [Install PraisonAI Code](#install-praisonai-code)
16+
- [Other Models](#other-models)
17+
- [To Use Gemini 1.5](#to-use-gemini-15)
18+
- [Ignore Files](#ignore-files)
19+
- [Using .praisonignore](#using-praisonignore)
20+
- [Using settings.yaml](#using-settingsyaml)
21+
- [Using .env File](#using-env-file)
22+
- [Using Environment Variables in the Terminal](#using-environment-variables-in-the-terminal)
23+
- [Include Files](#include-files)
24+
- [Set Max Tokens](#set-max-tokens)
25+
26+
## Install PraisonAI Code
27+
1328
1.
1429
```bash
1530
pip install "praisonai[code]"
@@ -62,7 +77,8 @@ pycache
6277
.env
6378
```
6479

65-
### Using settings.yaml (.praisonignore is preferred)
80+
### Using settings.yaml
81+
(.praisonignore is preferred)
6682

6783
* Create a `settings.yaml` file in the root folder of the project
6884
* Add below Variables and required Ignore Files

praisonai/deploy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def create_dockerfile(self):
5656
file.write("FROM python:3.11-slim\n")
5757
file.write("WORKDIR /app\n")
5858
file.write("COPY . .\n")
59-
file.write("RUN pip install flask praisonai==0.0.56 gunicorn markdown\n")
59+
file.write("RUN pip install flask praisonai==0.0.57 gunicorn markdown\n")
6060
file.write("EXPOSE 8080\n")
6161
file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')
6262

praisonai/ui/chat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@
4040

4141
create_step_counter = 0
4242

43-
DB_PATH = "threads.db"
43+
DB_PATH = os.path.expanduser("~/.praison/database.sqlite")
4444

4545
def initialize_db():
46+
os.makedirs(os.path.dirname(DB_PATH), exist_ok=True)
4647
conn = sqlite3.connect(DB_PATH)
4748
cursor = conn.cursor()
4849
cursor.execute('''

praisonai/ui/code.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@
4141

4242
create_step_counter = 0
4343

44-
DB_PATH = "threads.db"
44+
DB_PATH = os.path.expanduser("~/.praison/database.sqlite")
4545

4646
def initialize_db():
47+
os.makedirs(os.path.dirname(DB_PATH), exist_ok=True)
4748
conn = sqlite3.connect(DB_PATH)
4849
cursor = conn.cursor()
4950
cursor.execute('''

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "PraisonAI"
3-
version = "0.0.56"
3+
version = "0.0.57"
44
description = "PraisonAI application combines AutoGen and CrewAI or similar frameworks into a low-code solution for building and managing multi-agent LLM systems, focusing on simplicity, customization, and efficient human-agent collaboration."
55
authors = ["Mervin Praison"]
66
license = ""

0 commit comments

Comments
 (0)