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

做教学的视频网站有哪些问题龙岗龙城街道网站建设

做教学的视频网站有哪些问题,龙岗龙城街道网站建设,网站怎么做谷歌权重,网站手机客户端在线制作腾讯混元大模型集成LangChain 获取API密钥 登录控制台–访问管理–API密钥管理–新建密钥#xff0c;获取到SecretId和SecretKey。访问链接#xff1a;https://console.cloud.tencent.com/cam/capi python SDK方式调用大模型 可参考腾讯官方API import json…腾讯混元大模型集成LangChain 获取API密钥 登录控制台–访问管理–API密钥管理–新建密钥获取到SecretId和SecretKey。访问链接https://console.cloud.tencent.com/cam/capi python SDK方式调用大模型 可参考腾讯官方API import json import typesfrom tencentcloud.common import credential from tencentcloud.common.profile.client_profile import ClientProfile from tencentcloud.common.profile.http_profile import HttpProfile from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException from tencentcloud.hunyuan.v20230901 import hunyuan_client, modelstry:cred credential.Credential(SecretId, SecretKey)httpProfile HttpProfile()httpProfile.endpoint hunyuan.tencentcloudapi.comclientProfile ClientProfile()clientProfile.httpProfile httpProfileclient hunyuan_client.HunyuanClient(cred, , clientProfile)# 实例化一个请求对象,每个接口都会对应一个request对象req models.ChatCompletionsRequest()params {TopP: 1,Temperature: 1,Model: hunyuan-pro,Messages: [{Role: system,Content: 将英文单词转换为包括中文翻译、英文释义和一个例句的完整解释。请检查所有信息是否准确并在回答时保持简洁不需要任何其他反馈。},{Role: user,Content: nice}]}req.from_json_string(json.dumps(params))resp client.ChatCompletions(req)if isinstance(resp, types.GeneratorType): # 流式响应for event in resp:print(event)else: # 非流式响应print(resp)except TencentCloudSDKException as err:print(err) 注需要将上述SecretId和SecretKey替换成自己创建的API密钥。 集成LangChain import jsonfrom langchain.llms.base import LLM from typing import Any, List, Mapping, Optionalfrom pydantic import Field from tencentcloud.common import credential from tencentcloud.common.profile.client_profile import ClientProfile from tencentcloud.common.profile.http_profile import HttpProfile from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException from tencentcloud.hunyuan.v20230901 import hunyuan_client, modelsclass HunyuanAI(LLM):secret_id: str Field(..., descriptionTencent Cloud Secret ID)secret_key: str Field(..., descriptionTencent Cloud Secret Key)propertydef _llm_type(self) - str:return hunyuandef _call(self, prompt: str, stop: Optional[List[str]] None) - str:try:cred credential.Credential(self.secret_id, self.secret_key)httpProfile HttpProfile()httpProfile.endpoint hunyuan.tencentcloudapi.comclientProfile ClientProfile()clientProfile.httpProfile httpProfileclient hunyuan_client.HunyuanClient(cred, , clientProfile)req models.ChatCompletionsRequest()params {TopP: 1,Temperature: 1,Model: hunyuan-pro,Messages: [{Role: user,Content: prompt}]}req.from_json_string(json.dumps(params))resp client.ChatCompletions(req)return resp.Choices[0].Message.Contentexcept TencentCloudSDKException as err:raise ValueError(fError calling Hunyuan AI: {err})try:# 创建 HunyuanAI 实例llm HunyuanAI(secret_idSecretId, secret_keySecretKey)question input(请输入问题)# 运行链result llm.invoke(question)# 打印结果print(result)except Exception as err:print(fAn error occurred: {err}) 注需要将上述SecretId和SecretKey替换成自己创建的API密钥。 集成LangChain且自定义输入提示模板 import jsonfrom langchain.llms.base import LLM from langchain.prompts.chat import ChatPromptTemplate, HumanMessagePromptTemplate, SystemMessagePromptTemplate from langchain.schema import HumanMessage, SystemMessage from langchain.chains import LLMChain from typing import Any, List, Mapping, Optional, Dictfrom pydantic import Field from tencentcloud.common import credential from tencentcloud.common.profile.client_profile import ClientProfile from tencentcloud.common.profile.http_profile import HttpProfile from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException from tencentcloud.hunyuan.v20230901 import hunyuan_client, modelsclass HunyuanAI(LLM):secret_id: str Field(..., descriptionTencent Cloud Secret ID)secret_key: str Field(..., descriptionTencent Cloud Secret Key)propertydef _llm_type(self) - str:return hunyuandef _call(self, prompt: str, stop: Optional[List[str]] None) - str:# 将 prompt 解析为消息列表messages self._parse_prompt(prompt)try:cred credential.Credential(self.secret_id, self.secret_key)httpProfile HttpProfile()httpProfile.endpoint hunyuan.tencentcloudapi.comclientProfile ClientProfile()clientProfile.httpProfile httpProfileclient hunyuan_client.HunyuanClient(cred, , clientProfile)req models.ChatCompletionsRequest()params {TopP: 1,Temperature: 1,Model: hunyuan-pro,Messages: messages}req.from_json_string(json.dumps(params))resp client.ChatCompletions(req)return resp.Choices[0].Message.Contentexcept TencentCloudSDKException as err:raise ValueError(fError calling Hunyuan AI: {err})def _parse_prompt(self, prompt: str) - List[Dict[str, str]]:将 LangChain 格式的 prompt 解析为 Hunyuan API 所需的消息格式messages []for message in prompt.split(Human: ):if message.startswith(System: ):messages.append({Role: system, Content: message[8:]})elif message:messages.append({Role: user, Content: message})return messagestry:# 创建 HunyuanAI 实例llm HunyuanAI(secret_idSecretId, secret_keySecretKey)# 创建系统消息模板system_template 你是一个英语词典助手。你的任务是提供以下信息\n1. 单词的中文翻译\n2. 英文释义\n3. 一个例句\n请保持回答简洁明了。system_message_prompt SystemMessagePromptTemplate.from_template(system_template)# 创建人类消息模板human_template 请为英文单词 {word} 提供解释。如果这个词有多个常见含义请列出最常见的 2-3 个含义。human_message_prompt HumanMessagePromptTemplate.from_template(human_template)# 将系统消息和人类消息组合成聊天提示模板chat_prompt ChatPromptTemplate.from_messages([system_message_prompt, human_message_prompt])# 创建 LLMChainchain LLMChain(llmllm, promptchat_prompt)# 运行链word input(请输入要查询的英文单词: )result chain.invoke(input{word: word})# 打印结果print(result)except Exception as err:print(fAn error occurred: {err}) 注需要将上述SecretId和SecretKey替换成自己创建的API密钥。
http://www.dnsts.com.cn/news/181741.html

