Skip to main content

This is my custom aioaiagent client

Project description

DM-aioaiagent

Urls

* Package contains both asynchronous and synchronous clients

Usage

Analogue to DMAioAIAgent is the synchronous client DMAIAgent.

Windows Setup

import asyncio
import sys

if sys.platform == "win32":
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

Api Key Setup

You can set your OpenAI API key in the environment variable OPENAI_API_KEY or pass it as an argument to the agent.

Use load_dotenv to load the .env file.

from dotenv import load_dotenv
load_dotenv()

Use agent with inner memory and run single message

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)

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

    # call an agent
    answer = await ai_agent.run("Hello!")

    # call an agent
    answer = await ai_agent.run("I want to know the weather in Kyiv")

    # get full conversation history
    conversation_history = ai_agent.memory_messages

    # clear conversation history
    ai_agent.clear_memory_messages()


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

Use agent without inner memory and run multiple messages

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

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(s)
    messages = [
        {"role": "user", "content": "Hello!"}
    ]

    # call an agent
    new_messages = await ai_agent.run_messages(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(messages)


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

Image vision

from dm_aioaiagent import DMAIAgent, OpenAIImageMessageContent


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 = OpenAIImageMessageContent(image_url="https://your.domain/image",
                                            text="Hello, what is shown in the photo?")

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

    # call an agent
    new_messages = ai_agent.run_messages(messages)
    answer = new_messages[-1].content


if __name__ == "__main__":
    main()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dm_aioaiagent-0.5.1.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dm_aioaiagent-0.5.1-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file dm_aioaiagent-0.5.1.tar.gz.

File metadata

  • Download URL: dm_aioaiagent-0.5.1.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for dm_aioaiagent-0.5.1.tar.gz
Algorithm Hash digest
SHA256 5701b65c679eb72cdb464b0552d8d8986b3c97091b69496d542e27b9e99bfd21
MD5 f31139f86a8f0c3fa0e207d777ad585a
BLAKE2b-256 0e158a56fc0ba8cbb579ca19f481b6173d1f7f112b204ddd1d95b888205f815e

See more details on using hashes here.

File details

Details for the file dm_aioaiagent-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: dm_aioaiagent-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for dm_aioaiagent-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6eeedb67387334dd43379346d91b26f68c7759491ce671ef787df41098f36978
MD5 cc6c2e6479a8b804d6c54d46f9e1ad83
BLAKE2b-256 5778765fb4a3c66349f8d7aa166af9eab75cd3825b09dac36373876a3786e430

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page