Skip to main content

ASI-1 Mini Integration for LlamaIndex

This package contains the LlamaIndex integration with ASI-1 Mini, a powerful language model designed for various natural language processing tasks.

ASI-1 Mini is the world's first Web3-native Large Language Model (LLM) developed by Fetch.ai Inc., a founding member of the Artificial Superintelligence Alliance. Unlike general-purpose LLMs, ASI-1 Mini is specifically designed and optimized for supporting complex agentic workflows.

With ASI-1 Mini, you can leverage these powerful capabilities:

  • Advanced agentic reasoning with dynamic reasoning modes for complex tasks
  • High performance on par with leading LLMs but with significantly lower hardware costs
  • Specialized optimization for autonomous agent applications and multi-step tasks
  • Seamless Web3 integration for secure and autonomous AI interactions

Want to learn more about ASI? Visit the ASI website or Fetch.ai for more information!

Installation

pip install llama-index-llms-asi

Usage

Here's an example of how to use the ASI integration with LlamaIndex:

from llama_index.llms.asi import ASI

# Initialize the ASI LLM
llm = ASI(model="asi1-mini", api_key="your_api_key")

# Generate text
response = llm.complete("Tell me about artificial intelligence.")
print(response)

# Chat completion
from llama_index.core.llms import ChatMessage, MessageRole

messages = [
    ChatMessage(
        role=MessageRole.SYSTEM, content="You are a helpful AI assistant."
    ),
    ChatMessage(
        role=MessageRole.USER, content="Tell me about artificial intelligence."
    ),
]

response = llm.chat(messages)
print(response)

Streaming Support

The ASI integration has different streaming implementations for completion and chat:

  • Streaming Completion: ASI doesn't support streaming for completions (returns 404 error). Our implementation uses a fallback mechanism that returns the complete response as a single chunk.

  • Streaming Chat: ASI supports streaming for chat, but with a unique format that includes:

    • Many empty content chunks during the "thinking" phase
    • Custom fields like thought and init_thought that contain intermediate reasoning
    • Content that may appear in different locations within the response structure

Our enhanced implementation:

  • Checks multiple possible locations for content (choices array, delta object, etc.)
  • Filters out empty chunks to provide a clean streaming experience
  • Handles all ASI response formats consistently
  • Matches OpenAI's API patterns for seamless integration
# Streaming completion (falls back to regular completion)
for chunk in llm.stream_complete("Tell me about artificial intelligence."):
    print(chunk.text, end="", flush=True)

# Streaming chat (handles ASI's unique streaming format)
for chunk in llm.stream_chat(messages):
    if hasattr(chunk, "delta") and chunk.delta.strip():
        print(chunk.delta, end="", flush=True)

Async Support

The ASI integration also supports async operations:

# Async completion
response = await llm.acomplete("Tell me about artificial intelligence.")
print(response)

# Async chat
response = await llm.achat(messages)
print(response)

# Async streaming completion (falls back to regular completion)
async for chunk in await llm.astream_complete(
    "Tell me about artificial intelligence."
):
    print(chunk.text, end="", flush=True)

# Async streaming chat (handles ASI's unique streaming format)
# Note: This follows the same pattern as OpenAI's implementation
stream = await llm.astream_chat(messages)
async for chunk in stream:
    print(chunk.delta, end="", flush=True)

API Key

You need an API key to use ASI's API. You can provide it in two ways:

  1. Pass it directly to the ASI constructor: ASI(api_key="your_api_key")
  2. Set it as an environment variable: export ASI_API_KEY="your_api_key"

Models

Currently, this integration supports the following models:

  • asi1-mini: A powerful language model for various natural language processing tasks.

OpenAI Compatibility

ASI is designed to be a drop-in replacement for OpenAI in LlamaIndex applications. Developers can easily switch from OpenAI to ASI by simply changing the LLM initialization:

# From this (OpenAI)
from llama_index.llms.openai import OpenAI

llm = OpenAI(api_key=openai_api_key, model="gpt-3.5-turbo")

# To this (ASI)
from llama_index.llms.asi import ASI

llm = ASI(api_key=asi_api_key, model="asi1-mini")

The rest of your code remains unchanged, including:

  • Regular completions with llm.complete()
  • Chat with llm.chat()
  • Streaming chat with for chunk in llm.stream_chat()
  • Async streaming with stream = await llm.astream_chat() followed by async for chunk in stream
  • Multi-turn conversations

ASI works seamlessly with other LlamaIndex components, such as using OpenAI embeddings for vector search while using ASI as the LLM for generating responses.

Complete RAG Example

Here's a complete example showing how to use ASI as a drop-in replacement for OpenAI in a RAG application:

from llama_index.llms.asi import ASI
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.core.node_parser import SentenceSplitter

# Load documents
documents = SimpleDirectoryReader("./data").load_data()

# Create parser
parser = SentenceSplitter(chunk_size=1024)

# Create embeddings model (still using OpenAI for embeddings)
embedding_model = OpenAIEmbedding(model="text-embedding-3-small")

# Create ASI LLM (instead of OpenAI)
llm = ASI(model="asi1-mini", api_key="your_asi_api_key")

# Create index
nodes = parser.get_nodes_from_documents(documents)
index = VectorStoreIndex(nodes, embed_model=embedding_model)

# Create query engine with ASI as the LLM
query_engine = index.as_query_engine(llm=llm)

# Query with streaming
response = query_engine.query(
    "What information is in these documents?", streaming=True
)

# Process streaming response
for token in response.response_gen:
    print(token, end="", flush=True)

This example demonstrates how you can use ASI as the LLM while still using OpenAI for embeddings, showing the flexibility of the integration.

Development

To create a development environment, install poetry then run:

poetry install --with dev

Testing

To test the integration, first enter the poetry venv:

poetry shell

Then tests can be run with make

make test

Integration tests

Integration tests will be skipped unless an API key is provided. API keys can be obtained from the Fetch.ai team. Once created, store the API key in an environment variable and run tests

export ASI_API_KEY=<your key here>
make test

Linting and Formatting

Linting and code formatting can be executed with make.

make format
make lint

Download files

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

Source Distribution

llama_index_llms_asi-0.4.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

llama_index_llms_asi-0.4.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_llms_asi-0.4.0.tar.gz.

File metadata

  • Download URL: llama_index_llms_asi-0.4.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_llms_asi-0.4.0.tar.gz
Algorithm Hash digest
SHA256 9d4b80c36145af6a1bdf7fb09011105f3d1752d6f52540219926ec087f7e3275
MD5 00e176c9395fa9e25eb18a0bb8901db7
BLAKE2b-256 710b3a91cd4507e3d0eb8dc34e1443520d6777d03b15b6a92e7494a1c4f4cf75

See more details on using hashes here.

File details

Details for the file llama_index_llms_asi-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: llama_index_llms_asi-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for llama_index_llms_asi-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7aeace083fb2449d880b9a3f645224d3af0aec791dc4607ef71119c209f029f3
MD5 76c9048976aa8e375908b9e5cca58333
BLAKE2b-256 6a0b70b5b9f4d2b36ce2cc16e989e5be2cca754ad884d99c9b40a3b1bda7c663

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.1

2 files

This release

0.4.0 This release

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page