【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))

执行结果:

相关推荐
菠菠萝宝13 小时前
【Java手搓RAGFlow】-12- BaoRAGFlow最终项目展示
java·开发语言·人工智能·openai·embedding
AIBox3651 天前
国内可用 ChatGPT 中文版网站推荐(2025年11月最新)
人工智能·gpt·chatgpt
Ma0407131 天前
GPT:生成式预训练变形金刚
gpt
极客BIM工作室4 天前
从Transformer的Encoder与Decoder,到BERT和GPT的独立王国
gpt·bert·transformer
倔强的石头1068 天前
AiOnly大模型深度测评:调用GPT-5 API+RAG知识库,快速构建智能客服机器人
人工智能·gpt·机器人·aionly
boring_1118 天前
KubeFlow
gpt
智算菩萨8 天前
2025年通用大语言模型前沿进展评测:GPT-5.1、Claude 4.5、文心一言5.0 等全面解析
gpt·语言模型·文心一言
智慧地球(AI·Earth)9 天前
GPT-5.1发布!你的AI更暖更智能!
人工智能·gpt·神经网络·aigc·agi
盼小辉丶10 天前
PyTorch实战(10)——从零开始实现GPT模型
人工智能·pytorch·gpt·深度学习
Constantine3711 天前
GPT-5.1已上线!亲测国内可用,保姆级使用教程
gpt