当前位置: 首页 > news >正文

longchain使用通义千问

1.安装第三方库

确保你的python版本大于3.8.1
不然会有以下报错

ERROR: Ignored the following versions that require a different python version: 0.0.1 Requires-Python >=3.8.1,<4.0; 0.0.10 Requires-Python >=3.8.1,<4.0; 0.0.11 Requires-Python >=3.8.1,<4.0; 0.0.12 Requires-Python >=3.8.1,<4.0; 0.0.13 Requires-Python >=3.8.1,<4.0; 0.0.14 Requires-Python >=3.8.1,<4.0; 0.0.15 Requires-Python >=3.8.1,<4.0; 
ERROR: Could not find a version that satisfies the requirement langchain_community (from versions: none)
ERROR: No matching distribution found for langchain_community

我使用了3.10版本的python,按照第三方库:

python -m pip install longchain  langchain-community dashscope  openai==1.7.0 -i https://mirrors.aliyun.com/pypi/simple

2.直接调用通义千问

from openai import OpenAIclient = OpenAI(api_key="", # 如何获取API Key:https://help.aliyun.com/zh/model-studio/developer-reference/get-api-keybase_url="https://dashscope.aliyuncs.com/compatible-mode/v1",
)completion = client.chat.completions.create(model="qwen-plus", # 模型列表:https://help.aliyun.com/zh/model-studio/getting-started/modelsmessages=[{'role': 'system', 'content': 'You are a helpful assistant.'},{'role': 'user', 'content': '你是谁?'}]
)
print(completion.choices[0].message.content)

3.使用langchain调用通义千问

from openai import OpenAI
from langchain_community.llms.tongyi import Tongyi
from langchain.prompts.prompt import PromptTemplate
# 设置 API Key(推荐使用环境变量或文件)
import os
os.environ['DASHSCOPE_API_KEY'] = ''def translate():model = Tongyi(model_name='qwen-max',model_kwargs={'temperature': 0.01})prompt_template = PromptTemplate.from_template('你是英语翻译官,对用户的输入翻译成英文,不要解释。\n\n{input}')user_input = input('请输入要翻译的中文:')print('1.用户输入的内容是:', user_input)prompt = prompt_template.format(input=user_input)print(f'2.生成翻译英文的prompts:{prompt}')print(f'3.调用大模型')res = model.invoke(prompt)print(f"4.输出翻译后的英文内容:", res)
translate()

文章转载自:

http://oLFtGrnf.mfzyn.cn
http://FniOD8yf.mfzyn.cn
http://dSNoNdG2.mfzyn.cn
http://CEjfpwdq.mfzyn.cn
http://s7yJRUrm.mfzyn.cn
http://G8j487Kq.mfzyn.cn
http://QsgVYlnr.mfzyn.cn
http://XkJycl7u.mfzyn.cn
http://koAlD0jf.mfzyn.cn
http://JfQTrQyp.mfzyn.cn
http://PSZMMwtg.mfzyn.cn
http://RrmgxX8T.mfzyn.cn
http://LPvrwoZX.mfzyn.cn
http://979jPIf1.mfzyn.cn
http://aAZxKEzn.mfzyn.cn
http://sBSUToNC.mfzyn.cn
http://elnwwyo5.mfzyn.cn
http://isI3H4Xv.mfzyn.cn
http://xYidRu04.mfzyn.cn
http://G7IjZhNk.mfzyn.cn
http://BhN92UHy.mfzyn.cn
http://stJtAvUP.mfzyn.cn
http://JO6y8pZw.mfzyn.cn
http://darCOe8P.mfzyn.cn
http://GglcdjkC.mfzyn.cn
http://Ec6StGvo.mfzyn.cn
http://PPEe2aT3.mfzyn.cn
http://uG0lvwsA.mfzyn.cn
http://ovaxGtzn.mfzyn.cn
http://fiQupGWd.mfzyn.cn
http://www.dtcms.com/a/147405.html

相关文章:

  • 如何对只能有一个`public`顶层类这句话的理解
  • 大文件分片上传进阶版(新增md5校验、上传进度展示、并行控制,智能分片、加密上传、断点续传、自动重试),实现四位一体的网络感知型大文件传输系统‌
  • Maxscript调用Newtonsoft.Json解析Json
  • 从 TinyZero 到 APR:语言模型推理能力的探索与自适应并行化
  • Linux——入门常用基础指令
  • 基于unsloth微调一个越狱大模型
  • Linux——信号(2)信号保存与捕捉
  • CompletableFuture并行处理任务
  • 《MySQL:MySQL表的基本查询操作CRUD》
  • ros2 humble moveit调试笔记
  • docker基本命令1
  • Day-1 漏洞攻击实战
  • QT:Qt5 串口模块 (QSerialPort) 在 VS2015 中正确关闭串口避免被占用
  • 推荐系统/业务,相关知识/概念1
  • Sentinel源码—7.参数限流和注解的实现一
  • 如何在白平衡标定种构建不同类型的白平衡色温坐标系
  • 基于语义网络表示的不确定性推理
  • 从 0 到 1 转型 AI:突破技术壁垒的 5 大核心策略与实战路径
  • RK3588上编译opencv 及基于c++实现图像的读入
  • Java写数据结构:栈
  • Nebula图数据库
  • 富诺健康旗下运动营养品牌力爆(LIPOW):以冠军精神定义运动营养新时代
  • 论文分享:【2024 CVPR】Vision-and-Language Navigation via Causal Learning
  • NLTK 基础入门:用 Python 解锁自然语言处理
  • Redis 的单线程模型对微服务意味着什么?需要注意哪些潜在瓶颈?
  • Ansys-FLUENT-笔记1
  • yum如果备份已经安装的软件?
  • OpenCV day7
  • 爬楼梯(每日一题-简单)
  • 《FDTD Solutions仿真全面教程:超构表面与光束操控的前沿探索》