mirror of
https://github.com/MervinPraison/PraisonAI.git
synced 2026-11-09 03:39:37 -10:00
Changing the default DB location
This commit is contained in:
1 parent
1ea77d30e3
commit
6250c19f07
8 files changed
+98
-27
No files matched your search
+1
-1
@@ -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"]
|
||||
@@ -110,7 +110,7 @@ Loads environment variables from .env file or system and sets them.</p>
|
||||
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')
|
||||
|
||||
|
||||
@@ -68,10 +68,12 @@ hljs.highlightAll();
|
||||
self.max_file_size = max_file_size
|
||||
self.max_tokens = int(os.getenv("PRAISONAI_MAX_TOKENS", max_tokens))
|
||||
self.ignore_patterns = self.get_ignore_patterns()
|
||||
self.include_paths = self.get_include_paths()
|
||||
self.included_files = []
|
||||
|
||||
def get_ignore_patterns(self):
|
||||
"""
|
||||
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"Final ignore patterns: {modified_ignore_patterns}")
|
||||
return modified_ignore_patterns
|
||||
|
||||
def get_include_paths(self):
|
||||
include_paths = []
|
||||
|
||||
# 1. Load from .praisoninclude
|
||||
include_file = os.path.join(self.directory, '.praisoninclude')
|
||||
if os.path.exists(include_file):
|
||||
with open(include_file, 'r') as f:
|
||||
include_paths.extend(
|
||||
line.strip() for line in f
|
||||
if line.strip() and not line.startswith('#')
|
||||
)
|
||||
return include_paths
|
||||
|
||||
def should_ignore(self, file_path):
|
||||
"""
|
||||
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):
|
||||
"""Gather context from relevant files, respecting ignore patterns."""
|
||||
"""Gather context from relevant files, respecting ignore patterns and include paths."""
|
||||
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, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
context.append(f"File: {file_path}\n\n{content}\n\n{'='*50}\n")
|
||||
self.included_files.append(Path(file_path).relative_to(self.directory))
|
||||
except Exception as e:
|
||||
logger.error(f"Error reading {file_path}: {e}")
|
||||
processed_files += 1
|
||||
print(f"\rProcessed {processed_files}/{total_files} files", end="", 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, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
context.append(f"File: {file_path}\n\n{content}\n\n{'='*50}\n")
|
||||
self.included_files.append(Path(file_path).relative_to(self.directory))
|
||||
except Exception as e:
|
||||
logger.error(f"Error reading {file_path}: {e}")
|
||||
processed_files += 1
|
||||
print(f"\rProcessed {processed_files}/{total_files} files", end="", flush=True)
|
||||
elif os.path.isfile(full_path) and self.is_relevant_file(full_path):
|
||||
try:
|
||||
with open(file_path, 'r', encoding='utf-8') as f:
|
||||
with open(full_path, 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
context.append(f"File: {file_path}\n\n{content}\n\n{'='*50}\n")
|
||||
context.append(f"File: {full_path}\n\n{content}\n\n{'='*50}\n")
|
||||
self.included_files.append(Path(full_path).relative_to(self.directory))
|
||||
except Exception as e:
|
||||
logger.error(f"Error reading {file_path}: {e}")
|
||||
processed_files += 1
|
||||
print(f"\rProcessed {processed_files}/{total_files} files", end="", flush=True)
|
||||
logger.error(f"Error reading {full_path}: {e}")
|
||||
processed_files += 1
|
||||
print(f"\rProcessed {processed_files}/{total_files} files", end="", flush=True)
|
||||
|
||||
print() # New line after progress indicator
|
||||
return '\n'.join(context)
|
||||
|
||||
def count_tokens(self, text):
|
||||
"""Count tokens using a simple whitespace-based tokenizer."""
|
||||
return len(text.split())
|
||||
return len(text.split())
|
||||
|
||||
def truncate_context(self, context):
|
||||
"""Truncate context to stay within the token limit."""
|
||||
@@ -199,12 +248,9 @@ hljs.highlightAll();
|
||||
contents = sorted(path.iterdir())
|
||||
pointers = [('└── ' if i == len(contents) - 1 else '├── ') 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"{prefix}{pointer}{rel_path}")
|
||||
if rel_path in self.included_files:
|
||||
tree.append(f"{prefix}{pointer}{rel_path}")
|
||||
|
||||
if item.is_dir():
|
||||
add_to_tree(item, prefix + (' ' if pointer == '└── ' else '│ '))
|
||||
@@ -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
@@ -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
@@ -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')
|
||||
|
||||
|
||||
@@ -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('''
|
||||
|
||||
@@ -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
@@ -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 = ""
|
||||
|
||||
Reference in new issue
Block a user