Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# faster_llm

`faster_llm` is a Python library that speeds up common data preprocessing and analysis tasks. It builds on familiar tools like NumPy, Pandas and scikit-learn while adding connectors for Large Language Model (LLM) frameworks such as LangChain and LlamaIndex.
`faster_llm` is a Python library that speeds up common data preprocessing and analysis tasks. It builds on familiar tools like NumPy, Pandas and scikit-learn while adding connectors for Large Language Model (LLM) frameworks such as LangChain and LlamaIndex. Recent updates introduce lightweight helpers for other agent libraries including AutoGen and CrewAI.

## Overview

Expand All @@ -16,6 +16,7 @@
- Lightweight wrappers for Keras, PyTorch and PyTorch Lightning
- Simple generator for producing fake data for experiments
- MCP client for forwarding messages to LLM services and AI agents
- Wrappers for LangChain, LlamaIndex, AutoGen and CrewAI agents

## Quick Demo

Expand Down Expand Up @@ -79,6 +80,9 @@ python examples/classification_example.py

The same helper can forward metrics from Keras, PyTorch or PyTorch Lightning
models to AI agents by using the library's MCP integration.
The new ``agents`` module also exposes utility functions to create LangChain
``AIMessage`` objects, LlamaIndex ``Document`` instances, run simple CrewAI
crews or spin up AutoGen assistants directly from your code.

## Bug Reports & Feature Requests

Expand Down
16 changes: 15 additions & 1 deletion faster_llm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,18 @@
__author_email__ = "poczta130@gmail.com"
__maintainer__ = "unknown maintainer"
__maintainer_email__ = "maintainer@example.com"
__github_username__ = "fuwiak"
__github_username__ = "fuwiak"

from .agents import (
send_to_crewai,
send_with_autogen,
to_langchain_message,
to_llamaindex_document,
)

__all__ = [
"send_to_crewai",
"send_with_autogen",
"to_langchain_message",
"to_llamaindex_document",
]
83 changes: 83 additions & 0 deletions faster_llm/agents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""Wrappers for popular AI agent frameworks."""

from __future__ import annotations

from typing import Any

try: # optional LangChain import
from langchain.schema import AIMessage
except Exception: # pragma: no cover - optional
class AIMessage:
"""Fallback AIMessage when LangChain isn't installed."""

def __init__(self, content: str) -> None:
self.content = content


def to_langchain_message(message: str) -> AIMessage:
"""Wrap ``message`` in a LangChain ``AIMessage`` object."""
return AIMessage(message)


try: # optional LlamaIndex import
from llama_index.core import Document
except Exception: # pragma: no cover - optional
class Document: # type: ignore
"""Simplified stand-in for LlamaIndex ``Document``."""

def __init__(self, text: str) -> None:
self.text = text


def to_llamaindex_document(text: str) -> Document:
"""Create a LlamaIndex ``Document`` (or placeholder) from ``text``."""
return Document(text)


try: # optional CrewAI import
from crewai import Crew
except Exception: # pragma: no cover - optional
class Crew: # type: ignore
"""Basic replacement for a CrewAI ``Crew`` when the dependency is missing."""

def __init__(self, *_, **__) -> None:
self.messages: list[str] = []

def run(self, message: str) -> None:
self.messages.append(message)


def send_to_crewai(message: str) -> Crew:
"""Send a message to a CrewAI ``Crew`` instance."""
crew = Crew()
crew.run(message)
return crew


try: # optional AutoGen import
from autogen import AssistantAgent
except Exception: # pragma: no cover - optional
class AssistantAgent: # type: ignore
"""Minimal stub of AutoGen's ``AssistantAgent``."""

def __init__(self, name: str, llm_config: dict | None = None) -> None:
self.name = name
self.messages: list[str] = []

def send(self, message: str) -> None:
self.messages.append(message)


def send_with_autogen(message: str, *, llm_config: dict | None = None) -> AssistantAgent:
"""Create an AutoGen assistant and send it ``message``."""
agent = AssistantAgent("assistant", llm_config=llm_config or {})
agent.send(message)
return agent


__all__ = [
"to_langchain_message",
"to_llamaindex_document",
"send_to_crewai",
"send_with_autogen",
]
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ scikit-learn = ">=1.2.0"
matplotlib = ">=3.6.2"
mlflow = ">=2.0.0"
langsmith = ">=0.1.0"
autogen = ">=0.2.0"
crewai = ">=0.1.0"
langchain = ">=0.0.350"
llama-index = ">=0.9.0"

[build-system]
requires = ["poetry-core"]
Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,7 @@ widgetsnbextension>=4.0.5

mlflow>=2.0.0
langsmith>=0.1.0
autogen>=0.2.0
crewai>=0.1.0
langchain>=0.0.350
llama-index>=0.9.0
35 changes: 35 additions & 0 deletions tests/test_agents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os
import sys

sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))

from faster_llm import (
send_to_crewai,
send_with_autogen,
to_langchain_message,
to_llamaindex_document,
)


def test_to_langchain_message():
msg = to_langchain_message("hi")
assert hasattr(msg, "content")
assert msg.content == "hi"


def test_to_llamaindex_document():
doc = to_llamaindex_document("hello")
assert hasattr(doc, "text")
assert doc.text == "hello"


def test_send_to_crewai():
crew = send_to_crewai("ping")
assert hasattr(crew, "messages")
assert "ping" in crew.messages


def test_send_with_autogen():
agent = send_with_autogen("pong")
assert hasattr(agent, "messages")
assert "pong" in agent.messages
Loading