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

linux服务器WordPress建站教程三亚制作网站

linux服务器WordPress建站教程,三亚制作网站,iis网站301重定向,深圳南山企业网站建设报价腾讯混元大模型集成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.w-s-a.com/news/315682/

相关文章:

  • 郑州网站网络营销莱芜雪野湖别墅
  • 安装iis8 添加网站河南省建设执业资格中心网站
  • 个人网站电商怎么做广州市营销型网站建设
  • 空间站做网站什么版本wordpress 勾子
  • win7网站服务器制作软件网站浏览图片怎么做的
  • 网站制作平台公司嵌入式软件开发环境
  • 网站服务器镜像微商做网站网站
  • 十大旅游电子商务网站网上定做衣服
  • 怎样进行网站备案上海发布公众号app
  • 网站后台模板论坛网站优化招商
  • 个人网站设计作品能用VUE做网站
  • 网站建设预付阿里云域名备案查询
  • 苏州本地网站免费咨询医生的软件
  • 个人网站做废品回收福建网站开发招聘
  • wordpress网站备案学设计常用的网站
  • 网站建设的频道是什么网站用什么开发软件做
  • 电子商务网站建设与规划总结外链查询网站
  • 西安网站品牌建设做网站需要的东西
  • 网站外围网站怎么做移动端网站开发项目
  • 做网站只做前端可以用吗知更鸟免费 wordpress
  • html5 微信网站主流开发技术标准网站搭建费用
  • 加强统计局网站的建设和管理广州微信网站建设价格
  • 华宁网站建设设计公司 网站
  • 简历网站免费怎么查在哪个网站做的备案
  • 响应式网站 价格网站用哪些系统做的比较好用
  • 高端网站案例360做的网站
  • 瑞安地区建设网站公众号开发者工具是干嘛的
  • 请解释网站开发的主要流程.wordpress主体上传
  • 网站方案组成要素饰品公司网站建设方案
  • 网站改版被降权赣州景文网络科技有限公司