Skip to content

Commit

Permalink
Merge pull request #132 from MervinPraison/develop
Browse files Browse the repository at this point in the history
streaming subprocess working
  • Loading branch information
MervinPraison authored Aug 5, 2024
2 parents 7498069 + ecdaa2e commit b82d314
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:3.11-slim
WORKDIR /app
COPY . .
RUN pip install flask praisonai==0.0.59rc7 gunicorn markdown
RUN pip install flask praisonai==0.0.59rc8 gunicorn markdown
EXPOSE 8080
CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]
2 changes: 1 addition & 1 deletion docs/api/praisonai/deploy.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ <h2 id="raises">Raises</h2>
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.59rc7 gunicorn markdown\n&#34;)
file.write(&#34;RUN pip install flask praisonai==0.0.59rc8 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;)

Expand Down
2 changes: 1 addition & 1 deletion praisonai.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Praisonai < Formula

desc "AI tools for various AI applications"
homepage "https://github.com/MervinPraison/PraisonAI"
url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/0.0.59rc7.tar.gz"
url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/0.0.59rc8.tar.gz"
sha256 "1828fb9227d10f991522c3f24f061943a254b667196b40b1a3e4a54a8d30ce32" # Replace with actual SHA256 checksum
license "MIT"

Expand Down
19 changes: 13 additions & 6 deletions praisonai/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,22 @@
except ImportError:
GRADIO_AVAILABLE = False

def stream_subprocess(command):
def stream_subprocess(command, env=None):
"""
Execute a subprocess command and stream the output to the terminal in real-time.
Args:
command (list): A list containing the command and its arguments.
env (dict, optional): Environment variables for the subprocess.
"""
process = subprocess.Popen(
command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
bufsize=1,
universal_newlines=True
universal_newlines=True,
env=env
)

for line in iter(process.stdout.readline, ''):
Expand Down Expand Up @@ -148,19 +150,24 @@ def main(self):

try:
result = subprocess.check_output(['conda', 'env', 'list'])
if 'unsloth_env' in result.decode('utf-8'):
print("Conda environment 'unsloth_env' found.")
if 'prasion_env' in result.decode('utf-8'):
print("Conda environment 'prasion_env' found.")
else:
raise subprocess.CalledProcessError(1, 'grep')
except subprocess.CalledProcessError:
print("Conda environment 'unsloth_env' not found. Setting it up...")
print("Conda environment 'prasion_env' not found. Setting it up...")
from praisonai.setup.setup_conda_env import main as setup_conda_main
setup_conda_main()
print("All packages installed.")

train_args = sys.argv[2:] # Get all arguments after 'train'
train_script_path = os.path.join(package_root, 'train.py')
stream_subprocess(['conda', 'run', '--name', 'unsloth_env', 'python', train_script_path, 'train'])

# Set environment variables
env = os.environ.copy()
env['PYTHONUNBUFFERED'] = '1'

stream_subprocess(['conda', 'run', '--no-capture-output', '--name', 'prasion_env', 'python', '-u', train_script_path, 'train'] + train_args, env=env)
return

invocation_cmd = "praisonai"
Expand Down
2 changes: 1 addition & 1 deletion praisonai/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def create_dockerfile(self):
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.59rc7 gunicorn markdown\n")
file.write("RUN pip install flask praisonai==0.0.59rc8 gunicorn markdown\n")
file.write("EXPOSE 8080\n")
file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')

Expand Down
2 changes: 1 addition & 1 deletion praisonai/setup/setup_conda_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ else
fi

# Create and activate the Conda environment
ENV_NAME="unsloth_env"
ENV_NAME="prasion_env"
if conda info --envs | grep -q $ENV_NAME; then
echo "Environment $ENV_NAME already exists. Recreating..."
conda env remove -y -n $ENV_NAME # Remove existing environment
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "PraisonAI"
version = "0.0.59rc7"
version = "0.0.59rc8"
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 = ""
Expand Down

0 comments on commit b82d314

Please sign in to comment.