Skip to main content

Make class instantiation easy with auto-imports

Project description

AINI

aini

Make AI class initialization easy with auto-imports.

Installation

pip install aini

Why aini?

  • Simplified Initialization: Configure complex AI components with clean YAML files
  • Variable Substitution: Use environment variables and defaults for sensitive values
  • Auto-Imports: No need for multiple import statements
  • Debugging Tools: Inspect objects with aview for better debugging
  • Reusable Configs: Share configurations across projects

Core Features

Main Components

  • aini(): Loads and instantiates objects from configuration files
  • aview(): Visualizes complex nested objects for debugging
  • afunc(): Lists available methods on an object

Usage

Autogen

Use DeepSeek as the model for the assistant agent.

from aini import aini, aview

# Load assistant agent with DeepSeek as its model - requires DEEPSEEK_API_KEY
client = aini('autogen/client', model=aini('autogen/llm', 'ds'))
agent = aini('autogen/assistant', name='deepseek', model_client=client)

# Run the agent
ans = await agent.run(task='What is your name')

# Display result structure
aview(ans)
[Output]
<autogen_agentchat.base._task.TaskResult>
{
  'messages': [
    {'source': 'user', 'content': 'What is your name', 'type': 'TextMessage'},
    {
      'source': 'deepseek',
      'models_usage <autogen_core.models._types.RequestUsage>': {
        'prompt_tokens': 32,
        'completion_tokens': 17
      },
      'content': 'My name is DeepSeek Chat! 😊 How can I assist you today?',
      'type': 'TextMessage'
    }
  ]
}

# Display agent structure with private keys included
aview(agent._model_context, inc_=True, max_depth=5)
[Output]
<autogen_core.model_context._unbounded_chat_completion_context.UnboundedChatCompletionContext>
{
  '_messages': [
    {'content': 'What is your name', 'source': 'user', 'type': 'UserMessage'},
    {
      'content': 'My name is DeepSeek Chat! 😊 How can I assist you today?',
      'source': 'deepseek',
      'type': 'AssistantMessage'
    }
  ]
}

Agno

# Load an agent with tools from configuration files
agent = aini('agno/agent', tools=[aini('agno/tools', 'google')])

# Run the agent
ans = agent.run('Compare MCP and A2A')

# Display component structure with filtering
aview(ans, exclude_keys=['metrics'])
[Output]
<agno.run.response.RunResponse>
{
  'content': "Here's a comparison between **MCP** and **A2A**: ...",
  'content_type': 'str',
  'event': 'RunResponse',
  'messages': [
    {
      'role': 'user',
      'content': 'Compare MCP and A2A',
      'add_to_agent_memory': True,
      'created_at': 1746758165
    },
    {
      'role': 'assistant',
      'tool_calls': [
        {
          'id': 'call_0_21871e19-3de7-4a8a-9275-9b4128fb743c',
          'function': {
            'arguments': '{"query":"MCP vs A2A comparison","max_results":5}',
            'name': 'google_search'
          },
          'type': 'function'
        }
      ]
    }
  ]
  ...
}

# Export to YAML for debugging
aview(ans, to_file='debug/output.yaml')

Mem0

memory = aini('mem0/mem0', 'mem0')

Configuration File Format

aini uses YAML or JSON configuration files to define class instantiation. Here's how they work:

Basic Structure

# Optional defaults section for fallback values
defaults:
  api_key: "default-key-value"
  temperature: 0.7

# Component definition
assistant:
  class: autogen_agentchat.agents.AssistantAgent
  params:
    name: ${name}
    model_client: ${model_client|client}
    tools: ${tools}

# Nested components
mem0:
  class: mem0.Memory
  init: from_config
  params:
    config_dict:
      history_db_path: ${history_db_path}
      graph_store:
        provider: neo4j
        config:
          url: bolt://localhost:7687
          username: ${NEO4J_USERNAME}
          password: ${NEO4J_PASSWORD}

Variable Substitution

aini supports variable substitution with the ${var} syntax:

model_config:
  class: "openai.OpenAI"
  params:
    api_key: ${OPENAI_API_KEY}  # Uses environment variable
    model: ${model|'gpt-4'}     # Uses input parameter or default 'gpt-4'
    temperature: ${temp|0.7}    # Uses input parameter or default 0.7

Variable resolution priority:

  1. Input variables (passed as kwargs to aini())
  2. Environment variables
  3. Default variables from the defaults section
  4. Fallback values after the pipe | character

Custom Initialization Methods

By default, aini uses the class constructor (__init__), but you can specify custom initialization methods:

nested_example:
model_client:
  class: autogen_core.models.ChatCompletionClient
  init: load_component
  params:
    model: ${model}
    expected: ${expected}

Advanced Features

Raw Configuration Access

Use the araw parameter to get the resolved configuration without building objects:

# Get raw configuration with variables resolved
config = aini('openai/model_config', araw=True)
print(config)

# Get specific component configuration
model_config = aini('openai/model_config', akey='gpt4', araw=True)
print(model_config)

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

aini-0.2.0.tar.gz (29.9 kB view details)

Uploaded Source

Built Distribution

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

aini-0.2.0-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

Details for the file aini-0.2.0.tar.gz.

File metadata

  • Download URL: aini-0.2.0.tar.gz
  • Upload date:
  • Size: 29.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for aini-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1959af9b120cb76fbfa4e8fc96d5f1c36c446e994e4142b148c302de156c9e84
MD5 0590f8f9ca13caf03e8e5200ea8c44a9
BLAKE2b-256 2566ecd59e801241b713bde61735fab0023e2b4853008b101c1343cd2a3b2fef

See more details on using hashes here.

File details

Details for the file aini-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: aini-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 27.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for aini-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8896a6bf1d067d64fc00ff660c5c67ab1de6f908995cc320bb16beda4d8c5d32
MD5 61b395d43bb2f4867caec5bbc9fcfd3a
BLAKE2b-256 a5e4c31a8c0fb402797ad1acffa3b7f949e10be3652b1625f1a67019db26f815

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