Langchain创始人新项目Auto-Prompt Builder一键优化Prompt


大模型Prompt的重要性越来越受到重视,有关prompt engineering相关的技术一箩筐,在前面的文章里《一文探秘LLM应用开发(21)-Prompt(编写技巧)》有提到过OpenAI 官方推荐的最佳编写方法,也有大家经过实践总结的编写技巧。然而,这些理论对于prompt编写实操来讲,还是有些太重,做不到及时和灵活应用。

有没有这样一款工具,能够把用户的prompt进行优化改写以便达到最佳效果呢?曾经,笔者推荐过jinaAI开发的一款产品PromptPefect,它就能达到这样的目的,但是它是一款完整的产品,覆盖了prompt编写到应用服务的全过程,但对于开发者来讲,不太利于集成。现介绍另一款新的工具供大家参考,它是langchain创始人Harrison Chase最新开发的一个能力纯粹的开源项目auto-openai-prompter,其核心思路是将OpenAI的Prompt优化原则提交给GPT,然后让GPT-4帮助你优化prompt,可谓是用魔法打败魔法。

项目地址:https://github.com/hwchase17/auto-openai-prompter

整个实现非常简洁巧妙,他这样的编程思路相较于这一项目本身来讲更值得学习,如何改变编程惯性,用好大模型,是AI 2.0时代程序员脱颖而出的关键。

这是其中一段源码:

Prompt engineering
This guide shares strategies and tactics for getting better results from large language models (sometimes referred to as GPT models) like GPT-4. The methods described here can sometimes be deployed in combination for greater effect. We encourage experimentation to find the methods that work best for you.

Some of the examples demonstrated here currently work only with our most capable model, gpt-4. In general, if you find that a model fails at a task and a more capable model is available, it's often worth trying again with the more capable model.

You can also explore example prompts which showcase what our models are capable of:

Prompt examples
Explore prompt examples to learn what GPT models can do
Six strategies for getting better results
Write clear instructions
These models can’t read your mind. If outputs are too long, ask for brief replies. If outputs are too simple, ask for expert-level writing. If you dislike the format, demonstrate the format you’d like to see. The less the model has to guess at what you want, the more likely you’ll get it.

Tactics:

Include details in your query to get more relevant answers
Ask the model to adopt a persona
Use delimiters to clearly indicate distinct parts of the input
Specify the steps required to complete a task
Provide examples
Specify the desired length of the output
Provide reference text
Language models can confidently invent fake answers, especially when asked about esoteric topics or for citations and URLs. In the same way that a sheet of notes can help a student do better on a test, providing reference text to these models can help in answering with fewer fabrications.
...
template = """Based on the following instrutions, help me write a good prompt TEMPLATE for the following task:

{task}

Notably, this prompt TEMPLATE expects that additional information will be provided by the end user of the prompt you are writing. For the piece(s) of information that they are expected to provide, please write the prompt in a format where they can be formatted into as if a Python f-string.

When you have enough information to create a good prompt, return the prompt in the following format:\n\n```prompt\n\n...\n\n```

Instructions for a good prompt:

{instructions}
"""

Harrison Chase还专门录制了视频,给大家介绍这款工具。可以‬在‬vx公众号‬查看‬。

笔者简单测试:

感兴趣的读者可以直接点此尝试:https://openai-prompting-helper-e924c62387f55170bc7836f9f-ffoprvkqsa-uc.a.run.app/auto-prompter/playground/

举报
评论 0