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

企业备案增加网站/seo优化专员招聘

企业备案增加网站,seo优化专员招聘,苏宁易购网站建设的目的,健康陕西app管理端最新版1. 学习背景 在LangChain for LLM应用程序开发中课程中,学习了LangChain框架扩展应用程序开发中语言模型的用例和功能的基本技能,遂做整理为后面的应用做准备。视频地址:基于LangChain的大语言模型应用开发构建和评估高 2. 先准备尝试调用O…

1. 学习背景

在LangChain for LLM应用程序开发中课程中,学习了LangChain框架扩展应用程序开发中语言模型的用例和功能的基本技能,遂做整理为后面的应用做准备。视频地址:基于LangChain的大语言模型应用开发+构建和评估高

2. 先准备尝试调用OpenAI API

本实验基于jupyternotebook进行。

2.1先安装openai包、langchain包

!pip install openai
!pip install langchain

2.2 尝试调用openai包

import openai# 此处需要提前准备好可使用的openai KEY
openai.api_key = "XXXX"
openai.base_url = "XXXX"def get_completion(prompt, model = "gpt-3.5-turbo"):messages = [{"role": "user", "content": prompt}]response = openai.chat.completions.create(model = model,messages = messages,temperature = 0,)return response.choices[0].message.content
get_completion("What is 1+1?")

输出结果:

'1 + 1 equals 2.'

3.尝试用API解决邮件对话问题

3.1 邮件内容和风格

customer_email = """
Arrr, I be fuming that me blender lid \
flew off and splattered me kitchen walls \
with smoothie! And to make matters worse,\
the warranty don't cover the cost of \
cleaning up me kitchen. I need yer help \
right now, matey!
"""style = """American English \
in a calm and respectful tone
"""

3.2 构造成prompt

prompt = f"""Translate the text \
that is delimited by triple backticks \
into a style that is {style}. 
text: ```{customer_email}```
"""
prompt

输出如下:

"Translate the text that is delimited by triple backticks into a style that is American English in a calm and respectful tone\n. \ntext: ```\nArrr, I be fuming that me blender lid flew off and splattered me kitchen walls with smoothie! And to make matters worse,the warranty don't cover the cost of cleaning up me kitchen. I need yer help right now, matey!\n```\n"

3.3 使用上述prompt得到答案

response = get_completion(prompt)
response

输出如下:

'I must express my frustration that my blender lid unexpectedly came off and caused my kitchen walls to be covered in smoothie splatters! And unfortunately, the warranty does not cover the cleaning costs of my kitchen. I kindly request your immediate assistance, my friend.'

4. 尝试用langchain解决

4.1 用langchain调用API

from langchain.chat_models import ChatOpenAI
chat = ChatOpenAI(api_key = "XXXX",base_url = "XXXX",temperature=0.0)
print(chat)

输出如下:

ChatOpenAI(client=<openai.resources.chat.completions.Completions object at 0x7f362ab4f340>, 
async_client=<openai.resources.chat.completions.AsyncCompletions object at 0x7f362aba9d80>, 
temperature=0.0, openai_api_key='sk-gGSeHiJn09Ydl6Q1655eCf128b3a42XXXXXXXXXXXXXX', 
openai_api_base='XXXX', openai_proxy='')

4.2 构造prompt模板

注意和3.2的区别,一个用了f"“”“”“,一个直接”“”“”"。

template_string = """Translate the text \
that is delimited by triple backticks \
into a style that is {style}. \
text: ```{text}```
"""customer_style = """American English in a calm and respectful tone"""customer_email = """
Arrr, I be fuming that me blender lid \
flew off and splattered me kitchen walls \
with smoothie! And to make matters worse, \
the warranty don't cover the cost of \
cleaning up me kitchen. I need yer help \
right now, matey!
"""

4.3 调用ChatPromptTemplate

