langchain-prefect


Namelangchain-prefect JSON
Version 0.0.3 PyPI version JSON
download
home_pagehttps://github.com/PrefectHQ/langchain-prefect
SummaryOrchestrate and observe tools built with langchain.
upload_time2023-06-08 22:00:39
maintainer
docs_urlNone
authorPrefect Technologies
requires_python>=3.10
licenseApache License 2.0
keywords prefect
VCS
bugtrack_url
requirements prefect langchain tiktoken
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # langchain-prefect

<p align="center">
    <!--- Insert a cover image here -->
    <!--- <br> -->
    <img src="https://user-images.githubusercontent.com/31014960/224118318-02e49d8e-72e0-4850-93f7-d850c0f06ca1.png">
    <a href="https://pypi.python.org/pypi/langchain-prefect/" alt="PyPI version">
        <img alt="PyPI" src="https://img.shields.io/pypi/v/langchain-prefect?color=0052FF&labelColor=090422"></a>
    <a href="https://github.com/PrefectHQ/langchain-prefect/" alt="Stars">
        <img src="https://img.shields.io/github/stars/PrefectHQ/langchain-prefect?color=0052FF&labelColor=090422" /></a>
    <a href="https://pypistats.org/packages/langchain-prefect/" alt="Downloads">
        <img src="https://img.shields.io/pypi/dm/langchain-prefect?color=0052FF&labelColor=090422" /></a>
    <a href="https://github.com/PrefectHQ/langchain-prefect/pulse" alt="Activity">
        <img src="https://img.shields.io/github/commit-activity/m/PrefectHQ/langchain-prefect?color=0052FF&labelColor=090422" /></a>
    <br>
    <a href="https://prefect-community.slack.com" alt="Slack">
        <img src="https://img.shields.io/badge/slack-join_community-red.svg?color=0052FF&labelColor=090422&logo=slack" /></a>
    <a href="https://discourse.prefect.io/" alt="Discourse">
        <img src="https://img.shields.io/badge/discourse-browse_forum-red.svg?color=0052FF&labelColor=090422&logo=discourse" /></a>
</p>

