本文介绍如何基于LlamaIndex框架,调用百炼平台提供的大模型。
前提条件
- 您已开通百炼服务并获得API-KEY, 请参考获取与配置 API Key。
- 已导入 API-KEY,请参考配置API Key到环境变量。
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
本文介绍如何基于LlamaIndex框架,调用百炼平台提供的大模型。
pip install llama-index-core
pip install llama-index-llms-openai-like
import os
from llama_index.core import Settings
from llama_index.llms.openai_like import OpenAILike
# LlamaIndex默认使用的大模型被替换为百炼
Settings.llm = OpenAILike(
model="qwen-plus",
api_base="https://dashscope.aliyuncs.com/compatible-mode/v1",
api_key=os.getenv("DASHSCOPE_API_KEY"),
is_chat_model=True
)
import os
from llama_index.llms.openai_like import OpenAILike
# 所调用的模型
llm = OpenAILike(
model="qwen-plus",
api_base="https://dashscope.aliyuncs.com/compatible-mode/v1",
api_key=os.getenv("DASHSCOPE_API_KEY"),
is_chat_model=True
)
response = llm.complete("帮我推荐一下江浙沪5天的旅游攻略。")
print(response)
pip install llama-index-core
pip install llama-index-llms-dashscope
import os
from llama_index.core import Settings
from llama_index.llms.dashscope import DashScope
# LlamaIndex默认使用的大模型被替换为百炼
Settings.llm = DashScope(model_name="qwen-plus", api_key=os.getenv("DASHSCOPE_API_KEY"))
import os
from llama_index.llms.dashscope import DashScope
llm = DashScope(model_name="qwen-plus", api_key=os.getenv("DASHSCOPE_API_KEY"))
response = llm.complete("帮我推荐一下江浙沪5天的旅游攻略。")
print(response)