Coder Social home page Coder Social logo

runnable_family's Introduction

Runnable Family

GitHub top language GitHub tag (latest SemVer) GitHub GitHub last commit

Scheduled Test

A python library implementing a family of Runnables in langchain like loopback, self-consistent, self-refine, and self-translate.

Requirements

  • Python 3.10 or higher

See the pyproject.toml file for the required packages.

Installation

First, you should create a virtual environment before installing the package.

  • On Unix or MacOS:

    python -m venv venv
    source venv/bin/activate
  • On Windows:

    python -m venv venv
    venv\Scripts\activate

After creating the virtual environment, you can install the package using pip:

pip install git+https://github.com/hmasdev/runnable_family

or you can clone the repository and install the package using pip:

git clone https://github.com/hmasdev/runnable_family
cd runnable_family
pip install .

Usage

Just import your favorite classes.

from runnable_family.basic import RunnableConstant, RunnableAdd, RunnablePartialLambda, RunnableLog
from runnable_family.loopback import RunnableLoopback
from runnable_family.gacha import RunnableGacha
from runnable_family.random import RunnableRandomBranch
from runnable_family.runnable_diff import RunnableDiff
from runnable_family.self_consistent import RunnableSelfConsistent
from runnable_family.self_refine import RunnableSelfRefine
from runnable_family.self_translate import RunnableSelfTranslate

They are inherited from the Runnable class, so you can use them as a Runnable, that is, you can use them as chain components.

See basic-examples.ipynb to see how to use them.

Development

  1. Fork the repository: https://github.com/hmasdev/runnable_family

  2. Clone the repository

    git clone https://github.com/{YOURE_NAME}/runnable_family
    cd runnable_family
  3. Create a virtual environment

    python -m venv venv
    source venv/bin/activate
  4. Install the required packages

    pip install -e .[dev]
  5. Checkout your working branch

    git checkout -b your-working-branch
  6. Make your changes

  7. Test your changes

    pytest
    flake8 runnable_family tests
    mypy runnable_family tests
  8. Commit your changes

    git add .
    git commit -m "Your commit message"
  9. Push your changes

    git push origin your-working-branch
  10. Create a pull request: https://github.com/hmasdev/runnable_family/compare

License

MIT

Author

hmasdev

runnable_family's People

Contributors

hmasdev avatar github-actions[bot] avatar

Watchers

Kostas Georgiou avatar  avatar

runnable_family's Issues

`RunnableLoopback` is too slow.

I have used the following script performance.py to compare RunanbleLoopback and a equivalent graph of langgraph:

from contextlib import contextmanager
import time
from langgraph.graph import Graph, END
from langchain_core.runnables import RunnableLambda, RunnablePassthrough
from runnable_family import RunnableLoopback

countdown = RunnableLambda(lambda n: n-1)

loopback_chain = RunnableLoopback(countdown, RunnableLambda(lambda n: n > 1), RunnablePassthrough())  # noqa

workflow = Graph()
workflow.add_node('countdown', countdown.invoke)
workflow.add_conditional_edges('countdown', lambda n: "continue" if n > 1 else 'end', {'continue': 'countdown', 'end': END})  # noqa
workflow.set_entry_point('countdown')
loopback_graph_compiled = workflow.compile()

@contextmanager
def measure_time():
    start = time.time()
    yield
    print(time.time() - start)

with measure_time():
    loopback_chain.invoke(100)
with measure_time():
    loopback_graph_compiled.invoke(100, {"recursion_limit": 1000})

The results of 3 trials as follows:

$ python performance.py 2>/dev/null
1.2169935703277588
0.6739192008972168
$ python performance.py 2>/dev/null
1.1129276752471924
0.7416691780090332
$ python performance.py 2>/dev/null
1.158017873764038
0.7393209934234619

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.