Skip to content

LlamaIndex

LlamaIndex works against ai& through its OpenAILike LLM — same OpenAI wire protocol, custom base URL.

Terminal window
pip install llama-index llama-index-llms-openai-like
from 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)
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 HuggingFaceEmbedding
Settings.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?"))
from llama_index.core.agent.workflow import FunctionAgent
from 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?"))