Skip to main content

An orchestration framework for all your AI needs

Project description

โš”๏ธ๐Ÿ”— Empire Chain

โšก An orchestration framework for all your AI needs โšก

    โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ•—   โ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—
    โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•
    โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ•”โ–ˆโ–ˆโ–ˆโ–ˆโ•”โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—  
    โ–ˆโ–ˆโ•”โ•โ•โ•  โ–ˆโ–ˆโ•‘โ•šโ–ˆโ–ˆโ•”โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ•โ• โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•”โ•โ•โ•  
    โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘ โ•šโ•โ• โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘     โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—
    โ•šโ•โ•โ•โ•โ•โ•โ•โ•šโ•โ•     โ•šโ•โ•โ•šโ•โ•     โ•šโ•โ•โ•šโ•โ•  โ•šโ•โ•โ•šโ•โ•โ•โ•โ•โ•โ•
     โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ•— โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ–ˆโ•—   โ–ˆโ–ˆโ•—
    โ–ˆโ–ˆโ•”โ•โ•โ•โ•โ•โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ•—  โ–ˆโ–ˆโ•‘
    โ–ˆโ–ˆโ•‘     โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ–ˆโ–ˆโ•— โ–ˆโ–ˆโ•‘
    โ–ˆโ–ˆโ•‘     โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•”โ•โ•โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘โ•šโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘
    โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ•—โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘  โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘โ–ˆโ–ˆโ•‘ โ•šโ–ˆโ–ˆโ–ˆโ–ˆโ•‘
     โ•šโ•โ•โ•โ•โ•โ•โ•šโ•โ•  โ•šโ•โ•โ•šโ•โ•  โ•šโ•โ•โ•šโ•โ•โ•šโ•โ•  โ•šโ•โ•โ•โ•
    =============================================
         ๐Ÿ”— Chain Your AI Dreams Together ๐Ÿ”—
    =============================================

PyPI version PyPI downloads License GitHub stars

Features

  • ๐Ÿค– Multiple LLM Support (OpenAI, Anthropic, Groq)
  • ๐Ÿ“š Vector Store Integration (Qdrant, ChromaDB)
  • ๐Ÿ” Advanced Document Processing
  • ๐ŸŽ™๏ธ Speech-to-Text Capabilities
  • ๐ŸŒ Web Crawling with crawl4ai
  • ๐Ÿ“Š Data Visualization
  • ๐ŸŽฏ RAG Applications
  • ๐Ÿค PhiData Agent Integration
  • ๐Ÿ’ฌ Interactive Chatbots
  • ๐Ÿค– Agentic Framework

Installation

pip install empire-chain

Empire Chain Components

Empire Agent

"""
This is a simple example of how to use the Empire Agent.
Please run the following command to install the necessary dependencies and store keys in .env:
!pip install empire-chain
"""
from datetime import datetime
from empire_chain.agent.agent import Agent
from dotenv import load_dotenv

load_dotenv()

def get_weather(location: str) -> str:
    return f"The weather in {location} is sunny!"

def calculate_distance(from_city: str, to_city: str) -> str:
    return f"The distance from {from_city} to {to_city} is 500km"

def get_time(timezone: str) -> str:
    return f"Current time in {timezone}: {datetime.now()}"

def translate_text(text: str, target_language: str) -> str:
    return f"Translated '{text}' to {target_language}: [translation would go here]"

def search_web(query: str, num_results: int) -> str:
    return f"Top {num_results} results for '{query}': [search results would go here]"

def main():
    # Create agent
    agent = Agent()
    
    # Register functions
    functions = [
        get_weather,
        calculate_distance,
        get_time,
        translate_text,
        search_web
    ]
    
    for func in functions:
        agent.register_function(func)
    
    # Example queries
    queries = [
        "What's the weather like in Tokyo?",
        "How far is London from Paris?",
        "What time is it in EST timezone?",
        "Translate 'Hello World' to Spanish",
        "Search for latest news about AI and show 3 results"
    ]
    
    # Process queries
    for query in queries:
        try:
            result = agent.process_query(query)
            print(f"\nQuery: {query}")
            print(f"Result: {result['result']}")
        except Exception as e:
            print(f"Error processing query '{query}': {str(e)}")

