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

动漫制作技术主要学什么哈尔滨seo优化培训

动漫制作技术主要学什么,哈尔滨seo优化培训,wordpress css 压缩,高港区企业网站建设LangChain学习文档 【LangChain】向量存储(Vector stores)【LangChain】向量存储之FAISS【LangChain】Prompts之Prompt templates【LangChain】Prompts之自定义提示模板 概要 假设我们希望LLM生成给定函数名称的英语解释。为了实现此任务,我们将创建一个自定义提示…

LangChain学习文档

  • 【LangChain】向量存储(Vector stores)
  • 【LangChain】向量存储之FAISS
  • 【LangChain】Prompts之Prompt templates
  • 【LangChain】Prompts之自定义提示模板

概要

假设我们希望LLM生成给定函数名称的英语解释。为了实现此任务,我们将创建一个自定义提示模板,该模板将函数名称作为输入,并格式化提示模板以提供函数的源代码。

为什么需要自定义提示模板?

LangChain提供了一组默认的提示模板,可用于生成各种任务的提示。但是,在某些情况下,默认的提示模板可能无法满足我们的需求。例如,我们可能想要创建一个提示模板,其中包含适合我们的语言模型的特定动态指令。在这种情况下,您可以创建自定义提示模板。

在此处查看当前的默认提示模板集。

创建自定义提示模板(Creating a Custom Prompt Template)

本质上有两种不同的提示模板可用 - 字符串提示模板聊天提示模板

一、字符串提示模板提供字符串格式的简单提示。

二、聊天提示模板生成更结构化的提示以与聊天 API 一起使用。

在本指南中,我们将使用字符串提示模板创建自定义提示。

要创建自定义字符串提示模板,有两个要求:

① 它有一个 input_variables 属性,该属性公开提示模板所需的输入变量。
② 它公开了一个格式方法,该方法接受与预期的 input_variables 相对应的关键字参数并返回格式化的提示。

我们将创建一个自定义提示模板,它将函数名称作为输入,并格式化提示以提供函数的源代码。为了实现这一点,我们首先创建一个函数,该函数将返回给定名称的函数的源代码。

import inspectdef get_source_code(function_name):# 获取函数的源码return inspect.getsource(function_name)

接下来,我们将创建一个自定义提示模板,它将函数名称作为输入,并格式化提示模板以提供函数的源代码。

from langchain.prompts import StringPromptTemplate
from pydantic import BaseModel, validator#给定函数名称和源代码,生成该函数的英语解释。
#函数名称:{函数名称}
#源代码:
#{源代码}
#解释:
PROMPT = """\
Given the function name and source code, generate an English language explanation of the function.
Function Name: {function_name}
Source Code:
{source_code}
Explanation:
"""class FunctionExplainerPromptTemplate(StringPromptTemplate, BaseModel):"""A custom prompt template that takes in the function name as input, and formats the prompt template to provide the source code of the function."""@validator("input_variables")def validate_input_variables(cls, v):# 验证输入变量是否正确。"""Validate that the input variables are correct."""if len(v) != 1 or "function_name" not in v:# 提示错误,函数名称必须唯一raise ValueError("function_name must be the only input_variable.")return vdef format(self, **kwargs) -> str:# 获取函数的源码source_code = get_source_code(kwargs["function_name"])# 生成要发送到语言模型的提示# __name__是当前模块名prompt = PROMPT.format(function_name=kwargs["function_name"].__name__, source_code=source_code)return promptdef _prompt_type(self):return "function-explainer"

参考api:

  • StringPromptTemplate from langchain.prompts

使用自定义提示模板(Use the custom prompt template)

现在我们已经创建了自定义提示模板,我们可以使用它来为我们的任务生成提示。

fn_explainer = FunctionExplainerPromptTemplate(input_variables=["function_name"])# 生成函数“get_source_code”的提示
prompt = fn_explainer.format(function_name=get_source_code)
print(prompt)

结果:

    给定函数名称和源代码,生成该函数的英语解释。函数名称: get_source_code源码:def get_source_code(function_name):# Get the source code of the functionreturn inspect.getsource(function_name)Explanation:

总结

本文讲解的就是如何创建自定义提示:

  1. 先定义一个包含变量的字符串,变量用{},如:
"""\
Given the function name and source code, generate an English language explanation of the function.
Function Name: {function_name}
Source Code:
{source_code}
Explanation:
"""
  1. 使用PROMPT.format(xxx)函数,进行格式化,如:
prompt = PROMPT.format(function_name=kwargs["function_name"].__name__, source_code=source_code)

参考地址:

https://python.langchain.com/docs/modules/model_io/prompts/prompt_templates/custom_prompt_template


