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

执行结果:

相关推荐
程序员Sunday3 小时前
说点不一样的。GPT-5.3 与 Claude Opus 4.6 同时炸场,前端变天了?
前端·gpt·状态模式
刘大大Leo1 天前
GPT-5.3-Codex 炸了:第一个「自己造自己」的 AI 编程模型,到底意味着什么?
人工智能·gpt
ASS-ASH2 天前
AI时代之向量数据库概览
数据库·人工智能·python·llm·embedding·向量数据库·vlm
acai_polo2 天前
如何在国内合规、稳定地使用GPT/Claude/Gemini API?中转服务全解析
人工智能·gpt·ai·语言模型·ai作画
迈火3 天前
SD - Latent - Interposer:解锁Stable Diffusion潜在空间的创意工具
人工智能·gpt·计算机视觉·stable diffusion·aigc·语音识别·midjourney
空中楼阁,梦幻泡影3 天前
主流4 大模型(GPT、LLaMA、DeepSeek、QWE)的训练与推理算力估算实例详细数据
人工智能·gpt·llama
晓晓不觉早4 天前
OpenAI Codex App的推出:多代理工作流的新时代
人工智能·gpt
kebijuelun4 天前
Towards Automated Kernel Generation in the Era of LLMs:LLM 时代的自动化 Kernel 生成全景图
人工智能·gpt·深度学习·语言模型
玄同7656 天前
LangChain v1.0+ Retrieval模块完全指南:从文档加载到RAG实战
人工智能·langchain·知识图谱·embedding·知识库·向量数据库·rag
Loo国昌6 天前
【垂类模型数据工程】第四阶段:高性能 Embedding 实战:从双编码器架构到 InfoNCE 损失函数详解
人工智能·后端·深度学习·自然语言处理·架构·transformer·embedding