Changing the default DB location

This commit is contained in:
MervinPraison committed 2024-07-21 02:10:20 +01:00
1 parent 1ea77d30e3
commit 6250c19f07
8 files changed
+98 -27

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
FROM python:3.11-slim
WORKDIR /app
COPY . .
RUN pip install flask praisonai==0.0.56 gunicorn markdown
RUN pip install flask praisonai==0.0.57 gunicorn markdown
EXPOSE 8080
CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]
+1 -1
View File
@@ -110,7 +110,7 @@ Loads environment variables from .env file or system and sets them.</p>
file.write(&#34;FROM python:3.11-slim\n&#34;)
file.write(&#34;WORKDIR /app\n&#34;)
file.write(&#34;COPY . .\n&#34;)
file.write(&#34;RUN pip install flask praisonai==0.0.56 gunicorn markdown\n&#34;)
file.write(&#34;RUN pip install flask praisonai==0.0.57 gunicorn markdown\n&#34;)
file.write(&#34;EXPOSE 8080\n&#34;)
file.write(&#39;CMD [&#34;gunicorn&#34;, &#34;-b&#34;, &#34;0.0.0.0:8080&#34;, &#34;api:app&#34;]\n&#39;)
+73 -20
View File
@@ -68,10 +68,12 @@ hljs.highlightAll();
self.max_file_size = max_file_size
self.max_tokens = int(os.getenv(&#34;PRAISONAI_MAX_TOKENS&#34;, max_tokens))
self.ignore_patterns = self.get_ignore_patterns()
self.include_paths = self.get_include_paths()
self.included_files = []
def get_ignore_patterns(self):
&#34;&#34;&#34;
Loads ignore patterns from various sources, prioritizing them in
Loads ignore patterns from various sources, prioritizing them in
the following order:
1. .praisonignore
2. settings.yaml (under code.ignore_files)
@@ -129,6 +131,19 @@ hljs.highlightAll();
logger.debug(f&#34;Final ignore patterns: {modified_ignore_patterns}&#34;)
return modified_ignore_patterns
def get_include_paths(self):
include_paths = []
# 1. Load from .praisoninclude
include_file = os.path.join(self.directory, &#39;.praisoninclude&#39;)
if os.path.exists(include_file):
with open(include_file, &#39;r&#39;) as f:
include_paths.extend(
line.strip() for line in f
if line.strip() and not line.startswith(&#39;#&#39;)
)
return include_paths
def should_ignore(self, file_path):
&#34;&#34;&#34;
Check if a file or directory should be ignored based on patterns.
@@ -150,31 +165,65 @@ hljs.highlightAll();
any(file_path.endswith(ext) for ext in self.relevant_extensions)
def gather_context(self):
&#34;&#34;&#34;Gather context from relevant files, respecting ignore patterns.&#34;&#34;&#34;
&#34;&#34;&#34;Gather context from relevant files, respecting ignore patterns and include paths.&#34;&#34;&#34;
context = []
total_files = 0
processed_files = 0
for root, dirs, files in os.walk(self.directory):
total_files += len(files)
dirs[:] = [d for d in dirs if not self.should_ignore(os.path.join(root, d))]
for file in files:
file_path = os.path.join(root, file)
if not self.should_ignore(file_path) and self.is_relevant_file(file_path):
if not self.include_paths:
# No include paths specified, process the entire directory
for root, dirs, files in os.walk(self.directory):
total_files += len(files)
dirs[:] = [d for d in dirs if not self.should_ignore(os.path.join(root, d))]
for file in files:
file_path = os.path.join(root, file)
if not self.should_ignore(file_path) and self.is_relevant_file(file_path):
try:
with open(file_path, &#39;r&#39;, encoding=&#39;utf-8&#39;) as f:
content = f.read()
context.append(f&#34;File: {file_path}\n\n{content}\n\n{&#39;=&#39;*50}\n&#34;)
self.included_files.append(Path(file_path).relative_to(self.directory))
except Exception as e:
logger.error(f&#34;Error reading {file_path}: {e}&#34;)
processed_files += 1
print(f&#34;\rProcessed {processed_files}/{total_files} files&#34;, end=&#34;&#34;, flush=True)
else:
# Process specified include paths
for include_path in self.include_paths:
full_path = os.path.join(self.directory, include_path)
if os.path.isdir(full_path):
for root, dirs, files in os.walk(full_path):
total_files += len(files)
dirs[:] = [d for d in dirs if not self.should_ignore(os.path.join(root, d))]
for file in files:
file_path = os.path.join(root, file)
if not self.should_ignore(file_path) and self.is_relevant_file(file_path):
try:
with open(file_path, &#39;r&#39;, encoding=&#39;utf-8&#39;) as f:
content = f.read()
context.append(f&#34;File: {file_path}\n\n{content}\n\n{&#39;=&#39;*50}\n&#34;)
self.included_files.append(Path(file_path).relative_to(self.directory))
except Exception as e:
logger.error(f&#34;Error reading {file_path}: {e}&#34;)
processed_files += 1
print(f&#34;\rProcessed {processed_files}/{total_files} files&#34;, end=&#34;&#34;, flush=True)
elif os.path.isfile(full_path) and self.is_relevant_file(full_path):
try:
with open(file_path, &#39;r&#39;, encoding=&#39;utf-8&#39;) as f:
with open(full_path, &#39;r&#39;, encoding=&#39;utf-8&#39;) as f:
content = f.read()
context.append(f&#34;File: {file_path}\n\n{content}\n\n{&#39;=&#39;*50}\n&#34;)
context.append(f&#34;File: {full_path}\n\n{content}\n\n{&#39;=&#39;*50}\n&#34;)
self.included_files.append(Path(full_path).relative_to(self.directory))
except Exception as e:
logger.error(f&#34;Error reading {file_path}: {e}&#34;)
processed_files += 1
print(f&#34;\rProcessed {processed_files}/{total_files} files&#34;, end=&#34;&#34;, flush=True)
logger.error(f&#34;Error reading {full_path}: {e}&#34;)
processed_files += 1
print(f&#34;\rProcessed {processed_files}/{total_files} files&#34;, end=&#34;&#34;, flush=True)
print() # New line after progress indicator
return &#39;\n&#39;.join(context)
def count_tokens(self, text):
&#34;&#34;&#34;Count tokens using a simple whitespace-based tokenizer.&#34;&#34;&#34;
return len(text.split())
return len(text.split())
def truncate_context(self, context):
&#34;&#34;&#34;Truncate context to stay within the token limit.&#34;&#34;&#34;
@@ -199,12 +248,9 @@ hljs.highlightAll();
contents = sorted(path.iterdir())
pointers = [(&#39;└── &#39; if i == len(contents) - 1 else &#39;├── &#39;) for i in range(len(contents))]
for pointer, item in zip(pointers, contents):
# Use should_ignore for consistency
if self.should_ignore(item):
continue
rel_path = item.relative_to(start_dir)
tree.append(f&#34;{prefix}{pointer}{rel_path}&#34;)
if rel_path in self.included_files:
tree.append(f&#34;{prefix}{pointer}{rel_path}&#34;)
if item.is_dir():
add_to_tree(item, prefix + (&#39; &#39; if pointer == &#39;└── &#39; else &#39;│ &#39;))
@@ -236,7 +282,7 @@ hljs.highlightAll();
<span>def <span class="ident">gather_context</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"><p>Gather context from relevant files, respecting ignore patterns.</p></div>
<div class="desc"><p>Gather context from relevant files, respecting ignore patterns and include paths.</p></div>
</dd>
<dt id="praisonai.ui.context.ContextGatherer.get_context_tree"><code class="name flex">
<span>def <span class="ident">get_context_tree</span></span>(<span>self)</span>
@@ -256,6 +302,12 @@ the following order:
4. .gitignore
5. Default patterns</p></div>
</dd>
<dt id="praisonai.ui.context.ContextGatherer.get_include_paths"><code class="name flex">
<span>def <span class="ident">get_include_paths</span></span>(<span>self)</span>
</code></dt>
<dd>
<div class="desc"></div>
</dd>
<dt id="praisonai.ui.context.ContextGatherer.is_relevant_file"><code class="name flex">
<span>def <span class="ident">is_relevant_file</span></span>(<span>self, file_path)</span>
</code></dt>
@@ -316,6 +368,7 @@ Handles both file names and directory names for more comprehensive filtering.</p
<li><code><a title="praisonai.ui.context.ContextGatherer.gather_context" href="#praisonai.ui.context.ContextGatherer.gather_context">gather_context</a></code></li>
<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>
<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>
<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>
<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>
<li><code><a title="praisonai.ui.context.ContextGatherer.run" href="#praisonai.ui.context.ContextGatherer.run">run</a></code></li>
<li><code><a title="praisonai.ui.context.ContextGatherer.save_context" href="#praisonai.ui.context.ContextGatherer.save_context">save_context</a></code></li>
+17 -1
View File
@@ -10,6 +10,21 @@ PraisonAI Code helps you to interact with your whole codebase using the power of
| **Chat** | Chat with 100+ LLMs, single AI Agent | [https://docs.praison.ai/ui/chat](https://docs.praison.ai/ui/chat) |
| **Code** | Chat with entire Codebase, single AI Agent | [https://docs.praison.ai/ui/code](https://docs.praison.ai/ui/code) |
## Table of Contents
- [Install PraisonAI Code](#install-praisonai-code)
- [Other Models](#other-models)
- [To Use Gemini 1.5](#to-use-gemini-15)
- [Ignore Files](#ignore-files)
- [Using .praisonignore](#using-praisonignore)
- [Using settings.yaml](#using-settingsyaml)
- [Using .env File](#using-env-file)
- [Using Environment Variables in the Terminal](#using-environment-variables-in-the-terminal)
- [Include Files](#include-files)
- [Set Max Tokens](#set-max-tokens)
## Install PraisonAI Code
1.
```bash
pip install "praisonai[code]"
@@ -62,7 +77,8 @@ pycache
.env
```
### Using settings.yaml (.praisonignore is preferred)
### Using settings.yaml
(.praisonignore is preferred)
* Create a `settings.yaml` file in the root folder of the project
* Add below Variables and required Ignore Files
+1 -1
View File
@@ -56,7 +56,7 @@ class CloudDeployer:
file.write("FROM python:3.11-slim\n")
file.write("WORKDIR /app\n")
file.write("COPY . .\n")
file.write("RUN pip install flask praisonai==0.0.56 gunicorn markdown\n")
file.write("RUN pip install flask praisonai==0.0.57 gunicorn markdown\n")
file.write("EXPOSE 8080\n")
file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')
+2 -1
View File
@@ -40,9 +40,10 @@ now = utc_now()
create_step_counter = 0
DB_PATH = "threads.db"
DB_PATH = os.path.expanduser("~/.praison/database.sqlite")
def initialize_db():
os.makedirs(os.path.dirname(DB_PATH), exist_ok=True)
conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
cursor.execute('''
+2 -1
View File
@@ -41,9 +41,10 @@ now = utc_now()
create_step_counter = 0
DB_PATH = "threads.db"
DB_PATH = os.path.expanduser("~/.praison/database.sqlite")
def initialize_db():
os.makedirs(os.path.dirname(DB_PATH), exist_ok=True)
conn = sqlite3.connect(DB_PATH)
cursor = conn.cursor()
cursor.execute('''
+1 -1
View File
@@ -1,6 +1,6 @@
[tool.poetry]
name = "PraisonAI"
version = "0.0.56"
version = "0.0.57"
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."
authors = ["Mervin Praison"]
license = ""