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

执行结果:

相关推荐
bestcxx16 小时前
0.3、AI Agent 知识库、召回、Recall、Embedding等 相关的概念
embedding·知识库·dify·rag·ai agent·recall·召回
zstar-_19 小时前
nano-GPT:最小可复现的GPT实操
gpt
Font Tian1 天前
GPT-oss + vLLM + LobalChat
人工智能·gpt·llm
小新学习屋1 天前
大模型-智能体-【篇四: Agent GPT 、AgentTuning、LangChain-Agent】
gpt·langchain·大模型·智能体
YFCodeDream1 天前
MLLM技术报告 核心创新一览
python·gpt·aigc
安替-AnTi3 天前
PandaWiki:AI 驱动的开源知识库系
人工智能·embedding·检索增强·知识库·rag·查询优化
海森大数据4 天前
AI破解数学界遗忘谜题:GPT-5重新发现尘封二十年的埃尔德什问题解法
人工智能·gpt
ghostwritten4 天前
深入理解嵌入模型(Embedding Model):AI 语义世界的基石
人工智能·embedding
七牛云行业应用4 天前
从API调用到智能体编排:GPT-5时代的AI开发新模式
大数据·人工智能·gpt·openai·agent开发
Paraverse_徐志斌5 天前
RAG架构(检索增强生成)与向量数据库
数据库·ai·llm·embedding·milvus·rag