LlamaIndex is a widely used framework for building LLM-powered applications that leverage your data, enabling the creation of agents and structured workflows.
1.1 Usage
Method 1: OpenAILike (Recommended)
from llama_index.llms.openai_like import OpenAILike
llm = OpenAILike(
model="your-model-name",
api_base="https://api.rygen.io/v1",
api_key="your-rygen-api-key",
is_chat_model=True
)
response = llm.complete("Hi! How are you doing today?")
print(response.text)Method 2: OpenAI Class
from llama_index.llms.openai import OpenAI
llm = OpenAI(
model="your-model-name",
api_base="https://api.rygen.io/v1",
api_key="your-rygen-api-key"
)Method 3: Global Default LLM
from llama_index import Settings
from llama_index.llms.openai_like import OpenAILike
Settings.llm = OpenAILike(
model="your-model-name",
api_base="https://api.rygen.io/v1",
api_key="your-rygen-api-key",
is_chat_model=True,
is_function_calling_model=True
)Method 4: RAG Pipeline
from llama_index import VectorStoreIndex, SimpleDirectoryReader
from llama_index.llms.openai_like import OpenAILike
documents = SimpleDirectoryReader("data").load_data()
llm = OpenAILike(
model="your-model-name",
api_base="https://api.rygen.io/v1",
api_key="your-rygen-api-key",
is_chat_model=True
)
index = VectorStoreIndex.from_documents(documents, llm=llm)
query_engine = index.as_query_engine()
response = query_engine.query("Summarize the main idea of the documents.")1.2 Troubleshooting
| Issue | Fix |
|---|---|
is_chat_model errors | Set to True for chat models or False for completion models |
| Function calling issues | Enable is_function_calling_model=True |