if __name__ == "__main__":
    main()

RAG

from empire_chain.vector_stores import QdrantVectorStore
from empire_chain.embeddings import OpenAIEmbeddings
from empire_chain.llms.llms import GroqLLM
from empire_chain.tools.file_reader import DocumentReader
import os
from dotenv import load_dotenv
from empire_chain.stt.stt import GroqSTT

def main(if_audio_input: bool = False):
    load_dotenv()
    
    vector_store = QdrantVectorStore(":memory:")
    embeddings = OpenAIEmbeddings("text-embedding-3-small")
    llm = GroqLLM("llama3-8b-8192")
    reader = DocumentReader()
    
    file_path = "input.pdf"
    text = reader.read(file_path)
    
    text_embedding = embeddings.embed(text)
    vector_store.add(text, text_embedding)
    
    text_query = "What is the main topic of this document?"
    if if_audio_input:
        stt = GroqSTT()
        audio_query = stt.transcribe("audio.mp3")
        query_embedding = embeddings.embed(audio_query)
    else:
        query_embedding = embeddings.embed(text_query)
    relevant_texts = vector_store.query(query_embedding, k=3)
    
    context = "\n".join(relevant_texts)
    prompt = f"Based on the following context, {text_query}\n\nContext: {context}"
    response = llm.generate(prompt)
    print(f"Query: {text_query}")
    print(f"Response: {response}")

if __name__ == "__main__":
    main(if_audio_input=False)

Chatbots

Simple Chatbot

"""
This is a simple chatbot that uses the Empire Chain library to create a chatbot.
Please run the following command to install the necessary dependencies and store keys in .env:
!pip install empire-chain streamlit
!streamlit run app.py
"""
from empire_chain.streamlit import Chatbot
from empire_chain.llms.llms import OpenAILLM

chatbot = Chatbot(title="Empire Chatbot", llm=OpenAILLM("gpt-4o-mini"))
chatbot.chat()

Chat with Image

"""
This is a simple chatbot that uses the Empire Chain library to create a chatbot.
Please run the following command to install the necessary dependencies and groq key in .env (https://console.groq.com/keys):
!pip install empire-chain streamlit
!streamlit run app.py
"""
from empire_chain.streamlit import VisionChatbot

chatbot = VisionChatbot(title="Empire Chatbot")
chatbot.chat()

Chat with PDF

"""
This is a simple chatbot that uses the Empire Chain library to create a pdf chatbot.
Please run the following command to install the necessary dependencies and store keys in .env:
!pip install empire-chain streamlit
!streamlit run app.py
"""
from empire_chain.streamlit import PDFChatbot
from empire_chain.llms.llms import OpenAILLM
from empire_chain.vector_stores import QdrantVectorStore
from empire_chain.embeddings import OpenAIEmbeddings

pdf_chatbot = PDFChatbot(title="PDF Chatbot", llm=OpenAILLM("gpt-4o-mini"), vector_store=QdrantVectorStore(":memory:"), embeddings=OpenAIEmbeddings("text-embedding-3-small"))
pdf_chatbot.chat()

PhiData Agents

Web Agent

"""
This is a simple example of how to use the WebAgent class to generate web data.
Please run the following command to install the necessary dependencies and store keys in .env:
!pip install empire-chain phidata duckduckgo-search
"""
from empire_chain.phidata.web_agent import WebAgent

web_agent = WebAgent()

web_agent.generate("What is the price of Tesla?")

Finance Agent

"""
This is a simple example of how to use the PhiFinanceAgent class to generate financial data.
Please run the following command to install the necessary dependencies and store keys in .env:
!pip install empire-chain phidata yfinance
"""
from empire_chain.phidata.finance_agent import PhiFinanceAgent

finance_agent = PhiFinanceAgent()

finance_agent.generate("Analyze TSLA stock performance")

Tools

File Reader