from langchain.prompts import ChatPromptTemplate
# 将构造的prompt模板化
prompt_template = ChatPromptTemplate.from_template(template_string)
# 模板中的占位符填充的参数
customer_messages = prompt_template.format_messages(style = customer_style,text = customer_email
)
print(type(customer_messages))
print(customer_messages[0])

输出如下:

<class 'list'>
content="Translate the text that is delimited by triple backticks into a style that is American English in a calm and respectful tone\n. text: ```\nArrr, I be fuming that me blender lid flew off and splattered me kitchen walls with smoothie! And to make matters worse, the warranty don't cover the cost of cleaning up me kitchen. I need yer help right now, matey!\n```\n"

4.4 使用LLM解决问题

# Call the LLM to translate to the style of the customer message
customer_response = chat(customer_messages)
print(customer_response.content)

输出如下:

Oh man, I 'm really frustrated that my blender lid flew off and made a mess of my kitchen walls with smoothie! And on top of that, the warranty doesn't cover the cost of cleaning up my kitchen. I could really use your help right now, buddy!

5. 调用langchain对邮件回复

5.1定义回复的prompt

service_reply = """Hey there customer, \
the warranty does not cover \
cleaning expenses for your kitchen \
because it's your fault that \
you misused your blender \
by forgetting to put the lid on before \
starting the blender. \
Tough luck! See ya!
"""service_style_pirate = """\
a polite tone \
that speaks in English Pirate\
"""# 继续使用前面定义的prompt_template,占位符用参数填充
service_messages = prompt_template.format_messages(style = service_style_pirate,text = service_reply)print(service_messages[0].content)

输出如下:

Translate the text that is delimited by triple backticks into a style that is a polite tone that speaks in English Pirate. 
text: ```
Hey there customer, the warranty does not cover cleaning expenses for your kitchen because it's your fault that you misused your blender by forgetting to put the lid on before starting the blender. Tough luck! See ya!```

5.2 使用LLM解决问题

service_response = chat(service_messages)
print(service_response.content)

输出如下:

Ahoy there, me heartie! Unfortunately, the warranty be not coverin' the cost of cleanin' yer kitchen, as tis yer own fault for misusin' yer blender by forgettin' to put on the lid afore startin' the blendin'. Aye, 'tis a tough break indeed! Fare thee well, matey!

至此我们就完成了使用langchain去实现prompt的构造、转换和调用。

6. 用langchain转化回答为JSON格式

6.1 构造模板

# 顾客对产品的评论
customer_review = """\
This leaf blower is pretty amazing.  It has four settings:\
candle blower, gentle breeze, windy city, and tornado. \
It arrived in two days, just in time for my wife's \
anniversary present. \
I think my wife liked it so much she was speechless. \
So far I've been the only one using it, and I've been \
using it every other morning to clear the leaves on our lawn. \
It's slightly more expensive than the other leaf blowers \
out there, but I think it's worth it for the extra features.
"""# 顾客意见形成模板
review_template = """\
For the following text, extract the following information:gift: Was the item purchased as a gift for someone else? \
Answer True if yes, False if not or unknown.delivery_days: How many days did it take for the product \
to arrive? If this information is not found, output -1.price_value: Extract any sentences about the value or price,\
and output them as a comma separated Python list.Format the output as JSON with the following keys:
gift
delivery_days
price_valuetext: {text}
"""from langchain.prompts import ChatPromptTemplate
# 构造模板,占位符信息用prompt填充
prompt_template = ChatPromptTemplate.from_template(review_template)
messages = prompt_template.format_messages(text=customer_review)
# 调用LLM,输入为prompt
response = chat(messages)
print(response.content)

输出如下:

{"gift": true,"delivery_days": 2,"price_value": "It's slightly more expensive than the other leaf blowers out there, but I think it's worth it for the extra features."
}

6.2 构造合适的prompt

print(type(response.content))

输出如下:

str

可以看到输出内容是字符串类型的,为了方便处理数据,我们需要的是JSON格式,因此还需要进行转化。

