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

执行结果:

相关推荐
golang学习记4 小时前
Claude Code 平替:OpenAI发布 Codex CLI ,GPT-5 国内直接使用
gpt
z千鑫4 小时前
【OpenAI】性价比极高的轻量级多模态模型GPT-4.1-mini介绍 + API KEY的使用教程!
人工智能·gpt·ai·语言模型·chatgpt
闲看云起17 小时前
从 GPT 到 LLaMA:解密 LLM 的核心架构——Decoder-Only 模型
gpt·架构·llama
北京地铁1号线17 小时前
GPT(Generative Pre-trained Transformer)模型架构与损失函数介绍
gpt·深度学习·transformer
*星星之火*1 天前
【GPT入门】第65课 vllm指定其他卡运行的方法,解决单卡CUDA不足的问题
gpt
IT成长日记1 天前
【Linux基础】Linux系统管理:GPT分区实践详细操作指南
linux·运维·服务器·gpt·parted·磁盘分区·fdisk
XISHI_TIANLAN2 天前
【多模态学习】Q&A3:FFN的作用?Embedding生成方法的BERT和Word2Vec?非线性引入的作用?
学习·bert·embedding
API流转日记2 天前
Gemini-2.5-Flash-Image-Preview 与 GPT-4o 图像生成能力技术差异解析
人工智能·gpt·ai·chatgpt·ai作画·googlecloud
勇往直前plus2 天前
Milvus快速入门以及用 Java 操作 Milvus
java·spring boot·embedding·milvus