欢迎光临
我们一直在努力

langchain初识之deepseek调用方式

大模型的调用有同步和异步两种,同步有如下几种方式:

#构建方式之特定模型类
deepseek_llm = ChatDeepSeek(
model=\’deepseek-chat\’,
api_key=DEEPSEEEK_API_KEY #deepseek的API key
)

#另一种构建方式,更通用的一种方式
deepseek_llm_init: BaseChatModel = init_chat_model(
model=\”deepseek-chat\”,
model_provider=\”deepseek\”,
api_key=DEEPSEEEK_API_KEY,
base_url=\”https://api.deepseek.com\”
)

1、阻塞式调用,即invoke, 模型接受消息作为输入,并在生成完整响应后输出消息。

print(deepseek_llm.invoke(\”介绍下自己\”))

2、流式 stream,需要遍历返回结果

response = deepseek_llm.stream(\”who you are?\”)
for chunk in response:
print(chunk.content, end=\”|\”, flush=True)

3、批量调用,将多个请求批量发送给模型,以实现更高效的处理

#batch() 仅返回整个批次的最终输出
response1 = deepseek_llm.batch([
\”你是谁?\”,
\”你会什么\”,
\”你是锤子么?\”
])

for item in response1:
print(item.content, end=\”|\”, flush=True)

#多个问题处理时优先返回已有答案的结果,如果希望在

赞(0)
未经允许不得转载:171主机测评 » langchain初识之deepseek调用方式
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址