{"id":13651194,"url":"https://github.com/ConnectAI-E/Prompt-Engineering-Tutior","last_synced_at":"2025-04-22T22:30:36.085Z","repository":{"id":159110201,"uuid":"634430755","full_name":"ConnectAI-E/Prompt-Engineering-Tutior","owner":"ConnectAI-E","description":"🎡 Pompt 提示词工程师入门指南 ~视频字幕+代码资料 [( Python、Golang、NodeJs ) x ( 中文、英文 )]","archived":false,"fork":false,"pushed_at":"2023-06-13T10:49:30.000Z","size":385,"stargazers_count":94,"open_issues_count":0,"forks_count":10,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-20T01:33:05.501Z","etag":null,"topics":["chatgpt","connect-ai","go","golang","javascript","nodejs","openai","prompt","prompt-engineering","python"],"latest_commit_sha":null,"homepage":"https://www.connectai-e.com","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ConnectAI-E.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-04-30T05:00:56.000Z","updated_at":"2025-03-21T13:55:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"68ab99d6-7d6c-4411-83b8-d3476573ef1a","html_url":"https://github.com/ConnectAI-E/Prompt-Engineering-Tutior","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConnectAI-E%2FPrompt-Engineering-Tutior","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConnectAI-E%2FPrompt-Engineering-Tutior/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConnectAI-E%2FPrompt-Engineering-Tutior/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ConnectAI-E%2FPrompt-Engineering-Tutior/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ConnectAI-E","download_url":"https://codeload.github.com/ConnectAI-E/Prompt-Engineering-Tutior/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250333863,"owners_count":21413471,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chatgpt","connect-ai","go","golang","javascript","nodejs","openai","prompt","prompt-engineering","python"],"created_at":"2024-08-02T02:00:46.275Z","updated_at":"2025-04-22T22:30:36.066Z","avatar_url":"https://github.com/ConnectAI-E.png","language":"Jupyter Notebook","funding_links":[],"categories":["企联AI","Building"],"sub_categories":["Prompt Engineering"],"readme":"\n\u003cdiv align=\"center\"\u003e\n\t\u003ca href='https://learn.deeplearning.ai/chatgpt-prompt-eng/lesson/1/introduction' target=\"_blank\" rel=\"noopener noreferrer\"\u003e\n\t\u003cimg src=\"https://user-images.githubusercontent.com/50035229/235389663-fed583ca-7297-4385-88b9-3587baaed90b.png\" width=\"800\" \u003e\n\t\u003c/a\u003e\n\t\u003ch1\u003e🎡提示词工程师入门指南\u003c/h1\u003e\n\t\u003cp\u003e\n\t\t\u003cb\u003e👏🏻欢迎PR \u0026 Star，让更多人了解\u003cstrong\u003e 提示词工程师 \u003c/strong\u003e 👏🏻\u003c/b\u003e\n\t\u003c/p\u003e\n\t\u003cbr\u003e\n\t\u003cbr\u003e\n\t\u003cbr\u003e\n\u003c/div\u003e\n\n\n\n## 介绍\n\n🥐 参考视频课程：[ChatGPT Prompt Engineering for Developers](https://learn.deeplearning.ai/chatgpt-prompt-eng/lesson/1/introduction)\n\n🍔 中文字幕搬运：[提示词工程师入门指南【吴恩达】- 企联AI开源字幕组 - 欢迎PR翻译字幕](https://www.bilibili.com/video/BV1zz4y1i7QT)\n\n🥪 实现语言：Python、Golang、NodeJs\n\n🍗 语料语言：英文、中文\n\n## 代码资料\n\n\u003e 欢迎大家PR！\n\n| 资料     | 语料                                                                                                                                                 |\n|:-------|:---------------------------------------------------------------------------------------------------------------------------------------------------|\n| 教学视频   | \u003ca href=\"https://www.bilibili.com/video/BV1zz4y1i7QT\"\u003e中✅\u003c/a\u003e、\u003ca href=\"https://learn.deeplearning.ai/chatgpt-prompt-eng/lesson/2/guidelines\"\u003e英✅\u003c/a\u003e |\n| Python | \u003ca href=\"./python/cn/guidelines.ipynb\"\u003e中✅\u003c/a\u003e、\u003ca href=\"./python/en/guidelines.ipynb\"\u003e英✅\u003c/a\u003e                                                                                   |\n| NodeJS | \u003ca href=\"./nodejs/cn/readme.md\"\u003e中✅\u003c/a\u003e、\u003ca href=\"./nodejs/en/readme.md\"\u003e英✅\u003c/a\u003e                                                                                                             \n| Golang | \u003ca href=\"./golang/cn/guidelines.go\"\u003e中✅\u003c/a\u003e、\u003ca href=\"./golang/en/guidelines.go\"\u003e英✅\u003c/a\u003e                                                                                      |\n| 字幕     | \u003ca href=\"./srt/cn\"\u003e中✅\u003c/a\u003e、\u003ca href=\"./srt/en\"\u003e英✅\u003c/a\u003e      \n\n## 正文\n\n### Guidelines 总体准则\n\nLLM分成两个基本大类：Base-LLM和Instruction-Tuned-LLM。\n\n前者是基础语言模型，基于预训练数据预测下一个单词。后者则针对指令进行微调，使其更可能完成人类的指令。\n\nOpenAI的模型中，InstructGPT Models 列出了针对指令优化的模型。表格中也列出了不同的指令微调训练方法，如SFT、FeedME、PPO等。\n\n编写指令的准则包括：\n\n- 清晰和具体，但不一定要短。\n- 使用定界符如\"\"\"、```、---、\u003c\u003e、。以防止prompt注入，给LLM产生混乱的理解。\n- 使用结构化输出，如要求以HTML或JSON格式输出。\n- 要求检查：要求LLM先检查是否满足某个条件后再进行输出，如果条件不满足可以直接告知。\n- 利用少样本学习，展示一个期望的例子给LLM。\n- 给模型一些思考时间，不要给它过于简单或困难的问题。\n- 按步骤来解答，设定分隔符，例如使用\"Text:\u003c\u003e\"来表示文本。\n- 让模型自己推导出过程，而不仅仅是结果。展示一个带有解题过程的例子给LLM。\n- 避免模型产生幻觉：要告诉模型先查找相关资料，再根据相关资料来回答问题。（但模型产生幻觉很难避免，也是目前模型研究领域努力的方向）\n\n### Iterative Prompting 迭代提示词\n\n编写Prompt的过程是不断迭代的。\n\n基本步骤：\n- 编写Prompt\n- 进行测试，\n- 分析原因\n- 修订Prompt（澄清思路）\n- 循环上述步骤，直到达到满意的结果为止。\n\n### Summarizing 总结能力\n如果你经营一个电商网站，其中包含大量用户评论，你可以利用语言模型的\"总结（summarize）\"和\"提取信息（extract）\"的能力来简化你的工作量。\n\n使用LLM，你可以进行一系列的测试，如限制字数、限定主题、关注价格，并尝试用提取信息的方式替代总结。\n\n你还可以利用一个for循环，使用相同的提示模板来批量处理不同的内容。这样做可以帮助你更高效地处理大量评论。\n\n### Inferring 逻辑推理\n如果您想在用户评论中了解积极反馈和消极反馈的数量，那么您就需要使用\"LLM推理\"的能力。\n\n举例来说，LLM能够推理用户的情绪（sentiment），识别情绪类型（比如：happy、satisfied、grateful、impressed、content），提取品牌和商品信息并以JSON格式输出，还可以同时执行多个任务（例如提取用户评论中的商品并推理用户的情绪），推断主题，并基于推断的主题设计一个提醒程序等。\n\n因此，在用户评论中应用\"LLM推理\"的能力能够帮助您准确地了解积极反馈和消极反馈的情况。\n\n### Transforming 内容转换\n转换类应用是一种将一种语言转换为另一种语言的应用。\n\n例如，通过转换类应用，可以将一段文字翻译成另一种语言，识别一段文字所使用的语言，甚至同时将文本翻译成两种以上的语言。此外，还可以指定转换的语气是正式还是非正式的，指定适用于不同场合的语言，比如商务场合的邮件。转换类应用不仅限于自然语言的翻译，还可以进行程序语言的转换，例如将JSON转换为HTML。同时，您还可以要求LLM帮助您纠正语法错误。\n\n### Expanding 文本扩展\nLLM具备将简短文字扩展并添加修饰以及融入特定语言风格的能力。\n\n在下面的示例中，LLM充当了一个邮件回复助手的角色。您可以要求LLM撰写一封回复客户的邮件，并让它利用客户来信中的详细信息，以增加回复的真实感。此外，您还可以通过调整温度值来使回复显得不那么呆板。\n\n通过利用LLM的功能，您可以获得一封根据客户来信细节编写的回复邮件，同时也能根据需要灵活调整回复的语气。这使得与客户的邮件沟通更加个性化和真实。\n\n### Chatbot 对话Bot\n在使用OpenAI API发送消息时，消息中的角色可以包括系统（system）、用户（user）和助手（assistant）三种角色。\n\n系统角色（system）用于设定全局的风格和限制等信息。\n\n用户角色（user）表示人类用户，即发送消息的真实用户。\n\n助手角色（assistant）表示LLM，即语言模型，在对话中扮演回复和交互的角色。\n```bush\ndef get_completion(prompt, model=\"gpt-3.5-turbo\"):\n    messages = [{\"role\": \"user\", \"content\": prompt}]\n    response = openai.ChatCompletion.create(\n        model=model,\n        messages=messages,\n        temperature=0, # this is the degree of randomness of the model's output\n    )\n    return response.choices[0].message[\"content\"]\n\ndef get_completion_from_messages(messages, model=\"gpt-3.5-turbo\", temperature=0):\n    response = openai.ChatCompletion.create(\n        model=model,\n        messages=messages,\n        temperature=temperature, # this is the degree of randomness of the model's output\n    )\n    return response.choices[0].message[\"content\"] # print(str(response.choices[0].message))\n\nmessages =  [  \n{'role':'system', 'content':'You are an assistant that speaks like Shakespeare.'},    \n{'role':'user', 'content':'tell me a joke'},   \n{'role':'assistant', 'content':'Why did the chicken cross the road'},   \n{'role':'user', 'content':'I don\\'t know'}  ]\n\nresponse = get_completion_from_messages(messages, temperature=1)\nprint(response)\n\n```\n\n\n### Conclusion 结论\n在以下说明中，我们将讨论一些原则和能力相关的事项。\n\n一、原则：\n\n1. 指令要求清晰和具体，确保模型明确了解您的要求。\n\n2. 给予模型一些时间进行思考和处理。\n\n二、提示的开发过程是一个持续迭代的过程，需要不断进行调试和改进。\n\n三、模型具备以下能力：总结、推理、转换和扩展。这些能力可以在不同的应用场景中发挥作用。\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FConnectAI-E%2FPrompt-Engineering-Tutior","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FConnectAI-E%2FPrompt-Engineering-Tutior","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FConnectAI-E%2FPrompt-Engineering-Tutior/lists"}