longchain


Namelongchain JSON
Version 0.4.1 PyPI version JSON
download
home_pageNone
SummaryA framework for LLM-powered interactions
upload_time2024-08-26 16:28:18
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licensePermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords ai chatbot llm npc slack
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # longchain
## Usage
* `Quest` - The main object. Ititialize it, then call `asyncio.run(quest.run())` to run it.
* `Path` - A Path is one "step" in a player's experience. 
* `ActionResolver` - This is the real decision-making part of the `Path`. The two main ones are the `SequentialActionResolver`, which takes several `Action`s and just runs them in order, and the `LlmActionResolver`, which uses an LLM to decide what to do.
  * `starts_without_player_action` - If this parameter is `True`, then a `ChangePathAction` with `next_action='path'` can immediately call this `ActionResolver` without waiting for player input.
* `AgentAction` - This is a single step a path takes. It's something like sending a message or moving to another path. They have a `next_action` parameter which controls whether the player is prompted for an input or not before the next action happens.
* `core` vs `impl` vs `plugins` - `core` is the main part of the library, `impl` is the implementation of the `core` interfaces, and `plugins` are more niche implementations. For example, the path following code is in `core`, the `LlmActionResolver` is in `impl`, and the Bag utilities are in `plugins`.
* `Datastore` - This is an interface for the quest to keep player state. The only one currently implemented is `jsonfile`, but another one could be implemented for a database or something.
* `Messager` - Like Datastore, this is an abstraction layer that allows the quest to send messages to the player. The only one currently implemented is `slack`.
* `LlmActionResolver` - There's a lot here so it gets its own bullet point. The LLM automatically talks to the player, and you can add `LlmTool`s in the `agent_actions` parameter to allow it to do more. The `system_prompt` parameter can either be a string or a callable taking an `LlmContext`. This allows the system prompt to change based on what's going on, which is recommended (LLMs are not good at keeping information secret).
  * `LlmTool` - These describe an action the LLM can take. `description` should tell the LLM when to call the tool. `params` is a list of `LlmToolParam`s, which have a `name` and a `schema` (which is a JSON Schema object).  `available` and `action` are callables that take an `LlmContext` and return a boolean and an `AgentAction` respectively. `available` should return `True` if the tool can be used, and `action` should return the `AgentAction` to take if the tool is used. These both get `LlmContext`s, and `action` also gets a `dict` of the params the LLM called the action with. `strict` can turn on structured output, which forces the LLM's output to conform to the `params` perfectly but disables some JSON Schema properties. [See more in the OpenAI docs.](https://platform.openai.com/docs/guides/function-calling/function-calling-with-structured-outputs). If `strict` is off, don't trust the LLM to call your function correctly.

