Adding the Run function and restructure folder

This commit is contained in:
MervinPraison committed 2024-07-11 21:38:16 +01:00
1 parent 42ea5bb786
commit 2f4ad10e44
19 files changed
+343 -94

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.45 gunicorn markdown
RUN pip install flask praisonai==0.0.46 gunicorn markdown
EXPOSE 8080
CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]
+79 -59
View File
@@ -13,6 +13,11 @@
Praison AI, leveraging both AutoGen and CrewAI or any other agent framework, represents a low-code, centralised framework designed to simplify the creation and orchestration of multi-agent systems for various LLM applications, emphasizing ease of use, customization, and human-agent interaction.
| | Cookbook | Open in Colab |
| --- | --- | --- |
| Basic | PraisonAI | <a target="_blank" href="https://colab.research.google.com/github/MervinPraison/PraisonAI/blob/main/cookbooks/praisonai-googlecolab.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> |
| Include Tools | PraisonAI Tools | <a target="_blank" href="https://colab.research.google.com/github/MervinPraison/PraisonAI/blob/main/cookbooks/praisonai-tools-googlecolab.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a> |
## TL;DR
```bash
pip install praisonai
@@ -21,6 +26,22 @@ praisonai --init create a movie script about dog in moon
praisonai
```
## Table of Contents
- [Installation](#installation)
- [Initialise](#initialise)
- [Run](#run)
- [Full Automatic Mode](#full-automatic-mode)
- [User Interface](#user-interface)
- [Praison AI Chat](#praison-ai-chat)
- [Create Custom Tools](#create-custom-tools)
- [Agents Playbook](#agents-playbook)
- [Include praisonai package in your project](#include-praisonai-package-in-your-project)
- [Commands to Install Dev Dependencies](#commands-to-install-dependencies)
- [Other Models](#other-models)
- [Contributing](#contributing)
- [Star History](#star-history)
## Installation
```bash
@@ -88,29 +109,26 @@ or
python -m praisonai ui
```
## Praison AI Chat
* https://docs.praison.ai/chat/
```bash
pip install "praisonai[chat]"
export OPENAI_API_KEY="Enter your API key"
praisonai chat
```
## Create Custom Tools
### TL;DR to Create a Custom Tool
* https://docs.praison.ai/tools/custom/
```bash
pip install praisonai duckduckgo-search
export OPENAI_API_KEY="Enter your API key"
praisonai --init research about the latest AI News and prepare a detailed report
```
- Add `- InternetSearchTool` in the agents.yaml file in the tools section.
- Create a file called tools.py and add this code [tools.py](./tools.py)
```bash
praisonai
```
### Pre-requisite to Create a Custom Tool
### Step 1: Pre-requisite to Create a Custom Tool
`agents.yaml` file should be present in the current directory.
If it doesn't exist, create it by running the command `praisonai --init research about the latest AI News and prepare a detailed report`.
### Step 1 to Create a Custom Tool
### Step 2: to Create a Custom Tool
Create a file called tools.py in the same directory as the agents.yaml file.
@@ -129,7 +147,7 @@ class InternetSearchTool(BaseTool):
return results
```
### Step 2 to Create a Custom Tool
### Step 3: to Create a Custom Tool
Add the tool to the agents.yaml file as show below under the tools section `- InternetSearchTool`.
@@ -168,37 +186,63 @@ roles:
expected_output: 'Complete script ready for production.'
```
## Use 100+ Models
* https://docs.praison.ai/models/
## Include praisonai package in your project
* https://docs.praison.ai/developers/wrapper
* https://docs.praison.ai/developers/wrapper-tools/
## Option 1: Using RAW YAML
```python
from praisonai import PraisonAI
# Example agent_yaml content
agent_yaml = """
framework: "crewai"
topic: "Space Exploration"
roles:
astronomer:
role: "Space Researcher"
goal: "Discover new insights about {topic}"
backstory: "You are a curious and dedicated astronomer with a passion for unraveling the mysteries of the cosmos."
tasks:
investigate_exoplanets:
description: "Research and compile information about exoplanets discovered in the last decade."
expected_output: "A summarized report on exoplanet discoveries, including their size, potential habitability, and distance from Earth."
"""
# Create a PraisonAI instance with the agent_yaml content
praison_ai = PraisonAI(agent_yaml=agent_yaml)
# Run PraisonAI
result = praison_ai.main()
# Print the result
print(result)
```
## Option 2: Using separate agents.yaml file
Note: Please create agents.yaml file before hand.
```python
from praisonai import PraisonAI
def basic(): # Basic Mode
praison_ai = PraisonAI(agent_file="agents.yaml")
praison_ai.main()
def advanced(): # Advanced Mode with options
praison_ai = PraisonAI(
agent_file="agents.yaml",
framework="autogen",
)
praison_ai.main()
def auto(): # Full Automatic Mode
praison_ai = PraisonAI(
auto="Create a movie script about car in mars",
framework="autogen"
)
print(praison_ai.framework)
praison_ai.main()
if __name__ == "__main__":
basic()
advanced()
auto()
```
### Commands to Install Dependencies:
## Commands to Install Dependencies:
1. **Install all dependencies, including dev dependencies:**
```sh
@@ -222,30 +266,6 @@ if __name__ == "__main__":
This configuration ensures that your development dependencies are correctly categorized and installed as needed.
## Other Models
```bash
# Ollama
OPENAI_API_BASE='http://localhost:11434/v1'
OPENAI_MODEL_NAME='mistral'
OPENAI_API_KEY='NA'
# FastChat
OPENAI_API_BASE="http://localhost:8001/v1"
OPENAI_MODEL_NAME='oh-2.5m7b-q51'
OPENAI_API_KEY=NA
# LM Studio
OPENAI_API_BASE="http://localhost:1234/v1"
OPENAI_MODEL_NAME=NA
OPENAI_API_KEY=NA
# Mistral API
OPENAI_API_BASE=https://api.mistral.ai/v1
OPENAI_MODEL_NAME="mistral-small"
OPENAI_API_KEY=your-mistral-api-key
```
## Contributing
- Fork on GitHub: Use the "Fork" button on the repository page.
File renamed without changes.
+244
View File
@@ -0,0 +1,244 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"gpuType": "T4"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU"
},
"cells": [
{
"cell_type": "code",
"source": [
"!pip install -Uq praisonai duckduckgo_search"
],
"metadata": {
"id": "cW47IVIvdyii"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"# tools.py\n",
"from duckduckgo_search import DDGS\n",
"from praisonai_tools import BaseTool\n",
"\n",
"class InternetSearchTool(BaseTool):\n",
" name: str = \"InternetSearchTool\"\n",
" description: str = \"Search Internet for relevant information based on a query or latest news\"\n",
"\n",
" def _run(self, query: str):\n",
" ddgs = DDGS()\n",
" results = ddgs.text(keywords=query, region='wt-wt', safesearch='moderate', max_results=5)\n",
" return results"
],
"metadata": {
"id": "Qwds0ad96Pco"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import os\n",
"import yaml\n",
"from praisonai import PraisonAI\n",
"from google.colab import userdata\n",
"\n",
"# Example agent_yaml content\n",
"agent_yaml = \"\"\"\n",
"framework: \"crewai\"\n",
"topic: \"Space Exploration\"\n",
"\n",
"roles:\n",
" astronomer:\n",
" role: \"Space Researcher\"\n",
" goal: \"Discover new insights about {topic}\"\n",
" backstory: \"You are a curious and dedicated astronomer with a passion for unraveling the mysteries of the cosmos.\"\n",
" tasks:\n",
" investigate_exoplanets:\n",
" description: \"Research and compile information about exoplanets discovered in the last decade.\"\n",
" expected_output: \"A summarized report on exoplanet discoveries, including their size, potential habitability, and distance from Earth.\"\n",
" tools:\n",
" - \"InternetSearchTool\"\n",
"\"\"\"\n",
"\n",
"# Create a PraisonAI instance with the agent_yaml content\n",
"praison_ai = PraisonAI(agent_yaml=agent_yaml)\n",
"\n",
"# Add OPENAI_API_KEY Secrets to Google Colab on the Left Hand Side 🔑 or Enter Manually Below\n",
"os.environ[\"OPENAI_API_KEY\"] = userdata.get('OPENAI_API_KEY') or \"ENTER OPENAI_API_KEY HERE\"\n",
"\n",
"# Run PraisonAI\n",
"result = praison_ai.main()\n",
"\n",
"# Print the result\n",
"print(result)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "myh-_QCuHfOs",
"outputId": "248cf6ed-f927-41fe-dcde-ed0bea53f07e"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"\u001b[1m\u001b[95m [2024-07-03 04:53:48][DEBUG]: == Working Agent: Space Researcher\u001b[00m\n",
"\u001b[1m\u001b[95m [2024-07-03 04:53:48][INFO]: == Starting Task: Research and compile information about exoplanets discovered in the last decade.\u001b[00m\n",
"\n",
"\n",
"\u001b[1m> Entering new CrewAgentExecutor chain...\u001b[0m\n",
"\u001b[32;1m\u001b[1;3mI now can give a great answer.\n",
"\n",
"Final Answer: \n",
"\n",
"Over the last decade, the field of exoplanet research has experienced significant advancements, leading to the discovery of thousands of exoplanets. These discoveries have been made possible through missions like NASA's Kepler and TESS (Transiting Exoplanet Survey Satellite), as well as ground-based observatories. Here is a summarized report on some of the notable exoplanet discoveries, including their size, potential habitability, and distance from Earth:\n",
"\n",
"1. **Kepler-452b**\n",
" - **Size**: Approximately 1.6 times the radius of Earth\n",
" - **Potential Habitability**: Located in the habitable zone of its star, where liquid water could exist. It is often referred to as Earth's \"cousin.\"\n",
" - **Distance from Earth**: About 1,400 light-years\n",
"\n",
"2. **Proxima Centauri b**\n",
" - **Size**: About 1.17 times the mass of Earth\n",
" - **Potential Habitability**: Located in the habitable zone of Proxima Centauri, the closest star to the Sun. It has the potential to have liquid water.\n",
" - **Distance from Earth**: 4.24 light-years\n",
"\n",
"3. **TRAPPIST-1 System**\n",
" - **Size**: The system includes seven Earth-sized planets\n",
" - **Potential Habitability**: Three of the planets (TRAPPIST-1e, TRAPPIST-1f, and TRAPPIST-1g) are located in the habitable zone and could potentially support liquid water.\n",
" - **Distance from Earth**: Approximately 39 light-years\n",
"\n",
"4. **LHS 1140b**\n",
" - **Size**: About 1.4 times the size of Earth and 6.6 times its mass\n",
" - **Potential Habitability**: Located in the habitable zone of its star. It has a thick atmosphere and conditions that could support life.\n",
" - **Distance from Earth**: About 40 light-years\n",
"\n",
"5. **Kepler-186f**\n",
" - **Size**: Similar to Earth in size\n",
" - **Potential Habitability**: The first Earth-sized planet discovered in the habitable zone of another star. It has potential for liquid water on its surface.\n",
" - **Distance from Earth**: About 500 light-years\n",
"\n",
"6. **K2-18b**\n",
" - **Size**: Approximately 2.6 times the radius of Earth\n",
" - **Potential Habitability**: Located in the habitable zone of its star, with evidence of water vapor in its atmosphere.\n",
" - **Distance from Earth**: About 124 light-years\n",
"\n",
"7. **GJ 357 d**\n",
" - **Size**: About 6.1 times the mass of Earth\n",
" - **Potential Habitability**: Located in the habitable zone of its star, with the potential to have liquid water on its surface.\n",
" - **Distance from Earth**: About 31 light-years\n",
"\n",
"These discoveries highlight the diversity of exoplanets in terms of size, composition, and potential habitability. The search for exoplanets is crucial for understanding the potential for life beyond Earth and the formation and evolution of planetary systems. Ongoing and future missions, such as the James Webb Space Telescope, are expected to provide even more detailed information about these distant worlds.\n",
"\n",
"The continuous exploration and study of exoplanets will undoubtedly lead to new insights and perhaps even the discovery of life beyond our solar system.\n",
"\n",
"\u001b[0m\n",
"\n",
"\u001b[1m> Finished chain.\u001b[0m\n",
"\u001b[1m\u001b[92m [2024-07-03 04:53:58][DEBUG]: == [Space Researcher] Task output: Over the last decade, the field of exoplanet research has experienced significant advancements, leading to the discovery of thousands of exoplanets. These discoveries have been made possible through missions like NASA's Kepler and TESS (Transiting Exoplanet Survey Satellite), as well as ground-based observatories. Here is a summarized report on some of the notable exoplanet discoveries, including their size, potential habitability, and distance from Earth:\n",
"\n",
"1. **Kepler-452b**\n",
" - **Size**: Approximately 1.6 times the radius of Earth\n",
" - **Potential Habitability**: Located in the habitable zone of its star, where liquid water could exist. It is often referred to as Earth's \"cousin.\"\n",
" - **Distance from Earth**: About 1,400 light-years\n",
"\n",
"2. **Proxima Centauri b**\n",
" - **Size**: About 1.17 times the mass of Earth\n",
" - **Potential Habitability**: Located in the habitable zone of Proxima Centauri, the closest star to the Sun. It has the potential to have liquid water.\n",
" - **Distance from Earth**: 4.24 light-years\n",
"\n",
"3. **TRAPPIST-1 System**\n",
" - **Size**: The system includes seven Earth-sized planets\n",
" - **Potential Habitability**: Three of the planets (TRAPPIST-1e, TRAPPIST-1f, and TRAPPIST-1g) are located in the habitable zone and could potentially support liquid water.\n",
" - **Distance from Earth**: Approximately 39 light-years\n",
"\n",
"4. **LHS 1140b**\n",
" - **Size**: About 1.4 times the size of Earth and 6.6 times its mass\n",
" - **Potential Habitability**: Located in the habitable zone of its star. It has a thick atmosphere and conditions that could support life.\n",
" - **Distance from Earth**: About 40 light-years\n",
"\n",
"5. **Kepler-186f**\n",
" - **Size**: Similar to Earth in size\n",
" - **Potential Habitability**: The first Earth-sized planet discovered in the habitable zone of another star. It has potential for liquid water on its surface.\n",
" - **Distance from Earth**: About 500 light-years\n",
"\n",
"6. **K2-18b**\n",
" - **Size**: Approximately 2.6 times the radius of Earth\n",
" - **Potential Habitability**: Located in the habitable zone of its star, with evidence of water vapor in its atmosphere.\n",
" - **Distance from Earth**: About 124 light-years\n",
"\n",
"7. **GJ 357 d**\n",
" - **Size**: About 6.1 times the mass of Earth\n",
" - **Potential Habitability**: Located in the habitable zone of its star, with the potential to have liquid water on its surface.\n",
" - **Distance from Earth**: About 31 light-years\n",
"\n",
"These discoveries highlight the diversity of exoplanets in terms of size, composition, and potential habitability. The search for exoplanets is crucial for understanding the potential for life beyond Earth and the formation and evolution of planetary systems. Ongoing and future missions, such as the James Webb Space Telescope, are expected to provide even more detailed information about these distant worlds.\n",
"\n",
"The continuous exploration and study of exoplanets will undoubtedly lead to new insights and perhaps even the discovery of life beyond our solar system.\n",
"\n",
"\u001b[00m\n",
"### Task Output ###\n",
"Over the last decade, the field of exoplanet research has experienced significant advancements, leading to the discovery of thousands of exoplanets. These discoveries have been made possible through missions like NASA's Kepler and TESS (Transiting Exoplanet Survey Satellite), as well as ground-based observatories. Here is a summarized report on some of the notable exoplanet discoveries, including their size, potential habitability, and distance from Earth:\n",
"\n",
"1. **Kepler-452b**\n",
" - **Size**: Approximately 1.6 times the radius of Earth\n",
" - **Potential Habitability**: Located in the habitable zone of its star, where liquid water could exist. It is often referred to as Earth's \"cousin.\"\n",
" - **Distance from Earth**: About 1,400 light-years\n",
"\n",
"2. **Proxima Centauri b**\n",
" - **Size**: About 1.17 times the mass of Earth\n",
" - **Potential Habitability**: Located in the habitable zone of Proxima Centauri, the closest star to the Sun. It has the potential to have liquid water.\n",
" - **Distance from Earth**: 4.24 light-years\n",
"\n",
"3. **TRAPPIST-1 System**\n",
" - **Size**: The system includes seven Earth-sized planets\n",
" - **Potential Habitability**: Three of the planets (TRAPPIST-1e, TRAPPIST-1f, and TRAPPIST-1g) are located in the habitable zone and could potentially support liquid water.\n",
" - **Distance from Earth**: Approximately 39 light-years\n",
"\n",
"4. **LHS 1140b**\n",
" - **Size**: About 1.4 times the size of Earth and 6.6 times its mass\n",
" - **Potential Habitability**: Located in the habitable zone of its star. It has a thick atmosphere and conditions that could support life.\n",
" - **Distance from Earth**: About 40 light-years\n",
"\n",
"5. **Kepler-186f**\n",
" - **Size**: Similar to Earth in size\n",
" - **Potential Habitability**: The first Earth-sized planet discovered in the habitable zone of another star. It has potential for liquid water on its surface.\n",
" - **Distance from Earth**: About 500 light-years\n",
"\n",
"6. **K2-18b**\n",
" - **Size**: Approximately 2.6 times the radius of Earth\n",
" - **Potential Habitability**: Located in the habitable zone of its star, with evidence of water vapor in its atmosphere.\n",
" - **Distance from Earth**: About 124 light-years\n",
"\n",
"7. **GJ 357 d**\n",
" - **Size**: About 6.1 times the mass of Earth\n",
" - **Potential Habitability**: Located in the habitable zone of its star, with the potential to have liquid water on its surface.\n",
" - **Distance from Earth**: About 31 light-years\n",
"\n",
"These discoveries highlight the diversity of exoplanets in terms of size, composition, and potential habitability. The search for exoplanets is crucial for understanding the potential for life beyond Earth and the formation and evolution of planetary systems. Ongoing and future missions, such as the James Webb Space Telescope, are expected to provide even more detailed information about these distant worlds.\n",
"\n",
"The continuous exploration and study of exoplanets will undoubtedly lead to new insights and perhaps even the discovery of life beyond our solar system.\n"
]
}
]
}
]
}
File renamed without changes.
+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.45 gunicorn markdown\n&#34;)
file.write(&#34;RUN pip install flask praisonai==0.0.46 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;)
File renamed without changes.
File renamed without changes.
+15
View File
@@ -60,6 +60,12 @@ class PraisonAI:
self.auto = auto
self.init = init
def run(self):
"""
Run the PraisonAI application.
"""
self.main()
def main(self):
"""
The main function of the PraisonAI object. It parses the command-line arguments,
@@ -188,6 +194,15 @@ class PraisonAI:
if CHAINLIT_AVAILABLE:
import praisonai
os.environ["CHAINLIT_PORT"] = "8084"
public_folder = os.path.join(os.path.dirname(praisonai.__file__), 'public')
if not os.path.exists("public"): # Check if the folder exists in the current directory
if os.path.exists(public_folder):
shutil.copytree(public_folder, 'public', dirs_exist_ok=True)
logging.info("Public folder copied successfully!")
else:
logging.info("Public folder not found in the package.")
else:
logging.info("Public folder already exists.")
chat_ui_path = os.path.join(os.path.dirname(praisonai.__file__), 'ui', 'chat.py')
chainlit_run([chat_ui_path])
else:
+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.45 gunicorn markdown\n")
file.write("RUN pip install flask praisonai==0.0.46 gunicorn markdown\n")
file.write("EXPOSE 8080\n")
file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')
+1 -1
View File
@@ -218,7 +218,7 @@ thread_history = load_threads_from_db()
deleted_thread_ids = [] # type: List[str]
class TestDataLayer(cl_data.BaseDataLayer):
class TestDataLayer(cl_data.BaseDataLayer): # Implement SQLAlchemyDataLayer
async def get_user(self, identifier: str):
logger.debug(f"Getting user: {identifier}")
return cl.PersistedUser(id="test", createdAt=now, identifier=identifier)
+1 -1
View File
@@ -1,6 +1,6 @@
[tool.poetry]
name = "PraisonAI"
version = "0.0.45"
version = "0.0.46"
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 = ""
-30
View File
@@ -1,30 +0,0 @@
#!/bin/bash
# Check the first argument provided to the script for platform selection
if [ "$1" = "groq" ]; then
# Check for a second argument for the model name, default to mixtral-8x7b-32768 if not provided
MODEL_NAME=${2:-mixtral-8x7b-32768}
# Set environment variables for Groq configuration with dynamic model name
export OPENAI_MODEL_NAME=$MODEL_NAME
export OPENAI_API_BASE=https://api.groq.com/openai/v1
export OPENAI_API_KEY=$(echo $GROQ_API_KEY)
echo "Groq configuration initiated with model $MODEL_NAME."
elif [ "$1" = "openai" ] || [ -z "$1" ]; then
# Check for a second argument for the model name, default to gpt-3.5-turbo if not provided
MODEL_NAME=${2:-gpt-3.5-turbo}
# Set environment variables for OpenAI configuration with dynamic model name
export OPENAI_MODEL_NAME=$MODEL_NAME
export OPENAI_API_BASE=https://api.openai.com/v1
export OPENAI_API_KEY=$(echo $OAI_API_KEY)
echo "OpenAI configuration initiated with model $MODEL_NAME."
elif [ "$1" = "ollama" ]; then
# Check for a second argument for the model name, default to a custom model if not provided
MODEL_NAME=${2:-default-ollama-model}
# Set environment variables for Ollama local configuration with dynamic model name
export OPENAI_MODEL_NAME=$MODEL_NAME
export OPENAI_API_BASE=http://127.0.0.1:11434
export OPENAI_API_KEY=$(echo $OLLAMA_API_KEY)
# Set up SSH public key
export SSH_PUBLIC_KEY="ssh-ed25519 AAAA..."
echo "Ollama local model configuration initiated with model $MODEL_NAME.
fi