LlamaIndex
LlamaIndex 是使用智能体和工作流在您的数据上构建 LLM 驱动智能体的领先框架。 官方网站:llamaindex.ai
1.1 使用方法
方式一:OpenAILike(推荐)
from llama_index.llms.openai_like import OpenAILike
llm = OpenAILike(
model="minimax/minimax-m2.5",
api_base="https://api.luchentech.com/inference/v1",
api_key="your-luchentech-key",
is_chat_model=True
)
response = llm.complete("Hello, how are you?")
print(response.text)
方式二:OpenAI 类
from llama_index.llms.openai import OpenAI
llm = OpenAI(
model="minimax/minimax-m2.5",
api_base="https://api.luchentech.com/inference/v1",
api_key="your-luchentech-key"
)
方式三:全局默认 LLM
from llama_index import Settings
from llama_index.llms.openai_like import OpenAILike
Settings.llm = OpenAILike(
model="minimax/minimax-m2.5",
api_base="https://api.luchentech.com/inference/v1",
api_key="your-luchentech-key",
is_chat_model=True,
is_function_calling_model=True
)
方式四:RAG 流水线
from llama_index import VectorStoreIndex, SimpleDirectoryReader
from llama_index.llms.openai_like import OpenAILike
documents = SimpleDirectoryReader("data").load_data()
llm = OpenAILike(
model="minimax/minimax-m2.5",
api_base="https://api.luchentech.com/inference/v1",
api_key="your-luchentech-key",
is_chat_model=True
)
index = VectorStoreIndex.from_documents(documents, llm=llm)
query_engine = index.as_query_engine()
response = query_engine.query("What is the document about?")
1.2 故障排除
| 常见问题 | 解决方案 |
|---|---|
| is_chat_model 错误 | 根据模型类型设置为 True(Chat)或 False(Completion) |
| 函数调用不工作 | 设置 is_function_calling_model=True |