dm-aioaiagent


Namedm-aioaiagent JSON
Version 0.3.4 PyPI version JSON
download
home_pagehttps://pypi.org/project/dm-aioaiagent
SummaryThis is my custom aioaiagent client
upload_time2024-12-11 18:50:06
maintainerNone
docs_urlNone
authordimka4621
requires_python>=3.9
licenseNone
keywords dm aioaiagent
VCS
bugtrack_url
requirements dm-logger python-dotenv pydantic langchain langchain-core langgraph grandalf langchain-community langchain-openai
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # DM-aioaiagent

## Urls

* [PyPI](https://pypi.org/project/dm-aioaiagent)
* [GitHub](https://github.com/MykhLibs/dm-aioaiagent)

### * Package contains both `asynchronous` and `synchronous` clients

## Usage

Analogue to `DMAioAIAgent` is the synchronous client `DMAIAgent`.

### Use agent *with* inner memory

By default, agent use inner memory to store the conversation history.

(You can set *max count messages in memory* by `max_memory_messages` init argument)

```python
import asyncio
from dm_aioaiagent import DMAioAIAgent


async def main():
    # define a system message
    system_message = "Your custom system message with role, backstory and goal"

    # (optional) define a list of tools, if you want to use them
    tools = [...]

    # define a openai model, default is "gpt-4o-mini"
    model_name = "gpt-4o"

    # create an agent
    ai_agent = DMAioAIAgent(system_message, tools, model=model_name)
    # if you don't want to see the input and output messages from agent
    # you can set `input_output_logging=False` init argument

    # define the conversation message
    input_messages = [
        {"role": "user", "content": "Hello!"},
    ]

    # call an agent
    # specify `memory_id` argument to store the conversation history by your custom id
    answer = await ai_agent.run(input_messages)

    # define the next conversation message
    input_messages = [
        {"role": "user", "content": "I want to know the weather in Kyiv"}
    ]

    # call an agent
    answer = await ai_agent.run(input_messages)

    # get full conversation history
    conversation_history = ai_agent.get_memory_messages()

    # clear conversation history
    ai_agent.clear_memory()


if __name__ == "__main__":
    asyncio.run(main())
```

### Use agent *without* inner memory

If you want to control the memory of the agent, you can disable it by setting `is_memory_enabled=False`

```python
import asyncio
from dm_aioaiagent import DMAioAIAgent


async def main():
    # define a system message
    system_message = "Your custom system message with role, backstory and goal"

    # (optional) define a list of tools, if you want to use them
    tools = [...]

    # define a openai model, default is "gpt-4o-mini"
    model_name = "gpt-4o"

    # create an agent
    ai_agent = DMAioAIAgent(system_message, tools, model=model_name,
                            is_memory_enabled=False)
    # if you don't want to see the input and output messages from agent
    # you can set input_output_logging=False

    # define the conversation message
    messages = [
        {"role": "user", "content": "Hello!"}
    ]

    # call an agent
    new_messages = await ai_agent.run(messages)

    # add new_messages to messages
    messages.extend(new_messages)

    # define the next conversation message
    messages.append(
        {"role": "user", "content": "I want to know the weather in Kyiv"}
    )

    # call an agent
    new_messages = await ai_agent.run(messages)


if __name__ == "__main__":
    asyncio.run(main())
```

### Image vision

```python
from dm_aioaiagent import DMAIAgent, ImageMessageContentBuilder

def main():
    # create an agent
    ai_agent = DMAIAgent(agent_name="image_vision", model="gpt-4o")

    # create an image message content
    # NOTE: text argument is optional
    img_content = ImageMessageContentBuilder(image_url="https://your.domain/image",
                                             text="Hello, what is shown in the photo?")

    # define the conversation message
    messages = [
        {"role": "user", "content": "Hello!"},
        {"role": "user", "content": img_content},
    ]

    # call an agent
    answer = ai_agent.run(messages)


if __name__ == "__main__":
   main()
```

### Set custom logger

_If you want set up custom logger_

```python
from dm_aioaiagent import DMAioAIAgent


# create custom logger
class MyLogger:
    def debug(self, message):
        pass

    def info(self, message):
        pass

    def warning(self, message):
        print(message)

    def error(self, message):
        print(message)


# create an agent
ai_agent = DMAioAIAgent()

# set up custom logger for this agent
ai_agent.set_logger(MyLogger())
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://pypi.org/project/dm-aioaiagent",
    "name": "dm-aioaiagent",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "dm aioaiagent",
    "author": "dimka4621",
    "author_email": "mismartconfig@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/6e/20/2c42461a0306efe111eb75a779bc17cdb8be087c21d51e0c3aeb2df737a7/dm_aioaiagent-0.3.4.tar.gz",
    "platform": null,
    "description": "# DM-aioaiagent\n\n## Urls\n\n* [PyPI](https://pypi.org/project/dm-aioaiagent)\n* [GitHub](https://github.com/MykhLibs/dm-aioaiagent)\n\n### * Package contains both `asynchronous` and `synchronous` clients\n\n## Usage\n\nAnalogue to `DMAioAIAgent` is the synchronous client `DMAIAgent`.\n\n### Use agent *with* inner memory\n\nBy default, agent use inner memory to store the conversation history.\n\n(You can set *max count messages in memory* by `max_memory_messages` init argument)\n\n```python\nimport asyncio\nfrom dm_aioaiagent import DMAioAIAgent\n\n\nasync def main():\n    # define a system message\n    system_message = \"Your custom system message with role, backstory and goal\"\n\n    # (optional) define a list of tools, if you want to use them\n    tools = [...]\n\n    # define a openai model, default is \"gpt-4o-mini\"\n    model_name = \"gpt-4o\"\n\n    # create an agent\n    ai_agent = DMAioAIAgent(system_message, tools, model=model_name)\n    # if you don't want to see the input and output messages from agent\n    # you can set `input_output_logging=False` init argument\n\n    # define the conversation message\n    input_messages = [\n        {\"role\": \"user\", \"content\": \"Hello!\"},\n    ]\n\n    # call an agent\n    # specify `memory_id` argument to store the conversation history by your custom id\n    answer = await ai_agent.run(input_messages)\n\n    # define the next conversation message\n    input_messages = [\n        {\"role\": \"user\", \"content\": \"I want to know the weather in Kyiv\"}\n    ]\n\n    # call an agent\n    answer = await ai_agent.run(input_messages)\n\n    # get full conversation history\n    conversation_history = ai_agent.get_memory_messages()\n\n    # clear conversation history\n    ai_agent.clear_memory()\n\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\n### Use agent *without* inner memory\n\nIf you want to control the memory of the agent, you can disable it by setting `is_memory_enabled=False`\n\n```python\nimport asyncio\nfrom dm_aioaiagent import DMAioAIAgent\n\n\nasync def main():\n    # define a system message\n    system_message = \"Your custom system message with role, backstory and goal\"\n\n    # (optional) define a list of tools, if you want to use them\n    tools = [...]\n\n    # define a openai model, default is \"gpt-4o-mini\"\n    model_name = \"gpt-4o\"\n\n    # create an agent\n    ai_agent = DMAioAIAgent(system_message, tools, model=model_name,\n                            is_memory_enabled=False)\n    # if you don't want to see the input and output messages from agent\n    # you can set input_output_logging=False\n\n    # define the conversation message\n    messages = [\n        {\"role\": \"user\", \"content\": \"Hello!\"}\n    ]\n\n    # call an agent\n    new_messages = await ai_agent.run(messages)\n\n    # add new_messages to messages\n    messages.extend(new_messages)\n\n    # define the next conversation message\n    messages.append(\n        {\"role\": \"user\", \"content\": \"I want to know the weather in Kyiv\"}\n    )\n\n    # call an agent\n    new_messages = await ai_agent.run(messages)\n\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\n### Image vision\n\n```python\nfrom dm_aioaiagent import DMAIAgent, ImageMessageContentBuilder\n\ndef main():\n    # create an agent\n    ai_agent = DMAIAgent(agent_name=\"image_vision\", model=\"gpt-4o\")\n\n    # create an image message content\n    # NOTE: text argument is optional\n    img_content = ImageMessageContentBuilder(image_url=\"https://your.domain/image\",\n                                             text=\"Hello, what is shown in the photo?\")\n\n    # define the conversation message\n    messages = [\n        {\"role\": \"user\", \"content\": \"Hello!\"},\n        {\"role\": \"user\", \"content\": img_content},\n    ]\n\n    # call an agent\n    answer = ai_agent.run(messages)\n\n\nif __name__ == \"__main__\":\n   main()\n```\n\n### Set custom logger\n\n_If you want set up custom logger_\n\n```python\nfrom dm_aioaiagent import DMAioAIAgent\n\n\n# create custom logger\nclass MyLogger:\n    def debug(self, message):\n        pass\n\n    def info(self, message):\n        pass\n\n    def warning(self, message):\n        print(message)\n\n    def error(self, message):\n        print(message)\n\n\n# create an agent\nai_agent = DMAioAIAgent()\n\n# set up custom logger for this agent\nai_agent.set_logger(MyLogger())\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "This is my custom aioaiagent client",
    "version": "0.3.4",
    "project_urls": {
        "GitHub": "https://github.com/MykhLibs/dm-aioaiagent",
        "Homepage": "https://pypi.org/project/dm-aioaiagent"
    },
    "split_keywords": [
        "dm",
        "aioaiagent"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "adead459459523e4dee8aa099ba959ee9f752e502e35405c35f84fe034417529",
                "md5": "9c30fb12e27b90badf19292ec96afd64",
                "sha256": "4b3b5ed590e688f5c12a54db6efebf2017aab5509fc54ae9c8a27c2e0913ccb5"
            },
            "downloads": -1,
            "filename": "dm_aioaiagent-0.3.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9c30fb12e27b90badf19292ec96afd64",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 7577,
            "upload_time": "2024-12-11T18:50:04",
            "upload_time_iso_8601": "2024-12-11T18:50:04.710944Z",
            "url": "https://files.pythonhosted.org/packages/ad/ea/d459459523e4dee8aa099ba959ee9f752e502e35405c35f84fe034417529/dm_aioaiagent-0.3.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6e202c42461a0306efe111eb75a779bc17cdb8be087c21d51e0c3aeb2df737a7",
                "md5": "876ba522c55e4ef513fdf76fa9755214",
                "sha256": "16b10da2d37fca3db393a242e33970b105029a298714483715f9f8c66633c8e2"
            },
            "downloads": -1,
            "filename": "dm_aioaiagent-0.3.4.tar.gz",
            "has_sig": false,
            "md5_digest": "876ba522c55e4ef513fdf76fa9755214",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 6969,
            "upload_time": "2024-12-11T18:50:06",
            "upload_time_iso_8601": "2024-12-11T18:50:06.076910Z",
            "url": "https://files.pythonhosted.org/packages/6e/20/2c42461a0306efe111eb75a779bc17cdb8be087c21d51e0c3aeb2df737a7/dm_aioaiagent-0.3.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-11 18:50:06",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "MykhLibs",
    "github_project": "dm-aioaiagent",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "dm-logger",
            "specs": [
                [
                    "~=",
                    "0.5.2"
                ]
            ]
        },
        {
            "name": "python-dotenv",
            "specs": [
                [
                    ">=",
                    "1.0.0"
                ]
            ]
        },
        {
            "name": "pydantic",
            "specs": [
                [
                    "<",
                    "3.0.0"
                ],
                [
                    ">=",
                    "2.9.2"
                ]
            ]
        },
        {
            "name": "langchain",
            "specs": [
                [
                    "~=",
                    "0.3.0"
                ]
            ]
        },
        {
            "name": "langchain-core",
            "specs": [
                [
                    "~=",
                    "0.3.5"
                ]
            ]
        },
        {
            "name": "langgraph",
            "specs": [
                [
                    "~=",
                    "0.2.23"
                ]
            ]
        },
        {
            "name": "grandalf",
            "specs": [
                [
                    ">=",
                    "0.8"
                ]
            ]
        },
        {
            "name": "langchain-community",
            "specs": [
                [
                    "~=",
                    "0.3.0"
                ]
            ]
        },
        {
            "name": "langchain-openai",
            "specs": [
                [
                    "~=",
                    "0.2.0"
                ]
            ]
        }
    ],
    "lcname": "dm-aioaiagent"
}
        
Elapsed time: 3.15124s