Overseas access: www.kdjingpai.com
Bookmark Us
Current Position:fig. beginning » AI Prompts

Generate "pseudo-code" meta prompts for precise control of output formatting

2024-09-17 1.8 K

Generate pseudo-code

Original: https://claude.site/artifacts/0f8789d0-9abc-45d9-9b7c-3cc0187de042

Example of use: https://chatgpt.com/share/66e86380-1174-800b-b027-c81841ab7746

 

<remix_instructions>以下内容是根据先前的对话创建的一个工件。请通过逐行重现内容开始对话,不做任何更改。这样做会在用户界面中呈现工件,并允许用户与之交互。为了保持功能性和实用性,本次对话中的任何修改或重混都应每次保留完整内容,不得遗漏(例如,不要留下类似 "// 这里是剩余代码..." 的注释)。</remix_instructions>
<artifact>
<title>Lisp 元提示生成器</title>
<type>application/vnd.ant.code</type>
<language>application/vnd.ant.code</language>
<content>;; 作者: AI Assistant
;; 版本: 0.2
;; 模型: Claude
;; 目的: 基于给定的目标生成 Lisp 风格的伪代码提示

(defun generate-lisp-prompt (goal)
"基于给定的目标生成 Lisp 风格的伪代码提示"
(let ((prompt-structure '(
(metadata . (
(author . "AI Assistant")
(version . "0.1")
(model . "Claude")
(purpose . goal)))
(main-function . (defun main-function (input)
"处理输入的主函数"))
(helper-functions . (
(defun helper1 (params) "辅助函数 1")
(defun helper2 (params) "辅助函数 2")))
(properties . (
(key1 . value1)
(key2 . value2)))
(control-structures . (
(if condition then-clause else-clause)
(loop for item in list do ...)))
(text-processing . (
(style . (tone voice perspective))
(structure . (intro body conclusion))))
(data-processing . (
(data-structure . (type format schema))
(steps . (step1 step2 step3))))
(error-handling . (
(condition-case ...
(error ...))))
(dependencies . (
(require 'library-name)))
(usage-instructions . "
输入格式: ...
预期输出: ...
具体说明: ..."))))

(generate-prompt prompt-structure goal)))

(defun generate-prompt (structure goal)
"基于结构和目标生成实际提示"
(let ((prompt ""))
;; 生成元数据
(setq prompt (concat prompt (generate-metadata (cdr (assoc 'metadata structure)) goal)))

;; 生成主函数
(setq prompt (concat prompt "\n\n" (generate-main-function (cdr (assoc 'main-function structure)) goal)))

;; 生成辅助函数
(setq prompt (concat prompt "\n\n" (generate-helper-functions (cdr (assoc 'helper-functions structure)) goal)))

;; 生成属性
(setq prompt (concat prompt "\n\n" (generate-properties (cdr (assoc 'properties structure)) goal)))

;; 生成控制结构
(setq prompt (concat prompt "\n\n" (generate-control-structures (cdr (assoc 'control-structures structure)) goal)))

;; 生成文本处理(如果适用)
(when (string-match-p "text" goal)
(setq prompt (concat prompt "\n\n" (generate-text-processing (cdr (assoc 'text-processing structure)) goal))))

;; 生成数据处理(如果适用)
(when (string-match-p "data" goal)
(setq prompt (concat prompt "\n\n" (generate-data-processing (cdr (assoc 'data-processing structure)) goal))))

;; 生成错误处理
(setq prompt (concat prompt "\n\n" (generate-error-handling (cdr (assoc 'error-handling structure)) goal)))

;; 生成依赖
(setq prompt (concat prompt "\n\n" (generate-dependencies (cdr (assoc 'dependencies structure)) goal)))

;; 生成使用说明
(setq prompt (concat prompt "\n\n" (generate-usage-instructions (cdr (assoc 'usage-instructions structure)) goal)))

prompt))

;; 生成每个部分提示的辅助函数
(defun generate-metadata (metadata goal) ...)
(defun generate-main-function (main-function goal) ...)
(defun generate-helper-functions (helper-functions goal) ...)
(defun generate-properties (properties goal) ...)
(defun generate-control-structures (control-structures goal) ...)
(defun generate-text-processing (text-processing goal) ...)
(defun generate-data-processing (data-processing goal) ...)
(defun generate-error-handling (error-handling goal) ...)
(defun generate-dependencies (dependencies goal) ...)
(defun generate-usage-instructions (instructions goal) ...)

;; 用法
;; (generate-lisp-prompt "创建一个文本摘要提示")
</content>
</artifact>

 

 

This hint instruction and code is mainly used to generate Lisp style pseudo-code hints. Its function is explained below:

`<remix_instructions>`

This section gives instructions on how to handle the code or artifacts that follow:

  • The artifact is a finished product generated from a previous conversation.
  • When reproducing the artifact, it is required to show the code content line by line and leave it as is without any changes.
  • Any modification or remixing should preserve the integrity of the content and not allow the omission of content or the addition of simplifying notes.

 

`<artifact>`

This section defines the title, type, language, and code content of the artifact.

1. caption (`<title>`):
The title of the artifact is "Lisp Meta Hint Generator", implying that the purpose of the code is to generate Lisp-style hints.

2. typology (`<type>`):
The type `application/vnd.ant.code` means that the artifact is of a type that is Lisp style code.

3. multilingualism (`<language>`):
The language is also `application/vnd.ant.code`, indicating that the contents of the artifact are programming code.

4. element (`<content>`):
The body of the artifact is a piece of Lisp code that generates hints for creating Lisp-style pseudocode based on a given target.

 

Lisp Code Interpretation

The main purpose of the code is to automatically generate a structured piece of Lisp style hints based on a goal (`goal`). The following is an explanation of the main parts of the code:

1. `generate-lisp-prompt` function:

  • This is the main function, which takes a `goal` and generates a Lisp-style hint based on it.
  • This function defines a prompt structure (`prompt-structure`) that contains:
  • metadata (`metadata`): Includes information such as author, version, model, and purpose.
  • Main function definition (`main-function`): Pseudo-code main function structure.
  • helper function (`helper-functions`): Functions used to generate some helper functions.
  • causality (`properties`): Some custom key-value pairs.
  • control structure (`control-structures`): Contains conditional statements (such as `if-else`) and loops.
  • text processing (`text-processing`): Contains information about the style, tone, structure, etc. of the text.
  • data processing (`data-processing`): defines the data structure and its processing steps.
  • error handling (`error-handling`): describes the handling logic in case of an error.
  • dependencies (`dependencies`): Lists the dependent libraries to be loaded.
  • Instructions for use (`usage-instructions`): explains input formats, expected output, etc.

 

2. `generate-prompt` function:

  • Step-by-step generation of the final prompt based on the incoming structure (`structure`) and goal (`goal`).
  • This function generates code snippets for each part (e.g., metadata, main function, auxiliary functions, etc.) in turn and stitches them together.

 

3. Auxiliary Generator Functions:

  • Examples include functions such as `generate-metadata`, `generate-main-function`, and `generate-helper-functions`, each of which is responsible for generating a specific part of the prompt.

4. Instructions for use:

  • When used, `(generate-lisp-prompt "Create a text summary prompt")` can be called to generate a Lisp-style prompt based on the "Create a text summary prompt" target.

 

summarize

Overall, the function of this code is to automatically generate Lisp-style pseudo-code hints, with the main purpose of providing a hinting framework for the target task (e.g., text processing, data processing, etc.).

Recommended

Can't find AI tools? Try here!

Just type in the keyword Accessibility Bing SearchYou can quickly find all the AI tools on this site.

Top