from langchain.output_parsers import ResponseSchema
from langchain.output_parsers import StructuredOutputParsergift_schema = ResponseSchema(name="gift",  description="Was the item purchased as a gift for someone else? Answer True if yes, False if not or unknown.")
delivery_days_schema = ResponseSchema(name="delivery_days", description="How many days did it take for the product to arrive? If this information \is not found, output -1.")
price_value_schema = ResponseSchema(name="price_value", description="Extract any sentences about the value or price, and output them as a comma \separated Python list.")response_schemas = [gift_schema, delivery_days_schema,price_value_schema]
# 构造转换器
output_parser = StructuredOutputParser.from_response_schemas(response_schemas)
format_instructions = output_parser.get_format_instructions()
print(format_instructions)

输出如下:

The output should be a markdown code snippet formatted in the following schema, including the leading and trailing "```json" and "```":```json
{"gift": string  // Was the item purchased as a gift for someone else? Answer True if yes, False if not or unknown."delivery_days": string  // How many days did it take for the product to arrive? If this information                                       is not found, output -1."price_value": string  // Extract any sentences about the value or price, and output them as a comma                                     separated Python list.
}```

LLM会根据构造的prompt进行回答,生成最终的回答结果。接着构造完整的prompt:

review_template_2 = """\
For the following text, extract the following information:gift: Was the item purchased as a gift for someone else? \
Answer True if yes, False if not or unknown.delivery_days: How many days did it take for the product\
to arrive? If this information is not found, output -1.price_value: Extract any sentences about the value or price,\
and output them as a comma separated Python list.text: {text}{format_instructions}
"""prompt = ChatPromptTemplate.from_template(template=review_template_2)
messages = prompt.format_messages(text=customer_review, format_instructions=format_instructions)
print(messages[0].content)

输出如下:

