parent
6a9cd36a32
commit
afd12911ac
@ -1,42 +0,0 @@
|
|||||||
|
|
||||||
# ==================================
|
|
||||||
# Use an official Python runtime as a parent image
|
|
||||||
FROM python:3.9-slim
|
|
||||||
|
|
||||||
# Set environment variables
|
|
||||||
ENV PYTHONDONTWRITEBYTECODE 1
|
|
||||||
ENV PYTHONUNBUFFERED 1
|
|
||||||
|
|
||||||
# Set the working directory in the container
|
|
||||||
WORKDIR /usr/src/swarm_cloud
|
|
||||||
|
|
||||||
|
|
||||||
# Install Python dependencies
|
|
||||||
# COPY requirements.txt and pyproject.toml if you're using poetry for dependency management
|
|
||||||
COPY requirements.txt .
|
|
||||||
RUN pip install --upgrade pip
|
|
||||||
RUN pip install --no-cache-dir -r requirements.txt
|
|
||||||
|
|
||||||
# Install the 'swarms' package, assuming it's available on PyPI
|
|
||||||
RUN pip install swarms
|
|
||||||
|
|
||||||
# Copy the rest of the application
|
|
||||||
COPY . .
|
|
||||||
|
|
||||||
# Add entrypoint script if needed
|
|
||||||
# COPY ./entrypoint.sh .
|
|
||||||
# RUN chmod +x /usr/src/swarm_cloud/entrypoint.sh
|
|
||||||
|
|
||||||
# Expose port if your application has a web interface
|
|
||||||
# EXPOSE 5000
|
|
||||||
|
|
||||||
# # Define environment variable for the swarm to work
|
|
||||||
# ENV SWARM_API_KEY=your_swarm_api_key_here
|
|
||||||
|
|
||||||
# # Add Docker CMD or ENTRYPOINT script to run the application
|
|
||||||
# CMD python your_swarm_startup_script.py
|
|
||||||
# Or use the entrypoint script if you have one
|
|
||||||
# ENTRYPOINT ["/usr/src/swarm_cloud/entrypoint.sh"]
|
|
||||||
|
|
||||||
# If you're using `CMD` to execute a Python script, make sure it's executable
|
|
||||||
# RUN chmod +x your_swarm_startup_script.py
|
|
@ -1,125 +0,0 @@
|
|||||||
import os
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
|
||||||
|
|
||||||
from swarms.models import Anthropic, OpenAIChat
|
|
||||||
from swarms.prompts.accountant_swarm_prompts import (
|
|
||||||
DECISION_MAKING_PROMPT,
|
|
||||||
DOC_ANALYZER_AGENT_PROMPT,
|
|
||||||
FRAUD_DETECTION_AGENT_PROMPT,
|
|
||||||
SUMMARY_GENERATOR_AGENT_PROMPT,
|
|
||||||
)
|
|
||||||
from swarms.structs import Agent
|
|
||||||
from swarms.utils.pdf_to_text import pdf_to_text
|
|
||||||
|
|
||||||
# Environment variables
|
|
||||||
load_dotenv()
|
|
||||||
anthropic_api_key = os.getenv("ANTHROPIC_API_KEY")
|
|
||||||
openai_api_key = os.getenv("OPENAI_API_KEY")
|
|
||||||
|
|
||||||
|
|
||||||
# Base llms
|
|
||||||
llm1 = OpenAIChat(
|
|
||||||
openai_api_key=openai_api_key,
|
|
||||||
)
|
|
||||||
|
|
||||||
llm2 = Anthropic(
|
|
||||||
anthropic_api_key=anthropic_api_key,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# Agents
|
|
||||||
doc_analyzer_agent = Agent(
|
|
||||||
llm=llm1,
|
|
||||||
sop=DOC_ANALYZER_AGENT_PROMPT,
|
|
||||||
)
|
|
||||||
summary_generator_agent = Agent(
|
|
||||||
llm=llm2,
|
|
||||||
sop=SUMMARY_GENERATOR_AGENT_PROMPT,
|
|
||||||
)
|
|
||||||
decision_making_support_agent = Agent(
|
|
||||||
llm=llm2,
|
|
||||||
sop=DECISION_MAKING_PROMPT,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class AccountantSwarms:
|
|
||||||
"""
|
|
||||||
Accountant Swarms is a collection of agents that work together to help
|
|
||||||
accountants with their work.
|
|
||||||
|
|
||||||
Agent: analyze doc -> detect fraud -> generate summary -> decision making support
|
|
||||||
|
|
||||||
The agents are:
|
|
||||||
- User Consultant: Asks the user many questions
|
|
||||||
- Document Analyzer: Extracts text from the image of the financial document
|
|
||||||
- Fraud Detection: Detects fraud in the document
|
|
||||||
- Summary Agent: Generates an actionable summary of the document
|
|
||||||
- Decision Making Support: Provides decision making support to the accountant
|
|
||||||
|
|
||||||
The agents are connected together in a workflow that is defined in the
|
|
||||||
run method.
|
|
||||||
|
|
||||||
The workflow is as follows:
|
|
||||||
1. The Document Analyzer agent extracts text from the image of the
|
|
||||||
financial document.
|
|
||||||
2. The Fraud Detection agent detects fraud in the document.
|
|
||||||
3. The Summary Agent generates an actionable summary of the document.
|
|
||||||
4. The Decision Making Support agent provides decision making support
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
pdf_path: str,
|
|
||||||
list_pdfs: List[str] = None,
|
|
||||||
fraud_detection_instructions: str = None,
|
|
||||||
summary_agent_instructions: str = None,
|
|
||||||
decision_making_support_agent_instructions: str = None,
|
|
||||||
):
|
|
||||||
super().__init__()
|
|
||||||
self.pdf_path = pdf_path
|
|
||||||
self.list_pdfs = list_pdfs
|
|
||||||
self.fraud_detection_instructions = (
|
|
||||||
fraud_detection_instructions
|
|
||||||
)
|
|
||||||
self.summary_agent_instructions = summary_agent_instructions
|
|
||||||
self.decision_making_support_agent_instructions = (
|
|
||||||
decision_making_support_agent_instructions
|
|
||||||
)
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
# Transform the pdf to text
|
|
||||||
pdf_text = pdf_to_text(self.pdf_path)
|
|
||||||
|
|
||||||
# Detect fraud in the document
|
|
||||||
fraud_detection_agent_output = doc_analyzer_agent.run(
|
|
||||||
f"{self.fraud_detection_instructions}: {pdf_text}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Generate an actionable summary of the document
|
|
||||||
summary_agent_output = summary_generator_agent.run(
|
|
||||||
f"{self.summary_agent_instructions}:"
|
|
||||||
f" {fraud_detection_agent_output}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Provide decision making support to the accountant
|
|
||||||
decision_making_support_agent_output = decision_making_support_agent.run(
|
|
||||||
f"{self.decision_making_support_agent_instructions}:"
|
|
||||||
f" {summary_agent_output}"
|
|
||||||
)
|
|
||||||
|
|
||||||
return decision_making_support_agent_output
|
|
||||||
|
|
||||||
|
|
||||||
swarm = AccountantSwarms(
|
|
||||||
pdf_path="tesla.pdf",
|
|
||||||
fraud_detection_instructions="Detect fraud in the document",
|
|
||||||
summary_agent_instructions=(
|
|
||||||
"Generate an actionable summary of the document"
|
|
||||||
),
|
|
||||||
decision_making_support_agent_instructions=(
|
|
||||||
"Provide decision making support to the business owner:"
|
|
||||||
),
|
|
||||||
)
|
|
Before Width: | Height: | Size: 538 KiB |
Loading…
Reference in new issue