Skip to content

Commit cec33d6

Browse files
Merge pull request #123 from MervinPraison/develop
adding .praisoninclude and .praisoncontext
2 parents 31ab502 + 59160e1 commit cec33d6

File tree

10 files changed

+229
-114
lines changed

10 files changed

+229
-114
lines changed

.praisoncontext

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# praisonai/ui/context.py
2+
# /Users/praison/miniconda3/envs/praisonai-package/lib/python3.11/site-packages/llama_index/packs/code_hierarchy/code_hierarchy.py

.praisoninclude

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
#praisonai
1+
# praisonai/ui/context.py
2+
# /Users/praison/miniconda3/envs/praisonai-package/lib/python3.11/site-packages/llama_index/packs/code_hierarchy/code_hierarchy.py

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.57 gunicorn markdown
4+
RUN pip install flask praisonai==0.0.58 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.57 gunicorn markdown\n&#34;)
113+
file.write(&#34;RUN pip install flask praisonai==0.0.58 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: 93 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -132,17 +132,36 @@ <h2 class="section-title" id="header-classes">Classes</h2>
132132
return modified_ignore_patterns
133133

134134
def get_include_paths(self):
135+
&#34;&#34;&#34;
136+
Loads include paths from:
137+
1. .praisoninclude (includes ONLY files/directories listed)
138+
2. .praisoncontext (if .praisoninclude doesn&#39;t exist, this is used
139+
to include all other relevant files, excluding ignore patterns)
140+
&#34;&#34;&#34;
135141
include_paths = []
136-
137-
# 1. Load from .praisoninclude
138-
include_file = os.path.join(self.directory, &#39;.praisoninclude&#39;)
142+
include_all = False # Flag to indicate if we need to include all files
143+
144+
include_file = os.path.join(self.directory, &#39;.praisoncontext&#39;)
139145
if os.path.exists(include_file):
140146
with open(include_file, &#39;r&#39;) as f:
141147
include_paths.extend(
142148
line.strip() for line in f
143149
if line.strip() and not line.startswith(&#39;#&#39;)
144150
)
145-
return include_paths
151+
152+
# If .praisoncontext doesn&#39;t exist, fall back to .praisoninclude
153+
# for including all relevant files
154+
if not include_paths:
155+
include_file = os.path.join(self.directory, &#39;.praisoninclude&#39;)
156+
if os.path.exists(include_file):
157+
with open(include_file, &#39;r&#39;) as f:
158+
include_paths.extend(
159+
line.strip() for line in f
160+
if line.strip() and not line.startswith(&#39;#&#39;)
161+
)
162+
include_all = True # Include all files along with specified paths
163+
164+
return include_paths, include_all
146165

147166
def should_ignore(self, file_path):
148167
&#34;&#34;&#34;
@@ -165,61 +184,78 @@ <h2 class="section-title" id="header-classes">Classes</h2>
165184
any(file_path.endswith(ext) for ext in self.relevant_extensions)
166185

167186
def gather_context(self):
168-
&#34;&#34;&#34;Gather context from relevant files, respecting ignore patterns and include paths.&#34;&#34;&#34;
187+
&#34;&#34;&#34;
188+
Gather context from relevant files, respecting ignore patterns
189+
and include options from .praisoninclude and .praisoncontext.
190+
&#34;&#34;&#34;
169191
context = []
170192
total_files = 0
171193
processed_files = 0
194+
self.include_paths, include_all = self.get_include_paths()
172195

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
196+
def add_file_content(file_path):
197+
&#34;&#34;&#34;Helper function to add file content to context.&#34;&#34;&#34;
198+
try:
199+
with open(file_path, &#39;r&#39;, encoding=&#39;utf-8&#39;) as f:
200+
content = f.read()
201+
context.append(
202+
f&#34;File: {file_path}\n\n{content}\n\n{&#39;=&#39; * 50}\n&#34;
203+
)
204+
self.included_files.append(
205+
Path(file_path).relative_to(self.directory)
206+
)
207+
except Exception as e:
208+
logger.error(f&#34;Error reading {file_path}: {e}&#34;)
209+
210+
def process_path(path):
211+
&#34;&#34;&#34;Helper function to process a single path (file or directory).&#34;&#34;&#34;
212+
nonlocal total_files, processed_files
213+
if os.path.isdir(path):
214+
for root, dirs, files in os.walk(path):
215+
total_files += len(files)
216+
dirs[:] = [
217+
d
218+
for d in dirs
219+
if not self.should_ignore(os.path.join(root, d))
220+
]
221+
for file in files:
222+
file_path = os.path.join(root, file)
223+
if not self.should_ignore(file_path) and self.is_relevant_file(file_path):
224+
add_file_content(file_path)
225+
processed_files += 1
226+
print(
227+
f&#34;\rProcessed {processed_files}/{total_files} files&#34;,
228+
end=&#34;&#34;,
229+
flush=True,
230+
)
231+
elif os.path.isfile(path) and self.is_relevant_file(path):
232+
add_file_content(path)
233+
processed_files += 1
234+
print(
235+
f&#34;\rProcessed {processed_files}/1 files&#34;,
236+
end=&#34;&#34;,
237+
flush=True,
238+
)
239+
240+
if include_all:
241+
# Include ALL relevant files from the entire directory
242+
process_path(self.directory)
243+
244+
# Include files from .praisoninclude specifically
192245
for include_path in self.include_paths:
193246
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):
211-
try:
212-
with open(full_path, &#39;r&#39;, encoding=&#39;utf-8&#39;) as f:
213-
content = f.read()
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))
216-
except Exception as e:
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)
247+
process_path(full_path)
248+
elif self.include_paths:
249+
# Include only files specified in .praisoncontext
250+
for include_path in self.include_paths:
251+
full_path = os.path.join(self.directory, include_path)
252+
process_path(full_path)
253+
else:
254+
# No include options, process the entire directory
255+
process_path(self.directory)
220256

221257
print() # New line after progress indicator
222-
return &#39;\n&#39;.join(context)
258+
return &#34;\n&#34;.join(context)
223259

224260
def count_tokens(self, text):
225261
&#34;&#34;&#34;Count tokens using a simple whitespace-based tokenizer.&#34;&#34;&#34;
@@ -282,7 +318,8 @@ <h3>Methods</h3>
282318
<span>def <span class="ident">gather_context</span></span>(<span>self)</span>
283319
</code></dt>
284320
<dd>
285-
<div class="desc"><p>Gather context from relevant files, respecting ignore patterns and include paths.</p></div>
321+
<div class="desc"><p>Gather context from relevant files, respecting ignore patterns
322+
and include options from .praisoninclude and .praisoncontext.</p></div>
286323
</dd>
287324
<dt id="praisonai.ui.context.ContextGatherer.get_context_tree"><code class="name flex">
288325
<span>def <span class="ident">get_context_tree</span></span>(<span>self)</span>
@@ -306,7 +343,10 @@ <h3>Methods</h3>
306343
<span>def <span class="ident">get_include_paths</span></span>(<span>self)</span>
307344
</code></dt>
308345
<dd>
309-
<div class="desc"></div>
346+
<div class="desc"><p>Loads include paths from:
347+
1. .praisoninclude (includes ONLY files/directories listed)
348+
2. .praisoncontext (if .praisoninclude doesn't exist, this is used
349+
to include all other relevant files, excluding ignore patterns)</p></div>
310350
</dd>
311351
<dt id="praisonai.ui.context.ContextGatherer.is_relevant_file"><code class="name flex">
312352
<span>def <span class="ident">is_relevant_file</span></span>(<span>self, file_path)</span>

docs/ui/code.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ PraisonAI Code helps you to interact with your whole codebase using the power of
2020
- [Using settings.yaml](#using-settingsyaml)
2121
- [Using .env File](#using-env-file)
2222
- [Using Environment Variables in the Terminal](#using-environment-variables-in-the-terminal)
23-
- [Include Files](#include-files)
23+
- [Include Files](#include-files-praisoninclude)
2424
- [Set Max Tokens](#set-max-tokens)
2525

2626
## Install PraisonAI Code
@@ -114,11 +114,10 @@ PRAISONAI_IGNORE_FILES=".*,*.pyc,__pycache__,.git,.gitignore,.vscode"
114114
export PRAISONAI_IGNORE_FILES=".*,*.pyc,__pycache__,.git,.gitignore,.vscode"
115115
```
116116

117-
## Include Files
117+
## Include Files .praisoninclude
118118

119119
- Add files you wish to Include files in the context
120-
- This will automatically ignore all the ignore files option
121-
- This will include only the files/folders mentioned in `.praisoninclude` to the context
120+
- This will include the files/folders mentioned in `.praisoninclude` to the original context (files in the folder - .gitignore - .praisonignore)
122121

123122
* Create a `.praisoninclude` file in the root folder of the project
124123
* Add files to Include
@@ -128,6 +127,19 @@ projectfiles
128127
docs
129128
```
130129

130+
## Include ONLY these Files .praisoncontext (Context)
131+
132+
- Add files you wish to Include files in the context
133+
- This will include ONLY the files/folders mentioned in `.praisoncontext` to the context
134+
135+
* Create a `.praisoncontext` file in the root folder of the project
136+
* Add files to Include
137+
138+
```bash
139+
projectfiles
140+
docs
141+
```
142+
131143
## Set Max Tokens
132144

133145
Note: By Default Max Tokens set is 900,000
@@ -142,4 +154,8 @@ or
142154
* Add below Variables and required Max Tokens
143155
* ```
144156
PRAISONAI_MAX_TOKENS=1000000
145-
```
157+
```
158+
159+
## Default DB Location
160+
161+
`~/.praison/database.sqlite`

praisonai.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Praisonai < Formula
2+
include Language::Python::Virtualenv
3+
4+
desc "AI tools for various AI applications"
5+
homepage "https://github.com/MervinPraison/PraisonAI"
6+
url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/0.0.58.tar.gz"
7+
sha256 "1828fb9227d10f991522c3f24f061943a254b667196b40b1a3e4a54a8d30ce32" # Replace with actual SHA256 checksum
8+
license "MIT"
9+
10+
depends_on "[email protected]"
11+
12+
def install
13+
virtualenv_install_with_resources
14+
end
15+
16+
test do
17+
system "#{bin}/praisonai", "--version"
18+
end
19+
end
20+

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.57 gunicorn markdown\n")
59+
file.write("RUN pip install flask praisonai==0.0.58 gunicorn markdown\n")
6060
file.write("EXPOSE 8080\n")
6161
file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')
6262

0 commit comments

Comments
 (0)