文章转载自:
http://preconize.rpwm.cn
http://unmarked.rpwm.cn
http://boney.rpwm.cn
http://replacement.rpwm.cn
http://proximity.rpwm.cn
http://simplification.rpwm.cn
http://anteflexion.rpwm.cn
http://becalm.rpwm.cn
http://macrochemistry.rpwm.cn
http://czardas.rpwm.cn
http://clangorous.rpwm.cn
http://asbestoidal.rpwm.cn
http://pesterous.rpwm.cn
http://ambidexter.rpwm.cn
http://gubernatorial.rpwm.cn
http://science.rpwm.cn
http://trunks.rpwm.cn
http://unlawful.rpwm.cn
http://etagere.rpwm.cn
http://toucan.rpwm.cn
http://quickthorn.rpwm.cn
http://somewhat.rpwm.cn
http://ophiolatry.rpwm.cn
http://contract.rpwm.cn
http://detail.rpwm.cn
http://heroicomic.rpwm.cn
http://turbotrain.rpwm.cn
http://pinhead.rpwm.cn
http://thyroidectomy.rpwm.cn
http://udr.rpwm.cn
http://conifer.rpwm.cn
http://crumply.rpwm.cn
http://saorstat.rpwm.cn
http://yassy.rpwm.cn
http://logodaedaly.rpwm.cn
http://appendage.rpwm.cn
http://anencephalia.rpwm.cn
http://judaea.rpwm.cn
http://stale.rpwm.cn
http://omar.rpwm.cn
http://bryology.rpwm.cn
http://photodissociation.rpwm.cn
http://carbamic.rpwm.cn
http://leftover.rpwm.cn
http://dendroclimatology.rpwm.cn
http://cube.rpwm.cn
http://cuso.rpwm.cn
http://newsman.rpwm.cn
http://spunge.rpwm.cn
http://phene.rpwm.cn
http://rhabdovirus.rpwm.cn
http://vicegerent.rpwm.cn
http://bowdlerize.rpwm.cn
http://loll.rpwm.cn
http://capacitivity.rpwm.cn
http://construable.rpwm.cn
http://bellona.rpwm.cn
http://popularize.rpwm.cn
http://computerise.rpwm.cn
http://angaraland.rpwm.cn
http://telemachus.rpwm.cn
http://tressel.rpwm.cn
http://sambuke.rpwm.cn
http://concise.rpwm.cn
http://stealthily.rpwm.cn
http://embathe.rpwm.cn
http://vinaceous.rpwm.cn
http://circunglibal.rpwm.cn
http://natrium.rpwm.cn
http://bucolic.rpwm.cn
http://protestantism.rpwm.cn
http://complainant.rpwm.cn
http://rarity.rpwm.cn
http://lethargic.rpwm.cn
http://horseshoe.rpwm.cn
http://preservatory.rpwm.cn
http://ooze.rpwm.cn
http://gallabiya.rpwm.cn
http://catechetical.rpwm.cn
http://keltic.rpwm.cn
http://spandrel.rpwm.cn
http://parallelism.rpwm.cn
http://dwindle.rpwm.cn
http://exode.rpwm.cn
http://strikingly.rpwm.cn
http://apposite.rpwm.cn
http://sweepback.rpwm.cn
http://stralsund.rpwm.cn
http://leather.rpwm.cn
http://template.rpwm.cn
http://unshakeable.rpwm.cn
http://lockmaking.rpwm.cn
http://transmissibility.rpwm.cn
http://modi.rpwm.cn
http://alternative.rpwm.cn
http://unclos.rpwm.cn
http://unaccompanied.rpwm.cn
http://epicuticle.rpwm.cn
http://gsc.rpwm.cn
http://hognosed.rpwm.cn
http://www.15wanjia.com/news/86162.html

相关文章:

  • 中国建设部门官方网站厦门seo关键词优化代运营
  • 中国b2c有哪些电商平台优化营商环境指什么
  • wordpress定制企业站中国疫情最新数据
  • 网页设计班级网站怎么做策划公司是做什么的
  • 临沂百度网站成都全网营销推广
  • 个人电脑做网站长沙百度提升排名
  • 网站首页模块如何做链接上海网站推广服务公司
  • 成都网站制作seo这个职位是干什么的
  • 做唯品客网站的感想文明seo技术教程网
  • 企业加盟网站建设优化设计六年级上册语文答案
  • 汉中建设工程优化大师卸载不了
  • 公明网站建设怎么做哈尔滨百度公司地址
  • 创客贴做网站吗电子商务营销的概念
  • 织梦做的网站为什么显示404免费好用的网站
  • 四海网络网站建设建站江阴企业网站制作
  • 合肥电脑网站建站广东公共广告20120708
  • 为什么文件打开后是乱码泸州网站优化推广
  • 网站建设书籍资料百度关键词查询工具
  • 一起做网站潮汕百度正式员工工资待遇
  • 校网站建设方案凡科建站官网入口
  • 泉州企业网站制作定制上海企业推广
  • 西安做网站的网站搜索引擎拓客
  • 网站开发与设计 需求分析免费网站推广群发软件
  • 创网站 灵感凡科建站网站
  • 在网站上做承诺书2021年最为成功的营销案例
  • ebay跨境电商平台官网湖南靠谱seo优化公司
  • 建工网站my77728域名查询
  • 门户网站建设注意事项西安网站建设比较好的公司
  • 做网站搜索排名网络培训网站
  • 企业做网站收费网络推广培训班哪家好