【GPT入门】第66 课 llamaIndex调用远程llm模型与embedding模型的方法

【GPT入门】第66 课 llamaIndex调用远程llm模型与embedding模型的方法

  • [1. 调用私有模型的方法](#1. 调用私有模型的方法)
    • [1. OpenAILike](#1. OpenAILike)
    • [2. OpenAILikeEmbedding](#2. OpenAILikeEmbedding)
  • [2. 调用公开平台的模型](#2. 调用公开平台的模型)
    • [2.1 调用GLM](#2.1 调用GLM)

https://docs.llamaindex.org.cn/en/stable/api_reference/llms/openai_like/

1. 调用私有模型的方法

1. OpenAILike

OpenAILike 是对 OpenAI 模型的轻量级封装,使其兼容提供 OpenAI 兼容 API 的第三方工具。

官网:

https://docs.llamaindex.org.cn/en/stable/api_reference/llms/openai_like/

复制代码
pip install llama-index-llms-openai-like

from llama_index.llms.openai_like import OpenAILike

llm = OpenAILike(
    model="my model",
    api_base="https://hostname.com/v1",
    api_key="fake",
    context_window=128000,
    is_chat_model=True,
    is_function_calling_model=False,
)

response = llm.complete("Hello World!")
print(str(response))

2. OpenAILikeEmbedding

https://docs.llamaindex.org.cn/en/stable/api_reference/embeddings/openai_like/

复制代码
pip install llama-index-embeddings-openai-like

embedding = OpenAILikeEmbedding(
    model_name="my-model-name",
    api_base="https://:1234/v1",
    api_key="fake",
    embed_batch_size=10,
)

2. 调用公开平台的模型

2.1 调用GLM

参考官网:https://docs.bigmodel.cn/cn/guide/develop/http/introduction, 找到api_base,填入下面

复制代码
from llama_index.llms.openai_like import OpenAILike
llm = OpenAILike(
    model="glm-4",
    api_base="https://open.bigmodel.cn/api/paas/v4/",
    api_key="f45f06dfa35cf6c6110407aaae3b8ccf.Yl9o05aEpQqcC3yN",
    context_window=128000,
    is_chat_model=True,
    is_function_calling_model=False,
    max_tokens=1024,
    temperature=0.3,
)

response = llm.complete("我是星星之火,我不开心,开导我!")
print(str(response))

执行结果:

相关推荐
百***78751 天前
Gemini 3.0 Pro与2.5深度对比:技术升级与开发实战指南
开发语言·python·gpt
@我们的天空1 天前
【AI应用】学习和实践基于 LangChain/LangGraph 的链(Chain)构建、Agent 工具调用以及多轮对话流程的实现
人工智能·gpt·学习·语言模型·chatgpt·langchain·aigc
love3981467792 天前
Embedding,rerank,lora区别
embedding
星云POLOAPI2 天前
【2025实测】10大AI模型API中转/聚合平台横评:一键集成GPT/Claude/文心一言,拒绝重复造轮子
人工智能·gpt·文心一言
CodeCaptain2 天前
huggingface.co下载Qwen3-Embedding模型的步骤
经验分享·embedding·dify
liuc03173 天前
调用embedding生成向量并存储到milvus中,进行查询
embedding·milvus
百***24373 天前
Gemini 3.0 Pro 对决 GPT-5.2:编程场景深度横评与选型指南
gpt
薛定谔的猫19824 天前
Langchain(四)文本嵌入模型(Embedding Model)
langchain·embedding
return19994 天前
gpt进行修改润色 不要和原来的一样
gpt·深度学习
百***07454 天前
Claude Opus 4.5 场景化实战指南:全链路赋能开发,提升效率翻倍
人工智能·gpt·开源