"""
This is a simple file reader that uses the Empire Chain library to read a file.
It supports 
1. PDF files (.pdf)
2. Microsoft Word documents (.docx)
3. Text files (.txt)
4. JSON files (.json)
5. CSV files (.csv)
6. Google Drive files (.gdrive)
"""
from empire_chain.tools.file_reader import DocumentReader
reader = DocumentReader()

text = reader.read("https://drive.google.com/file/d/1t0Itw6oGO2iVusp=sharing")
print(text)

text = reader.read("input.pdf")
print(text)

Website Crawler

"""
This is a simple crawler that uses the Empire Chain library to crawl a website and save the content as markdown.
Please run the following command to install the necessary dependencies and store keys in .env:
!pip install empire-chain crawl4ai
"""
from empire_chain.tools.crawl4ai import Crawler

crawler = Crawler()
result = crawler.crawl(url="https://www.geekroom.in", format="markdown")
print(result)

Speech to Text

from empire_chain.stt.stt import GroqSTT
from empire_chain.stt.stt import HuggingFaceSTT
from dotenv import load_dotenv
import os
load_dotenv()

stt = GroqSTT()
text = stt.transcribe("audio.mp3")
print(text)

stt = HuggingFaceSTT()
text = stt.transcribe("audio.mp3")
print(text)

Cool Stuff

Visualize Data

"""
This is a simple example of how to use the DataAnalyzer and ChartFactory classes to visualize data.
Please run the following command to install the necessary dependencies and store keys in .env:
!pip install empire-chain matplotlib

_chart_types = {
        'Line Chart': LineChart,
        'Pie Chart': PieChart,
        'Bar Graph': BarGraph,
        'Scatter Plot': ScatterChart,
        'Histogram': Histogram,
        'Box Plot': BoxPlot
    }
Please adhere to the naming convention for the chart type.
"""
from empire_chain.cool_stuff.visualizer import DataAnalyzer, ChartFactory

data = """
Empire chain got a fund raise of $100M from a new investor in 2024 and $50M from a new investor in 2023.
"""
    
analyzer = DataAnalyzer()
analyzed_data = analyzer.analyze(data)
        
chart = ChartFactory.create_chart('Bar Chart', analyzed_data)
chart.show()

Text to Podcast

"""
This is a simple example of how to use the GeneratePodcast class to generate a podcast.
Please run the following command to install the necessary dependencies and store keys in .env:
!pip install empire-chain kokoro_onnx (It might take a while to download the model files)
"""
from empire_chain.cool_stuff.podcast import GeneratePodcast

podcast=GeneratePodcast()
podcast.generate(topic="About boom of meal plan and recipe generation apps")

Contributing

git clone https://github.com/manas95826/empire-chain.git
cd empire-chain
pip install -e .

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

empire_chain-0.5.4.tar.gz (40.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

empire_chain-0.5.4-py3-none-any.whl (39.7 kB view details)

Uploaded Python 3

File details

Details for the file empire_chain-0.5.4.tar.gz.

File metadata

  • Download URL: empire_chain-0.5.4.tar.gz
  • Upload date:
  • Size: 40.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for empire_chain-0.5.4.tar.gz
Algorithm Hash digest
SHA256 c880b939c939c5ee6996208a9af1cf924d06ed34cca307508d3c5a5f9fed4a1d
MD5 a254b2f4d0da41ba1d1e81c9250abcc8
BLAKE2b-256 ccc8157fa1bc5dc378a7e6f786e909ecb4cb1edd7a7ccdf0c4d87f395fb01a19

See more details on using hashes here.

File details

Details for the file empire_chain-0.5.4-py3-none-any.whl.

File metadata

  • Download URL: empire_chain-0.5.4-py3-none-any.whl
  • Upload date:
  • Size: 39.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for empire_chain-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 70dccc6e27b97f36f3dfbbd6130d96de1f2e3e37d392b267e6eb2f63ed48d3bb
MD5 20029ac54e85cf75816641435b150bf7
BLAKE2b-256 25a7eaefbd0ee0e6f236099d03e263a4ed798f9c392e2ce06398593692b54f37

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page