相关文章:

  • 医院网站建设价格html5 网站开发软件
  • 有价值 网站代理记账一般多少钱一个月
  • dede织梦建站教程单页面网站推广
  • 阿里云服务器做电影网站吗wordpress首页白板
  • 好大学网站设计新网建站教程
  • 小程序网站建设的公司会员卡管理系统excel
  • 企业网站的建立与维护论文wordpress关健词
  • 什么网站可以做TCGA病理分期大连开发区社保网站
  • 龙岗网站优化开原 铁岭网站建设
  • 外贸公司网站设计哪家好做网站的公司找客户
  • 河北住房和城乡建设厅网站官网wordpress+登录+api接口
  • 公司做网站推广需要多少钱团购小程序
  • 低价车网站建设html5开发wap网站
  • js建设网站外网cpanel伪静态wordpress
  • 宁波网站设计方案北京网站优化实战
  • .net 手机网站源码下载各大浏览器的网址
  • 网络服务商怎么咨询seo蒙牛伊利企业网站专业性诊断
  • 石家庄住房和城乡建设局网站销售公司怎么做网站
  • 白银市住房与建设局网站住房和城乡建设部网站三定
  • 建设什么网站好wordpress 批量爆破
  • asp是网站开发吗微信小程序营销推广
  • 招标建设网站北京小学大兴网站建设
  • 西安 医疗网站制作杭州职称评审系统网站
  • 创建网站平台要多少钱网站开发补全
  • 西安高端品牌网站重庆建设网站公司哪家好
  • 网站站群 硬盘扩容 申请报告特产网站设计
  • 瑞安网站建设市场营销经典案例
  • 网站导航固定专业建设目标
  • 直播网站app下载58网站怎么做品牌推广
  • 搜索引擎网站排名优化方案的搜索引擎优化