1
2
3
動態推理和行動:ReAct生成語言推理軌跡和動作,允許動態推理以響應複雜的任務。 ... Active Prompting是透過動態選擇特定於任務的範例提示來增強LLMs對各種任務的適應性。
example_guidance
. This function takes a string as input (representing an example) and returns a formatted string that can be used as a prompt. The prompt instructs a language model to "参考以下範例並完成類似的任務" (refer to the following example and complete a similar task).def example_guidance(example):
return f"請參考以下範例並完成類似的任務:\n範例:{example}"
example = "這是一個範例句子。"
prompt = example_guidance(example)
print(prompt)
example_guidance
: This function takes a single argument, example
, which is a string.f
before the string indicates an f-string in Python, allowing for the embedding of variables directly into the string.{example}
is replaced with the actual value of the example
variable when the function is called.example
variable.example_guidance
function is called with this example, and the resulting prompt is stored in the prompt
variable.print
function displays the generated prompt.請寫一首關於[主題]的詩。首先,請列出幾個關鍵詞。然後,選擇一個關鍵詞,並寫下一個句子。以此類推,直到完成一首詩。
請確保你的回答與主題[主題]相關。請重新嘗試。
def react_prompt(task, example):
if task == "write_poem":
return f"請寫一首關於{example}的詩。首先,請列出幾個關鍵詞。然後,選擇一個關鍵詞,並寫下一個句子。以此類推,直到完成一首詩。"
elif task == "translate":
return f"請將以下句子從{source_language}翻譯成{target_language}: {example}"
# Example usage
task = "write_poem"
example = "愛情"
prompt = react_prompt(task, example)
print(prompt)
react_prompt
function now takes both a task
and an example
as input.def contextual_setting(context):
"""
提供背景信息,用於 miniAGI 理解任務上下文。
Args:
context: 字符串,描述任务的背景信息。
Returns:
字符串,格式为 "在以下背景下完成任務:\n 背景: {context}"
"""
return f"在以下背景下完成任務:\n 背景:{context}"
context = "這是一個商業會議的背景。"
prompt = contextual_setting(context)
print(prompt)
generate_uml_diagram
that is not defined.from uml_diagram import generate_uml_diagram # Assuming this function exists
def formal_development_process(system_description):
"""
Generates a prompt for creating a UML diagram based on a given system description.
Args:
system_description: A textual description of the system.
Returns:
A prompt string for a language model to generate a UML diagram.
"""
# Incorporate OOA/OOD concepts and 4+1 views into the prompt
prompt = f"""
Create a UML diagram that visually represents the following system:
{system_description}
**Consider the following:**
* **Identify key entities:** Determine the main objects and their attributes.
* **Define relationships:** Establish connections between entities (inheritance, composition, association).
* **Consider behaviors:** Model the actions and interactions between objects.
* **Use appropriate diagrams:** Employ a combination of use case, class, sequence, and state diagrams as needed to provide a comprehensive view of the system.
**Ensure the diagram adheres to UML conventions and effectively communicates the system's structure and behavior.**
**Example UML diagram elements:** classes, objects, attributes, methods, associations, aggregations, compositions, inheritance, interfaces, use cases, actors, and sequences.
**Output the UML diagram in a textual format that can be easily converted to a visual representation.**
"""
uml_diagram = generate_uml_diagram(system_description, prompt) # Pass the enhanced prompt
return uml_diagram
generate_uml_diagram
function now takes both the system description and the enhanced prompt as inputs.generate_uml_diagram
function could potentially interface with a UML modeling tool to directly create visual diagrams.1
2
3
1
2
3