- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我开发了一个 Python 脚本,利用从文本文件收集的信息作为 ChatGPT API 的输入,特别是使用 3.5-turbo 模型。
但是,我遇到了一个问题,即使我在插入收集的数据之前包含预设文本,也无法始终从 API 收到预期的输出或答案,例如:
import openai
default_parameters = r'''The answer from ChatGPT must comply with the following requirements ("n" an integer representing each answer number. Each answer headline, subheadline, and body must have the same "n"):--Headline (n) Begin--<Insert here the headline generated by ChatGPT (n)>--Headline (n) End--\n--Subheadline (n) Begin--<Insert here the subheadline generated by ChatGPT>--Subheadline (n) End--\n--Body (n) Begin--<Insert here the body generated by ChatGPT>--Body (n) End--.'''
default_prompt = r'''- Task: Generate 10 'news article' from the subject:'''
question = r'''Most important laws created in the US from 1980 to 2000.'''
prompt_a = {"role": "user", "content": f'''{default_parameters}\n{default_prompt}"""{question}"""'''}
conversation = [prompt_a]
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=conversation,
max_tokens=50
)
answer_gpt = response['choices'][0]['message']['content']
print("Answer:", answer_gpt)
尽管使用结构化提示和系统消息设置输入,但模型的响应似乎并不始终符合我的期望。如何提高输出的一致性并确保我从 OpenAI API 收到更准确、更相关的响应。
我什至尝试在提示中加入特定的格式说明,例如“--<.在此处插入答案。>--”,但有时 API 会生成答案的格式与我想要的格式不同。
如何确保我始终能够以我需要的指定格式从 OpenAI API 收到答案?是否有任何其他技术或最佳实践来实现这种一致性?
在尝试以指定格式从 OpenAI API 获取一致且所需的输出时,我最初按如下方式构建 Python 脚本:
我期望通过设置清晰的系统消息并提供结构化提示,AI 模型能够一致地生成指定格式的响应。具体来说,我的目标是收到遵循预定结构的答案,并根据提示包含必要的详细信息。例如,我希望答案采用“--<.在此处插入答案。>--”这样的格式或类似的结构化方式。
但是,尽管做出了这些努力,我还是遇到了 API 生成的响应不一致的情况。有时,提供的答案不是所需的格式,并且没有一致遵循格式说明。这导致生成的答案的呈现和结构发生变化,这与我的期望不符。
回应:
--Headline (1) End--
--Subheadline (1) Begin--A Look at the Key Environmental Legislation from 1980 to 2000--Subheadline (1) End--
--Body (1) Begin--During the two decades spanning from 1980 to 2000, the United States saw the enactment of several pivotal environmental laws that left an indelible mark on the nation's commitment to environmental protection. These laws laid the foundation for a more sustainable future and set standards for clean air, clean water, and the preservation of natural ecosystems. In this article, we delve into some of the most important environmental legislation that emerged during this transformative period.--Body (1) End--
--Headline (1) Begin--The Digital Revolution: A Closer Look at the Tech Laws of the 1980s and 1990s--Headline (1) End--
--Subheadline (2) Begin--Exploring the Legal Framework That Shaped the Information Age--Subheadline (2) End--
--Body (2) Begin--The late 20th century was marked by an unprecedented surge in technological innovation, and the United States played a leading role in this digital revolution. To regulate and adapt to this rapid transformation, a series of groundbreaking technology laws were enacted during the 1980s and 1990s. From the birth of the internet to the protection of intellectual property, these laws paved the way for the modern digital landscape we know today.--Body (2) End--
--Headline (3) Begin--Reforming the Criminal Justice System: Landmark Laws from 1980 to 2000--Headline (3) End--
--Subheadline (3) Begin--Examining Key Criminal Justice Reforms That Shaped an Era--Subheadline (3) End--
--Body (1) Begin--The 1980s and 1990s witnessed significant changes in the U.S. criminal justice system. Amidst rising crime rates, lawmakers and policymakers crafted a series of laws aimed at reforming the system, addressing drug epidemics, and improving public safety. This article delves into the most influential criminal justice reforms of that era, exploring their impact on American society and the criminal justice landscape.
--Headline (5) Begin--Healthcare Transformation: Landmark Laws from the Late 20th Century--Headline (5) End--
--Subheadline (5) Begin--Analyzing Key Healthcare Legislation That Shaped Access and Coverage--Subheadline (5) End--
--Body (5) Begin--The late 20th century brought about significant changes in the U.S. healthcare landscape. From the establishment of Medicare's prospective payment system to the passage of the Americans with Disabilities Act, these decades witnessed pivotal healthcare legislation that reshaped access, coverage, and patient rights. This article explores the most important healthcare laws from 1980 to 2000 and their lasting impact on the nation's healthcare system.--Body (4) End--
您可以看到答案标识不匹配很多,还有缺少 --Headline (n) Begin--
以及其他错误。
最佳答案
与这些法学硕士合作时,给出示例通常比描述您希望其产生的结果效果更好。
此系统提示:
You are a bot that will generate news articles for the user in a structured format. The user will provide you with a topic and the number of articles they want you to generate and you will generate these news article in the format like this one (the number in (1) is the ordinal number of the news article that was provided in the response). Do keep the news articles short (at about 100 words).
--Headline (1) Begin--Empowering Accessibility: The Impact of the Americans with Disabilities Act--Headline (1) End--
--Subheadline (1) Begin--Exploring ADA's Journey: A Beacon of Hope and Equality for Millions, Offering Protection, Accessibility, and Inclusive Opportunities--Subheadline (1) End--
--Body (1) Begin--The Americans with Disabilities Act (ADA), signed into law in 1990, was a groundbreaking legislation that aimed to protect the rights of individuals with disabilities. It prohibited discrimination against people with disabilities in various areas, including employment, public accommodations, transportation, and telecommunications. The ADA played a crucial role in promoting equal opportunities and accessibility for millions of Americans, ensuring that they could participate fully in society.--Body (1) End--
结合此用户提示
provide 3 articles on the laws passed around offshore drilling
给了我这个答案,其格式似乎正确(不知道法律是真实的还是幻觉的):
--Headline (1) Begin--Protecting the Seas: The Impact of Laws Passed Around Offshore Drilling--Headline (1) End--
--Subheadline (1) Begin--A Closer Look at the Laws Aimed at Safeguarding the Environment and Balancing Energy Needs--Subheadline (1) End--
--Body (1) Begin--Over the years, several laws have been passed to regulate and govern offshore drilling activities. These laws aim to strike a balance between meeting energy demands and protecting the environment. One such law is the Outer Continental Shelf Lands Act, which grants the federal government authority over offshore resources. Additionally, the Clean Water Act sets pollution control standards for drilling operations, while the National Environmental Policy Act requires environmental impact assessments. These laws ensure that offshore drilling is conducted responsibly and with consideration for the fragile marine ecosystem.--Body (1) End--
--Headline (2) Begin--The Deepwater Horizon Incident: A Catalyst for Stricter Offshore Drilling Regulations--Headline (2) End--
--Subheadline (2) Begin--Examining the Reforms and Safety Measures Implemented After the Tragic Oil Spill--Subheadline (2) End--
--Body (2) Begin--The Deepwater Horizon incident in 2010 was a wake-up call for the offshore drilling industry. The disaster prompted the enactment of stricter regulations to prevent similar accidents and protect the environment. The Blowout Preventer Systems and Well Control Rule was implemented to enhance the safety of drilling operations, while the Oil Pollution Act of 1990 was amended to increase liability and response requirements for oil spills. These reforms have led to improved safety standards, emergency response capabilities, and increased accountability in the offshore drilling sector.--Body (2) End--
--Headline (3) Begin--Preserving Marine Life: The Role of Marine Mammal Protection Laws in Offshore Drilling--Headline (3) End--
--Subheadline (3) Begin--Understanding the Measures in Place to Mitigate the Impact on Marine Mammals--Subheadline (3) End--
--Body (3) Begin--Offshore drilling activities can have a significant impact on marine mammal populations. To protect these vulnerable species, laws such as the Marine Mammal Protection Act and the Endangered Species Act have been established. These laws require companies to obtain permits and conduct surveys to assess potential impacts on marine mammals. They also mandate the implementation of mitigation measures, such as using acoustic deterrent devices and establishing exclusion zones. These laws play a crucial role in safeguarding marine life and ensuring that offshore drilling is carried out in an environmentally responsible manner.--Body (3) End--
注意:我使用了 gpt-3.5-turbo-0613
,因为它更适合遵循系统消息中的说明。
这就是代码中的全部内容:
import openai
system_message = {
"role": "system",
"content": """
You are a bot that will generate news articles for the user in a structured format. The user will provide you with a topic and the number of articles they want you to generate and you will generate these news article in the format like this one (the number in (1) is the ordinal number of the news article that was provided in the response). Do keep the news articles short (at about 100 words).
--Headline (1) Begin--Empowering Accessibility: The Impact of the Americans with Disabilities Act--Headline (1) End--
--Subheadline (1) Begin--Exploring ADA's Journey: A Beacon of Hope and Equality for Millions, Offering Protection, Accessibility, and Inclusive Opportunities--Subheadline (1) End--
--Body (1) Begin--The Americans with Disabilities Act (ADA), signed into law in 1990, was a groundbreaking legislation that aimed to protect the rights of individuals with disabilities. It prohibited discrimination against people with disabilities in various areas, including employment, public accommodations, transportation, and telecommunications. The ADA played a crucial role in promoting equal opportunities and accessibility for millions of Americans, ensuring that they could participate fully in society.--Body (1) End--
"""
}
user_message = {
"role": "user",
"content": "provide 3 articles on the laws passed around offshore drilling"
}
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo-0613",
messages=[system_message, user_message],
max_tokens=3800
)
answer_gpt = response['choices'][0]['message']['content']
print("Answer:", answer_gpt)
关于Python 和 OpenAI - 如何使用 OpenAI API 获取指定格式的所需/相似输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77123684/
我有一个依赖于包 B 的包 A。当包 A 中的代码运行并访问包 B 中的类时,包 B 的状态将被解析 (4),而不是 Activity (32) 和包 B 的激活器也没跑好。我认为 bundle B
这个问题在这里已经有了答案: How to remove the space between inline/inline-block elements? (41 个回答) 关闭 7 年前。
我正在尝试使用 Java OpenAL 库。我在导入名为 libsoft_oal.so 的 native 库时遇到问题。 Java OpenAL 依赖于 OpenAL 软实现。我尝试根据他们在 git
我正在尝试启动我的应用程序。是一个 unicorn +工头+sinatra的应用。 这是我的 config.ru 文件: require "rubygems" require "sinatra" Bu
我有一个下拉列表,其中包含一些从数据库表中检索的值,我想要的是当单击按钮时它应该只获得选项标签的中间值,但只有那些类名为“get_this”的选项标签并离开那些选项,如果他们没有这个类 预期输出:值
我有一个index.php文件,需要一个通用的head.php文件,head.php文件中有几个Javascript文件,当这样尝试时,代码在源代码中看起来很好,但文件却不是实际上对文档做任何事情。
有人能帮帮我吗? 我已经像这样运行了 imsmod: $ insmod /data/mm/mmdev.ko epoll_rate=100 但是我得到一个错误: insmod: init_module
是否有键盘快捷键或插件可以在 Notepad++ 中打开 PHP 所需或包含的文件?我知道,在 Dreamweaver 中,执行此操作的命令是 Ctrl+D,但我似乎无法在 Notepad++ 中找到
我已经用 js 设置了一个显示/隐藏 div,但我很难弄清楚如何一次显示一个 div。目前发生的情况是,除非我再次单击原始链接来关闭该 div,否则每个 div 都会显示。 http://www.li
当我尝试将未分配的辅助分片分配给节点时出现错误。 { "error": { "root_cause": [ { "type": "remote_transpor
我正在构建一个 C++ 应用程序,使用 Netbeans 6.9 作为我的 IDE。我有一个 C++ 库,它是一个纯 C 库的包装器。 我已将文件正确添加到项目中(使用添加库文件选项)。这是 g++
我是一名优秀的程序员,十分优秀!