parent
9c92517b5c
commit
42b2cd6313
@ -1,35 +1,96 @@
|
||||
import re
|
||||
from swarms.models.nougat import Nougat
|
||||
from swarms.structs import Flow
|
||||
from swarms.models import OpenAIChat
|
||||
from swarms.models import LayoutLMDocumentQA
|
||||
from swarms.models import OpenAIChat, Anthropic
|
||||
from typing import List
|
||||
|
||||
# # URL of the image of the financial document
|
||||
IMAGE_OF_FINANCIAL_DOC_URL = "bank_statement_2.jpg"
|
||||
|
||||
# Example usage
|
||||
api_key = ""
|
||||
# Base llms
|
||||
llm1 = OpenAIChat()
|
||||
llm2 = Anthropic()
|
||||
nougat = Nougat()
|
||||
|
||||
# Initialize the language flow
|
||||
llm = OpenAIChat(
|
||||
openai_api_key=api_key,
|
||||
)
|
||||
|
||||
# LayoutLM Document QA
|
||||
pdf_analyzer = LayoutLMDocumentQA()
|
||||
# Prompts for each agent
|
||||
SUMMARY_AGENT_PROMPT = """
|
||||
Generate an actionable summary of this financial document be very specific and precise, provide bulletpoints be very specific provide methods of lowering expenses: {answer}"
|
||||
"""
|
||||
|
||||
|
||||
question = "What is the total amount of expenses?"
|
||||
answer = pdf_analyzer(
|
||||
question,
|
||||
IMAGE_OF_FINANCIAL_DOC_URL,
|
||||
# Agents
|
||||
user_consultant_agent = Flow(
|
||||
llm=llm1,
|
||||
)
|
||||
doc_analyzer_agent = Flow(
|
||||
llm=llm1,
|
||||
)
|
||||
summary_generator_agent = Flow(
|
||||
llm=llm2,
|
||||
)
|
||||
fraud_detection_agent = Flow(
|
||||
llm=llm2,
|
||||
)
|
||||
decision_making_support_agent = Flow(
|
||||
llm=llm2,
|
||||
)
|
||||
|
||||
# Initialize the Flow with the language flow
|
||||
agent = Flow(llm=llm)
|
||||
SUMMARY_AGENT_PROMPT = f"""
|
||||
Generate an actionable summary of this financial document be very specific and precise, provide bulletpoints be very specific provide methods of lowering expenses: {answer}"
|
||||
"""
|
||||
|
||||
# Add tasks to the workflow
|
||||
summary_agent = agent.run(SUMMARY_AGENT_PROMPT)
|
||||
print(summary_agent)
|
||||
class AccountantSwarms:
|
||||
"""
|
||||
Accountant Swarms is a collection of agents that work together to help
|
||||
accountants with their work.
|
||||
|
||||
Flow: 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
|
||||
to the accountant.
|
||||
|
||||
Example:
|
||||
>>> accountant_swarms = AccountantSwarms(
|
||||
|
||||
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
financial_document_img: str,
|
||||
financial_document_list_img: List[str] = None,
|
||||
fraud_detection_instructions: str = None,
|
||||
summary_agent_instructions: str = None,
|
||||
decision_making_support_agent_instructions: str = None,
|
||||
):
|
||||
super().__init__()
|
||||
self.financial_document_img = financial_document_img
|
||||
self.fraud_detection_instructions = fraud_detection_instructions
|
||||
self.summary_agent_instructions = summary_agent_instructions
|
||||
|
||||
def run(self):
|
||||
# Extract text from the image
|
||||
analyzed_doc = self.nougat(self.financial_document_img)
|
||||
|
||||
# Detect fraud in the document
|
||||
fraud_detection_agent_output = self.fraud_detection_agent(analyzed_doc)
|
||||
|
||||
# Generate an actionable summary of the document
|
||||
summary_agent_output = self.summary_agent(fraud_detection_agent_output)
|
||||
|
||||
# Provide decision making support to the accountant
|
||||
decision_making_support_agent_output = self.decision_making_support_agent(
|
||||
summary_agent_output
|
||||
)
|
||||
|
||||
return decision_making_support_agent_output
|
||||
|
@ -0,0 +1,19 @@
|
||||
from swarms.structs import Flow, SequentialWorkflow
|
||||
from swarms.models import OpenAIChat, Anthropic
|
||||
|
||||
# llm
|
||||
llm = OpenAIChat()
|
||||
llm2 = Anthropic()
|
||||
|
||||
# 2 Flows, one that creates an algorithmic pseuedocode and another that creates the pytorch code
|
||||
flow1 = Flow(llm2, max_loops=1)
|
||||
flow2 = Flow(llm, max_loops=1)
|
||||
|
||||
# SequentialWorkflow
|
||||
workflow = SequentialWorkflow(
|
||||
[flow1, flow2],
|
||||
max_loops=1,
|
||||
name="Paper to Code",
|
||||
autosave=True,
|
||||
description="This workflow takes a paper and converts it to code.",
|
||||
)
|
@ -0,0 +1,10 @@
|
||||
from swarms import Flow, Fuyu
|
||||
|
||||
llm = Fuyu()
|
||||
|
||||
flow = Flow(max_loops="auto", llm=llm)
|
||||
|
||||
flow.run(
|
||||
task="Describe this image in a few sentences: ",
|
||||
img="https://unsplash.com/photos/0pIC5ByPpZY",
|
||||
)
|
@ -0,0 +1,14 @@
|
||||
# This might not work in the beginning but it's a starting point
|
||||
from swarms.structs import Flow, GPT4V
|
||||
|
||||
llm = GPT4V()
|
||||
|
||||
flow = Flow(
|
||||
max_loops="auto",
|
||||
llm=llm,
|
||||
)
|
||||
|
||||
flow.run(
|
||||
task="Describe this image in a few sentences: ",
|
||||
img="https://unsplash.com/photos/0pIC5ByPpZY",
|
||||
)
|
Loading…
Reference in new issue