Skip to main content

Declarative AI components

Project description

AINI

aini

Declarative AI components - make AI component initialization easy with auto-imports and prebuilt YAML configs.


๐Ÿš€ Quick Start: Discover, Inspect, Use

0. Install (with LangChain support)

pip install aini[lang]

1. Discover Available LangChain Configurations

List all available YAML config files for LangChain components:

In [1]: from aini import alist

In [2]: alist(key='lang')
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ Found 9 YAML file(s)                                                             โ”‚
โ”‚ โ””โ”€โ”€ aini / Site-Packages: C:/Python3/Lib/site-packages/aini/                     โ”‚
โ”‚     โ”œโ”€โ”€ lang/                                                                    โ”‚
โ”‚     โ”‚   โ”œโ”€โ”€ config.yml: config                                                   โ”‚
โ”‚     โ”‚   โ”œโ”€โ”€ graph.yml: state_graph                                               โ”‚
โ”‚     โ”‚   โ”œโ”€โ”€ llm.yml: ds, r1, sf-qwen, sf-qwen-14b, sf-qwen-30b, sf-qwen-32b      โ”‚
โ”‚     โ”‚   โ”œโ”€โ”€ memory.yml: instore, saver                                           โ”‚
โ”‚     โ”‚   โ”œโ”€โ”€ msg.yml: msg_state, sys, human, user, ai, invoke, prompt             โ”‚
โ”‚     โ”‚   โ”œโ”€โ”€ react.yml: agent                                                     โ”‚
โ”‚     โ”‚   โ”œโ”€โ”€ supervisor.yml: supervisor                                           โ”‚
โ”‚     โ”‚   โ””โ”€โ”€ tools.yml: tavily                                                    โ”‚
โ”‚     โ””โ”€โ”€ lang_book/                                                               โ”‚
โ”‚         โ””โ”€โ”€ idea_validator.yml: clarifier, researcher, competitor, report        โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

2. Inspect a Componentโ€™s Component

See the exact configuration for a component by passing akey:

In [3]: from aini import aini

In [4]: aini('lang/llm:ds', araw=True)
Out [4]:
{
  'class': 'langchain.llms.DeepSeek',
  'params': {'model': 'deepseek-chat'}
}

3. Instantiate and Use the Component

Initialize and use the component directly:

# Instantiate the DeepSeek LLM (make sure DEEPSEEK_API_KEY is set)
In [5]: ds = aini('lang/llm:ds')

# Use the model (example: send a message)
In [6]: ds.invoke('hi').pretty_print()
======================== Ai Message ========================
Hello! ๐Ÿ˜Š How can I assist you today?

๐Ÿง‘โ€๐Ÿ’ป Extended Usage

Visualize and Debug

In [7]: from aini import aview

In [8]: aview(ds.invoke('hi'))
<langchain_core.messages.ai.AIMessage>
{
  'content': 'Hello! ๐Ÿ˜Š How can I assist you today?',
  'response_metadata': {
    'token_usage': {'completion_tokens': 11, 'prompt_tokens': 4, 'total_tokens': 15, 'prompt_cache_miss_tokens': 4},
    'model_name': 'deepseek-chat',
    'system_fingerprint': 'fp_8802369eaa_prod0425fp8',
    'id': '2be77461-5d07-4f95-8976-c3a782e1799b',
    'finish_reason': 'stop'
  },
  'type': 'ai',
  'id': 'run--5cdbede5-9545-441e-a137-ebe25699bf36-0',
  'usage_metadata': {'input_tokens': 4, 'output_tokens': 11, 'total_tokens': 15}
}

List Methods

In [9]: from aini import ameth

In [10]: ameth(ds)
Out [10]:
['invoke', 'predict', 'stream', ...]

๐Ÿ› ๏ธ Advanced Features

Variable Substitution

Use environment variables, input variables, or defaults in your YAML:

llm:
  class: "langchain_deepseek.ChatDeepSeek"
  params:
    api_key: ${DEEPSEEK_API_KEY}
    model: ${model|'deepseek-chat'}
    temperature: ${temp|0.7}

Resolution priority:

  1. Input variables (kwargs to aini())
  2. Environment variables
  3. Defaults section in YAML
  4. Fallback after |

Additioal Parameters

You can pass additional parameters when initializing components (only for single component):

In [11]: ds = aini('lang/llm:ds', max_tokens=100)

Custom Initialization

Specify custom init methods:

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

๐Ÿ“š More Examples

LangChain / LangGraph

In [13]: import operator
In [14]: from functools import reduce
# Get a list of agents from LangGraph
In [15]: agents = aini('lang_book/idea_validator)
# Chain them together
In [16]: workflow = reduce(operator.or_, agents.value())
# Get report from the workflow
In [17]: ans = workflow.invoke({'messages': 'Consistency check for AI agents'})
In [18]: ans['messages'][-1].pretty_print()

Autogen

pip install aini[autogen]
In [17]: client = aini('autogen/client', model=aini('autogen/llm:ds'))
In [18]: agent = aini('autogen/assistant', name='deepseek', model_client=client)
In [19]: ans = await agent.run(task='What is your name')
In [20]: aview(ans)

Agno

pip install aini[agno]
In [21]: agent = aini('agno/agent', tools=[aini('agno/tools:google')])
In [22]: ans = agent.run('Compare MCP and A2A')
In [23]: aview(ans, exc_keys=['metrics'])

<<<<<<< HEAD
### [Mem0](https://mem0.ai/)

```bash
pip install aini[mem0]
In [24]: memory = aini('mem0/memory:mem0')

๐Ÿ“ Configuration File Format

YAML or JSON, with support for defaults, variable substitution, and nested components.

defaults:
  api_key: "default-key-value"
  temperature: 0.7

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

๐Ÿ”— Links


๐Ÿ“ฆ Installation

pip install aini

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.3.3.tar.gz (45.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.3.3-py3-none-any.whl (42.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aini-0.3.3.tar.gz
  • Upload date:
  • Size: 45.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.3.3.tar.gz
Algorithm Hash digest
SHA256 81715e717626eff49bae0446cd1daaf6697bf61b0f6b466802d5d41e92f58ddb
MD5 04c000f7dcd6b26c25b4c6db14dafc86
BLAKE2b-256 e106750d45f0243c2a0cfb1a5f5847c7d2682c9bf37a7171a46830c914bbd7f7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aini-0.3.3-py3-none-any.whl
  • Upload date:
  • Size: 42.7 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.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0ac061771281ab6ece82bea11cb1c45c9f8477fc2846cf068a965cdc6c73f128
MD5 1feedb073c398cbceecf9da87463d8e4
BLAKE2b-256 a1531120070a614ede74bf47e891e5290aa0e1ccd0de30a7731e1ad41e7b43cc

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