Read the [accompanying article](https://medium.com/the-prefect-blog/keeping-your-eyes-on-your-ai-tools-6428664537da) for background

## Orchestrate and observe langchain using Prefect

Large Language Models (LLMs) are interesting and useful  -  building apps that use them responsibly feels like a no-brainer. Tools like [Langchain](https://github.com/hwchase17/langchain) make it easier to build apps using LLMs. We need to know details about how our apps work, even when we want to use tools with convenient abstractions that may obfuscate those details.

Prefect is built to help data people build, run, and observe event-driven workflows wherever they want. It provides a framework for creating deployments on a whole slew of runtime environments (from Lambda to Kubernetes), and is cloud agnostic (best supports AWS, GCP, Azure). For this reason, it could be a great fit for observing apps that use LLMs.

## Features
- `RecordLLMCalls` is a `ContextDecorator` that can be used to track LLM calls made by Langchain LLMs as Prefect flows.

### Call an LLM and track the invocation with Prefect:
```python
from langchain.llms import OpenAI
from langchain_prefect.plugins import RecordLLMCalls

with RecordLLMCalls():
    llm = OpenAI(temperature=0.9)
    text = (
        "What would be a good company name for a company that makes colorful socks?"
    )
    llm(text)
```
and a flow run will be created to track the invocation of the LLM:

<p align="center">
    <img src="https://user-images.githubusercontent.com/31014960/224114166-f2c7d5ed-49b6-406e-a384-bd327d4e1fe4.png" alt="LLM invocation UI">
</p>

### Run several LLM calls via langchain agent as Prefect subflows:
```python
from langchain.agents import initialize_agent, load_tools
from langchain.llms import OpenAI

from prefect import flow

llm = OpenAI(temperature=0)
tools = load_tools(["llm-math"], llm=llm)
agent = initialize_agent(tools, llm)

@flow
def my_flow():
    agent.run(
        "How old is the current Dalai Lama? "
        "What is his age divided by 2 (rounded to the nearest integer)?"
    )

with RecordLLMCalls(tags={"agent"}):
    my_flow()
```

<p align="center">
    <img src="https://user-images.githubusercontent.com/31014960/224113843-b91f204b-8085-4739-b483-a45c4f339210.png" alt="LLM agent UI">
</p>

Find more examples [here](examples/).

## How do I get a Prefect UI?
- The easiest way is to use the [Prefect Cloud](https://www.prefect.io/cloud/) UI for free. You can find details on getting setup [here](https://docs.prefect.io/ui/cloud-quickstart/).

- If you don't want to sign up for cloud, you can use the dashboard locally by running `prefect server start` in your terminal - more details [here](https://docs.prefect.io/ui/overview/#using-the-prefect-ui).


## Resources
### Installation

```bash
pip install langchain-prefect
```

Requires an installation of Python 3.10+.

### Feedback

If you encounter any bugs while using `langchain-prefect`, feel free to open an issue in the [langchain-prefect](https://github.com/PrefectHQ/langchain-prefect) repository.

Feel free to star or watch [`langchain-prefect`](https://github.com/PrefectHQ/langchain-prefect) for updates too!

### Contributing

If you'd like to help contribute to fix an issue or add a feature to `langchain-prefect`, please [propose changes through a pull request from a fork of the repository](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork).

Here are the steps:

1. [Fork the repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo#forking-a-repository)
2. [Clone the forked repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo#cloning-your-forked-repository)
3. Install the repository and its dependencies:
```
pip install -e ".[dev]"
```
4. Make desired changes
5. Add tests
6. Insert an entry to [CHANGELOG.md](https://github.com/PrefectHQ/langchain-prefect/blob/main/CHANGELOG.md)
7. Install `pre-commit` to perform quality checks prior to commit:
```
pre-commit install
```
8. `git commit`, `git push`, and create a pull request

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/PrefectHQ/langchain-prefect",
    "name": "langchain-prefect",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "prefect",
    "author": "Prefect Technologies",
    "author_email": "nate@prefect.io",
    "download_url": "https://files.pythonhosted.org/packages/11/1e/d72c8b8146ff92db235a8e962769ef5c122908f3ac2ab8dafcbd60b976d4/langchain-prefect-0.0.3.tar.gz",
    "platform": null,
    "description": "# langchain-prefect\n\n<p align=\"center\">\n    <!--- Insert a cover image here -->\n    <!--- <br> -->\n    <img src=\"https://user-images.githubusercontent.com/31014960/224118318-02e49d8e-72e0-4850-93f7-d850c0f06ca1.png\">\n    <a href=\"https://pypi.python.org/pypi/langchain-prefect/\" alt=\"PyPI version\">\n        <img alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/langchain-prefect?color=0052FF&labelColor=090422\"></a>\n    <a href=\"https://github.com/PrefectHQ/langchain-prefect/\" alt=\"Stars\">\n        <img src=\"https://img.shields.io/github/stars/PrefectHQ/langchain-prefect?color=0052FF&labelColor=090422\" /></a>\n    <a href=\"https://pypistats.org/packages/langchain-prefect/\" alt=\"Downloads\">\n        <img src=\"https://img.shields.io/pypi/dm/langchain-prefect?color=0052FF&labelColor=090422\" /></a>\n    <a href=\"https://github.com/PrefectHQ/langchain-prefect/pulse\" alt=\"Activity\">\n        <img src=\"https://img.shields.io/github/commit-activity/m/PrefectHQ/langchain-prefect?color=0052FF&labelColor=090422\" /></a>\n    <br>\n    <a href=\"https://prefect-community.slack.com\" alt=\"Slack\">\n        <img src=\"https://img.shields.io/badge/slack-join_community-red.svg?color=0052FF&labelColor=090422&logo=slack\" /></a>\n    <a href=\"https://discourse.prefect.io/\" alt=\"Discourse\">\n        <img src=\"https://img.shields.io/badge/discourse-browse_forum-red.svg?color=0052FF&labelColor=090422&logo=discourse\" /></a>\n</p>\n\nRead the [accompanying article](https://medium.com/the-prefect-blog/keeping-your-eyes-on-your-ai-tools-6428664537da) for background\n\n## Orchestrate and observe langchain using Prefect\n\nLarge Language Models (LLMs) are interesting and useful\u200a - \u200abuilding apps that use them responsibly feels like a no-brainer. Tools like [Langchain](https://github.com/hwchase17/langchain) make it easier to build apps using LLMs. We need to know details about how our apps work, even when we want to use tools with convenient abstractions that may obfuscate those details.\n\nPrefect is built to help data people build, run, and observe event-driven workflows wherever they want. It provides a framework for creating deployments on a whole slew of runtime environments (from Lambda to Kubernetes), and is cloud agnostic (best supports AWS, GCP, Azure). For this reason, it could be a great fit for observing apps that use LLMs.\n\n## Features\n- `RecordLLMCalls` is a `ContextDecorator` that can be used to track LLM calls made by Langchain LLMs as Prefect flows.\n\n### Call an LLM and track the invocation with Prefect:\n```python\nfrom langchain.llms import OpenAI\nfrom langchain_prefect.plugins import RecordLLMCalls\n\nwith RecordLLMCalls():\n    llm = OpenAI(temperature=0.9)\n    text = (\n        \"What would be a good company name for a company that makes colorful socks?\"\n    )\n    llm(text)\n```\nand a flow run will be created to track the invocation of the LLM:\n\n<p align=\"center\">\n    <img src=\"https://user-images.githubusercontent.com/31014960/224114166-f2c7d5ed-49b6-406e-a384-bd327d4e1fe4.png\" alt=\"LLM invocation UI\">\n</p>\n\n### Run several LLM calls via langchain agent as Prefect subflows:\n```python\nfrom langchain.agents import initialize_agent, load_tools\nfrom langchain.llms import OpenAI\n\nfrom prefect import flow\n\nllm = OpenAI(temperature=0)\ntools = load_tools([\"llm-math\"], llm=llm)\nagent = initialize_agent(tools, llm)\n\n@flow\ndef my_flow():\n    agent.run(\n        \"How old is the current Dalai Lama? \"\n        \"What is his age divided by 2 (rounded to the nearest integer)?\"\n    )\n\nwith RecordLLMCalls(tags={\"agent\"}):\n    my_flow()\n```\n\n<p align=\"center\">\n    <img src=\"https://user-images.githubusercontent.com/31014960/224113843-b91f204b-8085-4739-b483-a45c4f339210.png\" alt=\"LLM agent UI\">\n</p>\n\nFind more examples [here](examples/).\n\n## How do I get a Prefect UI?\n- The easiest way is to use the [Prefect Cloud](https://www.prefect.io/cloud/) UI for free. You can find details on getting setup [here](https://docs.prefect.io/ui/cloud-quickstart/).\n\n- If you don't want to sign up for cloud, you can use the dashboard locally by running `prefect server start` in your terminal - more details [here](https://docs.prefect.io/ui/overview/#using-the-prefect-ui).\n\n\n## Resources\n### Installation\n\n```bash\npip install langchain-prefect\n```\n\nRequires an installation of Python 3.10+.\n\n### Feedback\n\nIf you encounter any bugs while using `langchain-prefect`, feel free to open an issue in the [langchain-prefect](https://github.com/PrefectHQ/langchain-prefect) repository.\n\nFeel free to star or watch [`langchain-prefect`](https://github.com/PrefectHQ/langchain-prefect) for updates too!\n\n### Contributing\n\nIf you'd like to help contribute to fix an issue or add a feature to `langchain-prefect`, please [propose changes through a pull request from a fork of the repository](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork).\n\nHere are the steps:\n\n1. [Fork the repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo#forking-a-repository)\n2. [Clone the forked repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo#cloning-your-forked-repository)\n3. Install the repository and its dependencies:\n```\npip install -e \".[dev]\"\n```\n4. Make desired changes\n5. Add tests\n6. Insert an entry to [CHANGELOG.md](https://github.com/PrefectHQ/langchain-prefect/blob/main/CHANGELOG.md)\n7. Install `pre-commit` to perform quality checks prior to commit:\n```\npre-commit install\n```\n8. `git commit`, `git push`, and create a pull request\n",
    "bugtrack_url": null,
    "license": "Apache License 2.0",
    "summary": "Orchestrate and observe tools built with langchain.",
    "version": "0.0.3",
    "project_urls": {
        "Homepage": "https://github.com/PrefectHQ/langchain-prefect"
    },
    "split_keywords": [
        "prefect"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8583330cef6b1271c084246505f69caa6dcd9f0c72e70c5d20bc7282926e425b",
                "md5": "75b35e5e265bdbef38f06c0b6533cde7",
                "sha256": "dcf0f4e21c31d55a9fe41dd6e3c3fd55bd51ea4308f80c34cc4a82d76c4b73b7"
            },
            "downloads": -1,
            "filename": "langchain_prefect-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "75b35e5e265bdbef38f06c0b6533cde7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 14403,
            "upload_time": "2023-06-08T22:00:37",
            "upload_time_iso_8601": "2023-06-08T22:00:37.611743Z",
            "url": "https://files.pythonhosted.org/packages/85/83/330cef6b1271c084246505f69caa6dcd9f0c72e70c5d20bc7282926e425b/langchain_prefect-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "111ed72c8b8146ff92db235a8e962769ef5c122908f3ac2ab8dafcbd60b976d4",
                "md5": "b79e90068f81739b29cb21991252101c",
                "sha256": "cd8528a26c6460944fb406a7b9c646242fa0b99f8f46504db0777295d46c5cf1"
            },
            "downloads": -1,
            "filename": "langchain-prefect-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "b79e90068f81739b29cb21991252101c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 33841,
            "upload_time": "2023-06-08T22:00:39",
            "upload_time_iso_8601": "2023-06-08T22:00:39.059938Z",
            "url": "https://files.pythonhosted.org/packages/11/1e/d72c8b8146ff92db235a8e962769ef5c122908f3ac2ab8dafcbd60b976d4/langchain-prefect-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-08 22:00:39",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "PrefectHQ",
    "github_project": "langchain-prefect",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "prefect",
            "specs": [
                [
                    ">=",
                    "2.8.4"
                ]
            ]
        },
        {
            "name": "langchain",
            "specs": [
                [
                    ">=",
                    "0.0.27"
                ]
            ]
        },
        {
            "name": "tiktoken",
            "specs": [
                [
                    ">=",
                    "0.3.0"
                ]
            ]
        }
    ],
    "lcname": "langchain-prefect"
}
        
Elapsed time: 0.14063s