LlamaIndex
LlamaIndex works against ai& through its OpenAILike LLM — same OpenAI wire protocol, custom base URL.
pip install llama-index llama-index-llms-openai-likefrom llama_index.llms.openai_like import OpenAILike
llm = OpenAILike( model="openai/gpt-oss-120b", api_base="https://api.aiand.com/v1", api_key="sk-your-api-key", is_chat_model=True,)
print(llm.complete("Hello").text)Indexing + querying documents
Section titled “Indexing + querying documents”from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings
Settings.llm = llm# Bring your own embeddings — ai& doesn't expose an embeddings endpoint:from llama_index.embeddings.huggingface import HuggingFaceEmbeddingSettings.embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
docs = SimpleDirectoryReader("./data").load_data()index = VectorStoreIndex.from_documents(docs)query_engine = index.as_query_engine()
print(query_engine.query("What is this corpus about?"))With tools (function agent)
Section titled “With tools (function agent)”from llama_index.core.agent.workflow import FunctionAgentfrom llama_index.core.tools import FunctionTool
def get_weather(city: str) -> str: """Get current weather for a city.""" return f"Sunny in {city}, 22°C"
agent = FunctionAgent( tools=[FunctionTool.from_defaults(fn=get_weather)], llm=llm,)
print(await agent.run("What's the weather in Tokyo?"))