For the following text, extract the following information:gift: Was the item purchased as a gift for someone else? Answer True if yes, False if not or unknown.delivery_days: How many days did it take for the productto arrive? If this information is not found, output -1.price_value: Extract any sentences about the value or price,and output them as a comma separated Python list.text: This leaf blower is pretty amazing.  It has four settings:candle blower, gentle breeze, windy city, and tornado. It arrived in two days, just in time for my wife's anniversary present. I think my wife liked it so much she was speechless. So far I've been the only one using it, and I've been using it every other morning to clear the leaves on our lawn. It's slightly more expensive than the other leaf blowers out there, but I think it's worth it for the extra features.The output should be a markdown code snippet formatted in the following schema, including the leading and trailing "```json" and "```":```json
{"gift": string  // Was the item purchased as a gift for someone else? Answer True if yes, False if not or unknown."delivery_days": string  // How many days did it take for the product to arrive? If this information                                       is not found, output -1."price_value": string  // Extract any sentences about the value or price, and output them as a comma                                     separated Python list.
}```

6.3 使用LLM解决问题

response = chat(messages)
print(response.content)

输出如下:

```json
{"gift": "True","delivery_days": "2","price_value": "It's slightly more expensive than the other leaf blowers out there, but I think it's worth it for the extra features."
}```

进行格式转换

output_dict = output_parser.parse(response.content)
print(output_dict)

输出如下:

{'gift': 'True', 'delivery_days': '2', 'price_value': "It's slightly more expensive than the other leaf blowers out there, but I think it's worth it for the extra features."}

接下来查看输出类型:

type(output_dict)

输出如下:

dict

接下来就可以愉快的使用输出数据了。

总的来说,langchain对于格式化输出和prompt构造拥有较好的效果,可以很好使用。

相关文章:

LangChain学习之prompt格式化与解析器使用

1. 学习背景 在LangChain for LLM应用程序开发中课程中&#xff0c;学习了LangChain框架扩展应用程序开发中语言模型的用例和功能的基本技能&#xff0c;遂做整理为后面的应用做准备。视频地址&#xff1a;基于LangChain的大语言模型应用开发构建和评估高 2. 先准备尝试调用O…...

基于EasyX的贪吃蛇小游戏 - C语言

游戏基本功能演示&#xff1a; 1.主菜单界面 2.自定难度界面 在这里可以自行设定游戏的难度&#xff0c;包括蛇的移动速度&#xff0c;初始节数&#xff0c;以及默认模式&#xff0c;参考线&#xff08;网格&#xff09;。这些设定的数据都会在右上角的游戏属性栏中实时显示。…...

使用Docker辅助图像识别程序开发:在Docker中显示GUI、访问GPU、USB相机以及网络

目录概览 引言安装和配置安装docker安装nvidia-docker在docker中显示GUI在Docker中访问usb相机在Docker镜像中开放端口开启更多的GPU功能支持创建本地镜像中心一些可选参数上传镜像回收空间清理所有的无用镜像清理指定的镜像GPU Docker with Anaconda第一种方式:构建DockerFile…...

Java中常见错误-泛型擦除及桥接方法问题及解决方案

Java中泛型擦除及桥接方法 泛型擦除无界擦除上界擦除下界擦除 桥接方法演示案例wrong1wrong2wrong3right 原理总结 泛型擦除 ​ 泛型擦除是Java泛型机制的一个特性&#xff0c;它意味着**在编译期间&#xff0c;所有的泛型信息都会被移除&#xff0c;而在运行时&#xff0c;所…...

Linux 程序守护脚本

引言 程序是由代码形成的&#xff0c;代码是由人写的。只要是人&#xff0c;都会有疏忽的时候&#xff0c;导致写出的程序有bug&#xff0c;当然最严重的bug就是程序闪退。 本文旨在提供一个程序守护脚本&#xff0c;当监测到程序闪退后&#xff0c;立马将程序再起启动&#…...

跨境电商|Facebook Marketplace怎么做?

2016 年&#xff0c;Facebook打造了同名平台 Facebook Marketplace。通过利用 Facebook 现有的庞大客户群&#xff0c;该平台取得了立竿见影的成功&#xff0c;每月访问量将超过 10 亿。对于个人卖家和小企业来说&#xff0c;Facebook Marketplace是一个不错的销货渠道&#xf…...

.gitignore 文件

一.什么是 .gitignore 文件 在任何当前工作的 Git 仓库中&#xff0c;每个文件都是这样的&#xff1a; 追踪的&#xff08;tracked&#xff09;- 这些是 Git 所知道的所有文件或目录。这些是新添加&#xff08;用 git add 添加&#xff09;和提交&#xff08;用 git commit 提…...

qt中实现多语言功能

qt中实现多语言功能 原理&#xff1a; 其本质就是生成ts文件&#xff0c;然后使用Linguist软件手工翻译&#xff0c;再生成qm文件&#xff0c;最后在主程序的开始加载不同的qm文件&#xff0c;实现多语言。 步骤&#xff1a; 修改程序文件 在pro文件中加入说明 TRANSLATI…...

数据结构与算法之 leetcode 513. 找树左下角的值 (BFS) 广度优先

513. 找树左下角的值 /*** Definition for a binary tree node.* function TreeNode(val, left, right) {* this.val (valundefined ? 0 : val)* this.left (leftundefined ? null : left)* this.right (rightundefined ? null : right)* }*/ /*** param {T…...

mysql中的函数

MySQL提供了丰富的内置函数&#xff0c;涵盖了字符串操作、数字计算、日期和时间处理、条件判断、聚合计算等多个方面。这些函数可以帮助开发者在查询和数据处理时更高效地完成任务。下面是对MySQL中常见的函数分类及其主要函数的介绍&#xff1a; 字符串函数 CONCAT()&#x…...

Shell正则表达式与文本处理器

一、grep 1. 正则表达式 是一种匹配字符串的方法&#xff0c;通过一些特殊符号&#xff0c;快速实现查找&#xff0c;删除&#xff0c;替换某特定字符串。 选项&#xff1a; -a 不要忽略二进制数据。 -A 显示该行之后的内容。 -b 显示该行之前的内容。 -c 计算符合范本样…...

双指针法 ( 三数之和 )

题目 &#xff1a;给你一个整数数组 nums &#xff0c;判断是否存在三元组 [nums[i], nums[j], nums[k]] 满足 i ! j、i ! k 且 j ! k &#xff0c;同时还满足 nums[i] nums[j] nums[k] 0 。请 你返回所有和为 0 且不重复的三元组。 注意&#xff1a;答案中不可以包含重复…...

感染恶意代码之后怎么办?

隔离设备 立即将感染设备与网络隔离&#xff0c;断开与互联网和其他设备的连接。这可以防止恶意代码进一步传播到其他设备&#xff0c;并减少对网络安全的威胁。 确认感染 确认设备是否真的感染了恶意代码。这可能需要使用安全软件进行全面扫描&#xff0c;以检测和识别任何已…...

【计算机网络】P3 计算机网络协议、接口、服务的概念、区别以及计算机网络提供的三种服务方式

目录 协议什么是协议协议是水平存活的协议的组成 接口服务服务是什么服务原语 协议与服务的区别计算机网络提供的服务的三种方式面向连接服务与无连接服务可靠服务与不可靠服务有应答服务与无应答服务 协议 什么是协议 协议&#xff0c;就是规则的集合。 在计算机网络中&…...

多角度剖析事务和事件的区别

事务和事件这两个概念在不同的领域有着不同的含义&#xff0c;尤其是在计算机科学、数据库管理和软件工程中。下面从多个角度来剖析事务和事件的区别&#xff1a; 计算机科学与数据库管理中的事务 事务(Transaction)&#xff1a; 定义&#xff1a;在数据库管理中&#xff0c…...

模糊小波神经网络(MATLAB 2018)

模糊系统是一种基于知识或规则的控制系统&#xff0c;从属于智能控制&#xff0c;通过简化系统的复杂性&#xff0c;利用控制法来描述系统变量之间的关系&#xff0c;采用语言式的模糊变量来描述系统&#xff0c;不必对被控对象建立完整的数学模型。相比较传统控制策略&#xf…...

HTML布局

标准流&#xff1a; 标准流就是元素在页面中的默认排列方式&#xff0c;也就是元素在页面中的默认位置。 1.1 块元素----独占一行----从上到下排列 1.2 行内元素----不独占一行----从左到右排列&#xff0c;遇到边界换行 1.3 行内块元素----不独占一行…...

数据结构:双链表

数据结构&#xff1a;双链表 题目描述参考代码 题目描述 输入样例 10 R 7 D 1 L 3 IL 2 10 D 3 IL 2 7 L 8 R 9 IL 4 7 IR 2 2输出样例 8 7 7 3 2 9参考代码 #include <iostream>using namespace std;const int N 100010;int m; int idx, e[N], l[N], r[N];void init…...

Python3 元组、列表、字典、集合小结

前言 本文主要对Python中的元组、列表、字典、集合进行小结&#xff0c;主要内容包括知识点回顾、异同点、使用场景。 文章目录 前言一、知识点回顾1、列表&#xff08;List&#xff09;2、 元组&#xff08;Tuple&#xff09;3、 字典&#xff08;Dictionary&#xff09;4.、…...

2024会声会影破解免费序列号,激活全新体验!

会声会影2024序列号注册码是一款专业的视频编辑软件&#xff0c;它以其强大的功能和易用性受到了广大用户的喜爱。在这篇文章中&#xff0c;我将详细介绍会声会影2024序列号注册码的功能和特色&#xff0c;帮助大家更好地了解这款产品。 会声会影全版本绿色安装包获取链接&…...

机器学习18个核心算法模型

1. 线性回归&#xff08;Linear Regression&#xff09; 用于建立自变量&#xff08;特征&#xff09;和因变量&#xff08;目标&#xff09;之间的线性关系。 核心公式&#xff1a; 简单线性回归的公式为&#xff1a; , 其中 是预测值&#xff0c; 是截距&#xff0c; 是斜…...

平滑值(pinghua)

平滑值 题目描述 一个数组的“平滑值”定义为&#xff1a;相邻两数差的绝对值的最大值。 具体的&#xff0c;数组a的平滑值定义为 f ( a ) m a x i 1 n − 1 ∣ a i 1 − a i ∣ f(a)max_{i1}^{n-1}|a_{i1}-a_i| f(a)maxi1n−1​∣ai1​−ai​∣ 现在小红拿到了一个数组…...

使用matplotlib绘制折线条形复合图

使用matplotlib绘制折线条形复合图 介绍效果代码 介绍 在数据可视化中&#xff0c;复合图形是一种非常有用的工具&#xff0c;可以同时显示多种数据类型的关系。在本篇博客中&#xff0c;我们将探讨如何使用 matplotlib 库来绘制包含折线图和条形图的复合图。 效果 代码 imp…...

云计算中网络虚拟化的核心组件——NFV、NFVO、VIM与VNF

NFV NFV&#xff08;Network Functions Virtualization&#xff0c;网络功能虚拟化&#xff09;&#xff0c;是一种将传统电信网络中的网络节点设备功能从专用硬件中解耦并转换为软件实体的技术。通过运用虚拟化技术&#xff0c;NFV允许网络功能如路由器、防火墙、负载均衡器、…...

# SpringBoot 如何让指定的Bean先加载

SpringBoot 如何让指定的Bean先加载 文章目录 SpringBoot 如何让指定的Bean先加载ApplicationContextInitializer使用启动入口出注册配置文件中配置spring.factories中配置 BeanDefinitionRegistryPostProcessor使用 使用DependsOn注解实现SmartInitializingSingleton接口使用P…...

家用洗地机哪个品牌好?洗地机怎么选?这几款全网好评如潮

如今&#xff0c;人们家里越来越多的智能清洁家电&#xff0c;小到吸尘器、电动拖把&#xff0c;大到扫地机器人、洗地机&#xff0c;作为一个用过所有这些清洁工具的家庭主妇&#xff0c;我觉得最好用的还是洗地机。它的清洁效果比扫地机器人更好&#xff0c;功能也比吸尘器更…...

iOS与前端:深入解析两者之间的区别与联系

iOS与前端&#xff1a;深入解析两者之间的区别与联系 在数字科技高速发展的今天&#xff0c;iOS与前端技术作为两大热门领域&#xff0c;各自在移动应用与网页开发中扮演着不可或缺的角色。然而&#xff0c;这两者之间究竟存在哪些差异与联系呢&#xff1f;本文将从四个方面、…...

SpringBoot 基于jedis实现Codis高可用访问

codis与redis的关系 codis与redis之间关系就是codis是基于多个redis实例做了一层路由层来进行数据的路由&#xff0c;每个redis实例承担一定的数据分片。 codis作为开源产品&#xff0c;可以很直观的展示出codis运维成本低&#xff0c;扩容平滑最核心的优势. 其中&#xff0…...

力扣108. 将有序数组转换为二叉搜索树

108. 将有序数组转换为二叉搜索树 - 力扣&#xff08;LeetCode&#xff09; 找割点&#xff0c;一步一步将原数组分开。妙极了&#xff01;&#xff01;&#xff01;&#xff01;&#xff01; /*** Definition for a binary tree node.* public class TreeNode {* int val;…...

人工智能机器学习系统技术要求

一 术语和定义 1.1机器学习系统 machinelearningsystem 能运行或用于开发机器学习模型、算法和相关应用的软件系统。 1.2机器学习框架 machinelearningframework 利用预先构建和优化好的组件集合定义模型,实现对机器学习算法封装、数据调用处理和计算资源使用的软件库。 1…...