### Example
There is an example project in the [examples folder](https://github.com/rivques/longchain/tree/main/examples/sockthief).
## Development
### to build:
```
.\venv\Scripts\activate
py -m build
python -m twine upload dist/*
```
### to regenerate the bag api:
1. download the update bag.proto
2. `pip install grpcio grpcio_tools`
3. run `cd .\src\longchain\plugins\bag\api\`
4. run `python -m grpc_tools.protoc -I . --grpc_python_out . --python_out . --pyi_out . bag.proto`
5. Go to the generated bag_pb2_grpc.py and change the `bag_pb2` import to `import longchain.plugins.bag.api.bag_pb2 as bag__pb2`
## Naming
It's a tool for making _long chains_ of NPC interactions.
            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "longchain",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "ai, chatbot, llm, npc, slack",
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/a4/80/977740b5353fe52f45a2f4b78cfa206f56478e22494d9d64e5588152a33b/longchain-0.4.1.tar.gz",
    "platform": null,
    "description": "# longchain\n## Usage\n* `Quest` - The main object. Ititialize it, then call `asyncio.run(quest.run())` to run it.\n* `Path` - A Path is one \"step\" in a player's experience. \n* `ActionResolver` - This is the real decision-making part of the `Path`. The two main ones are the `SequentialActionResolver`, which takes several `Action`s and just runs them in order, and the `LlmActionResolver`, which uses an LLM to decide what to do.\n  * `starts_without_player_action` - If this parameter is `True`, then a `ChangePathAction` with `next_action='path'` can immediately call this `ActionResolver` without waiting for player input.\n* `AgentAction` - This is a single step a path takes. It's something like sending a message or moving to another path. They have a `next_action` parameter which controls whether the player is prompted for an input or not before the next action happens.\n* `core` vs `impl` vs `plugins` - `core` is the main part of the library, `impl` is the implementation of the `core` interfaces, and `plugins` are more niche implementations. For example, the path following code is in `core`, the `LlmActionResolver` is in `impl`, and the Bag utilities are in `plugins`.\n* `Datastore` - This is an interface for the quest to keep player state. The only one currently implemented is `jsonfile`, but another one could be implemented for a database or something.\n* `Messager` - Like Datastore, this is an abstraction layer that allows the quest to send messages to the player. The only one currently implemented is `slack`.\n* `LlmActionResolver` - There's a lot here so it gets its own bullet point. The LLM automatically talks to the player, and you can add `LlmTool`s in the `agent_actions` parameter to allow it to do more. The `system_prompt` parameter can either be a string or a callable taking an `LlmContext`. This allows the system prompt to change based on what's going on, which is recommended (LLMs are not good at keeping information secret).\n  * `LlmTool` - These describe an action the LLM can take. `description` should tell the LLM when to call the tool. `params` is a list of `LlmToolParam`s, which have a `name` and a `schema` (which is a JSON Schema object).  `available` and `action` are callables that take an `LlmContext` and return a boolean and an `AgentAction` respectively. `available` should return `True` if the tool can be used, and `action` should return the `AgentAction` to take if the tool is used. These both get `LlmContext`s, and `action` also gets a `dict` of the params the LLM called the action with. `strict` can turn on structured output, which forces the LLM's output to conform to the `params` perfectly but disables some JSON Schema properties. [See more in the OpenAI docs.](https://platform.openai.com/docs/guides/function-calling/function-calling-with-structured-outputs). If `strict` is off, don't trust the LLM to call your function correctly.\n\n### Example\nThere is an example project in the [examples folder](https://github.com/rivques/longchain/tree/main/examples/sockthief).\n## Development\n### to build:\n```\n.\\venv\\Scripts\\activate\npy -m build\npython -m twine upload dist/*\n```\n### to regenerate the bag api:\n1. download the update bag.proto\n2. `pip install grpcio grpcio_tools`\n3. run `cd .\\src\\longchain\\plugins\\bag\\api\\`\n4. run `python -m grpc_tools.protoc -I . --grpc_python_out . --python_out . --pyi_out . bag.proto`\n5. Go to the generated bag_pb2_grpc.py and change the `bag_pb2` import to `import longchain.plugins.bag.api.bag_pb2 as bag__pb2`\n## Naming\nIt's a tool for making _long chains_ of NPC interactions.",
    "bugtrack_url": null,
    "license": "Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "A framework for LLM-powered interactions",
    "version": "0.4.1",
    "project_urls": {
        "Respository": "https://github.com/rivques/longchain"
    },
    "split_keywords": [
        "ai",
        " chatbot",
        " llm",
        " npc",
        " slack"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c6e236fbe091afb934eea7b738c3fffdcc227279631b811a1148b2bf2f888c33",
                "md5": "97d3da6aa175bd719a5615d9df03b1b9",
                "sha256": "0f0d17eb89fedd8c1d1edf369e208c912c835104cfa60381a23b8e437f34c31e"
            },
            "downloads": -1,
            "filename": "longchain-0.4.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "97d3da6aa175bd719a5615d9df03b1b9",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 33276,
            "upload_time": "2024-08-26T16:28:17",
            "upload_time_iso_8601": "2024-08-26T16:28:17.637717Z",
            "url": "https://files.pythonhosted.org/packages/c6/e2/36fbe091afb934eea7b738c3fffdcc227279631b811a1148b2bf2f888c33/longchain-0.4.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a480977740b5353fe52f45a2f4b78cfa206f56478e22494d9d64e5588152a33b",
                "md5": "3002a7d7eb4362f5d414bc433c7ba904",
                "sha256": "e116178d91c863360f4b866a29295dc8e14c5785772495a73ce6d690c86dc5e7"
            },
            "downloads": -1,
            "filename": "longchain-0.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "3002a7d7eb4362f5d414bc433c7ba904",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 29487,
            "upload_time": "2024-08-26T16:28:18",
            "upload_time_iso_8601": "2024-08-26T16:28:18.556305Z",
            "url": "https://files.pythonhosted.org/packages/a4/80/977740b5353fe52f45a2f4b78cfa206f56478e22494d9d64e5588152a33b/longchain-0.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-26 16:28:18",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rivques",
    "github_project": "longchain",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "longchain"
}
        
Elapsed time: 0.32099s