迷你通用型人工智慧之軟體架構 Software Architecture of miniAGI
AGI 通用人工智慧 (Artificial General Intelligence) 是AI界的聖杯, 也是我們希望挑戰的大目標,
工程萬分浩大, 所以嘗試先定義出迷你型的AGI之必要的軟體架構, 已備深入研究與探討,
打造一個彈性、可擴展的智慧數位人系統,希望運用他來處理與解決當下現今社會的問題
感謝國科會專案廖御圻教授與相關人員提供資源與協助, 專案編號111-2410-H-468 -008 -MY3
作者: 沈雲謙 Alex Shen 指導教授 Advisor: 蔡志仁教授 亞洲大學資訊工程學系
中華民國113年11月3日 Taichung, Taiwan, Republic of Chain (R.O.C.)
了解更多
大綱Agenda
背景動機
系統簡介 (人工修改AI版)(HI人類智慧版)
架構圖
提示工程與方法論 Prompt Engineering & Methodology
核心模組
通用型基礎知識管理平台
自然語言處理(輸出入)
知識/經驗/智慧建構專家平台
推理與決策
學習與優化
未來發展
背景動機
2021年的既定的想法, 以期終結社會亂象與政治對立,產生真正對人民有幫助的智慧政策,落實與實踐長期智慧教育目標
系統簡介

1

全方位的人工智慧解決方案
迷你通用型人工智慧提供涵蓋通用型基礎知識管理平台、自然語言處理、知識建構、推理決策等多個核心模組的完整系統。

2

靈活性與擴充性
系統採用模組化設計,各功能模組可單獨使用或靈活組合,滿足不同場景的需求。

3

成熟穩定的技術基礎
基於先進的LLM大語言模型、生成式AI、深度學習、機器學習及知識圖譜等技術,提供可靠、高效的AI人工智慧與HI(Human Intelligence)人類智慧合作服務。
HI人類智慧版
系統簡介
目的: 為了要終結社會亂象(缺水缺電缺疫苗缺雞蛋)與政治對立,產生真正對人民有幫助的智慧政策,落實與實踐長期智慧教育目標
說明: 嘗試研究"智慧數位人之必要軟體架構"
架構圖
使用 prompt 幫助搜尋到的開源 AGI 模組庫架構圖 (2023 年 7 月 23 日,llama2-map 模組庫架構圖)
我們的miniAGI系統架構圖 (三個核心模組套件, 一個內部子系統, 一個評估子系統, 三個附屬關聯系統)
miniAGI系統與可搭配三個附屬系統的整體圖(三個附屬系統: 政治專家系統推論機, 綜合現況評估與政策規劃產生知識平台, 大數據政策實驗模型模擬平台)
Mediator媒合協調者子系統示意圖
知識管理平台架構
通用型基礎知識管理平台架構(主要分成三大類: 專業知識, 常識, 雜識等 立體化呈現)
知識/經驗/智慧建構專系統平台示意圖
自然語言處理(輸出入)架構堆疊
提示工程與方法論 Prompt Engineering & Methodology
在使用提示方法論和提示工程來進行miniAGI的基礎研究時,我們所使用的策略和技術包括以下幾種:
1.任務專注提示(Task-Specific Prompting):為特定任務設計專門的提示語,以提升模型在特定領域的準確性。例如,在解釋複雜問題時加入範例能顯著提升模型理解和回應的精度思維鏈(Chain of Thought, CoT)提示:這可讓模型分步處理複雜的推理問題,通過鼓勵模型按步驟回答來提升其推理能力。在miniAGI的應用中,這類分步式提示有助於模擬更細緻的思考過程 :
def task_specific_prompt(task):
if task == "翻譯":
return "請將以下句子翻譯成英文:"
elif task == "摘要":
return "請為以下文章生成摘要:"
else:
return "請完成以下任務:"
task = "翻譯"
prompt = task_specific_prompt(task)
print(prompt)
1.任務專注提示(Task-Specific Prompting)
同樣的問題, 分別由Copilot & Gemini 回答, 可增強同學學習比較能力!

Gemini

‎Gemini - Python提示工程範例

Created with Gemini

提示工程與方法論
2.動態調整提示(Dynamic Prompting):根據模型的回應動態調整提示,讓模型的生成更符合需求。動態提示結合了多階段的回應確認,以精確引導模型的回答 :
def dynamic_prompt(response):
if "錯誤" in response:
return "請重新檢查並修正以下內容:"
else:
return "請繼續完成以下內容:"
response = "這裡有一個錯誤"
prompt = dynamic_prompt(response)
print(prompt)

Gemini

‎Gemini - 動態提示範例程式優化

Created with Gemini

2.動態調整提示(Dynamic Prompting)
談談2.動態調整提示(Dynamic Prompting)這個概念與技術
Gemini答復
動態調整提示 (Dynamic Prompting) 是一種提示工程技術,它會根據模型的回應 5,在互動過程中實時調整提示内容,以引導模型生成更符合需求的結果。
舉例來說,如果模型的回應中包含錯誤,則提示可以轉為告知錯誤並要求改正的方向 [5]。
更进一步,動態調整提示可以结合迭代式提示 (Iterative Prompting) 的方法,逐步细化提示信息,从而让模型逐步提炼出更准确的答案 [4, 6]。
資料来源
  • Sertis Corp - The Art of Prompt Engineering: A Developer's Toolkit
  • Medium - Mastering Iterative Prompting: A Guide to Enhanced AI Interactions
  • arXiv - Understanding the Effects of Iterative Prompting on ...
3.範例引導(Acting):利用實時樣本或範例來指導模型,特別是在未知或模糊領域中探索應用miniAGI的潛力
Gemini 回應: Prompt Analysis and Response
Prompt:
動態推理和行動:ReAct生成語言推理軌跡和動作,允許動態推理以響應複雜的任務。 ... Active Prompting是透過動態選擇特定於任務的範例提示來增強LLMs對各種任務的適應性。
Understanding the Prompt
The prompt is discussing two key concepts in the field of AI, particularly in relation to large language models (LLMs):
  1. ReAct: This refers to a framework that combines language reasoning and actions. It allows AI models to generate a sequence of language-based reasoning steps and actions in response to complex tasks. For instance, if asked to book a flight, a ReAct model could first search for flights, then compare prices, and finally make a reservation.
  1. Active Prompting: This technique involves dynamically selecting specific examples or prompts based on the task at hand. By tailoring the prompts to the task, it enhances the LLM's ability to adapt to various scenarios.
Key Points and Potential Questions
  • Dynamic Reasoning: Both ReAct and Active Prompting emphasize the dynamic nature of AI reasoning, where the model's responses are influenced by the specific task and the evolving context.
  • Task Adaptation: Active Prompting highlights the importance of tailoring prompts to improve the model's performance on diverse tasks.
  • Action Generation: ReAct introduces the concept of generating actions based on language reasoning, which opens up possibilities for AI systems to interact with the real world.
Potential questions based on the prompt:
  • What are the key differences between ReAct and Active Prompting?
  • How can Active Prompting be used to improve the performance of LLMs on specific tasks?
  • What are some potential applications of ReAct in real-world scenarios?
  • How can we evaluate the effectiveness of ReAct and Active Prompting?
Response
Prompt Engineering Techniques: ReAct and Active Prompting
The prompt introduces two innovative techniques in prompt engineering: ReAct and Active Prompting. These methods aim to enhance the capabilities of large language models (LLMs) by making the prompting process more dynamic and adaptive.
  • ReAct offers a framework for LLMs to engage in complex tasks that involve both language understanding and action execution. By generating a sequence of language-based reasoning steps and actions, ReAct enables models to tackle multi-step problems. For example, a ReAct model could be used to plan a trip, which involves tasks like searching for flights, booking hotels, and creating an itinerary.
  • Active Prompting focuses on selecting the most appropriate prompts for a given task. By dynamically choosing examples or instructions, Active Prompting helps LLMs better adapt to different scenarios and improve their performance. For instance, when training an LLM for sentiment analysis, Active Prompting could select examples that are particularly challenging or representative of the target domain.
Key Differences and Applications
While both techniques aim to improve the performance of LLMs, they have different focuses:
  • ReAct emphasizes the generation of actions and the ability to interact with the environment.
  • Active Prompting focuses on selecting the best prompts to guide the model's reasoning.
Potential Applications
  • Customer Service: ReAct could be used to create chatbots that can handle complex customer inquiries, such as troubleshooting technical issues or processing returns.
  • Education: Active Prompting could be used to generate personalized learning experiences by tailoring prompts to each student's needs and abilities.
  • Scientific Discovery: ReAct could be used to assist researchers in exploring large datasets and generating new hypotheses.
Evaluation
Evaluating the effectiveness of ReAct and Active Prompting requires careful consideration of the specific task and evaluation metrics. Some potential evaluation metrics include:
  • Task completion rate: How often does the model successfully complete the given task?
  • Quality of the generated text: How well does the generated text match the desired output?
  • Efficiency: How quickly can the model generate a response?
In conclusion, ReAct and Active Prompting are promising techniques for enhancing the capabilities of LLMs. By combining language reasoning with action generation and dynamically selecting prompts, these methods can enable AI systems to perform a wider range of tasks with greater accuracy and efficiency.
Would you like to explore any of these concepts in more detail?
Possible follow-up questions:
  • Can you provide a concrete example of how ReAct could be used in a medical diagnosis scenario?
  • What are some of the challenges in implementing Active Prompting for complex tasks?
  • How can we ensure that the actions generated by a ReAct model are safe and ethical?
Please let me know if you have any other questions.
Prompt Analysis and Response
Prompt Breakdown:
The provided Python code defines a simple function named 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).
Code Explanation:
def example_guidance(example): return f"請參考以下範例並完成類似的任務:\n範例:{example}" example = "這是一個範例句子。" prompt = example_guidance(example) print(prompt)
  1. Function Definition:
  • example_guidance: This function takes a single argument, example, which is a string.
  1. String Formatting:
  • 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.
  1. Return Value:
  • The function returns a formatted string, which is essentially a prompt instructing a model to follow the provided example.
  1. Usage:
  • A sample example string is assigned to the example variable.
  • The example_guidance function is called with this example, and the resulting prompt is stored in the prompt variable.
  • Finally, the print function displays the generated prompt.
Prompt Engineering Perspective:
The given code demonstrates a basic form of prompting where the goal is to provide a clear and concise instruction to the language model. However, there's room for improvement based on the concepts of ReAct and Active Prompting:
Potential Enhancements:
  1. Incorporate ReAct:
  • Break down complex tasks into smaller, sequential steps.
  • Allow the model to generate intermediate responses that guide subsequent steps.
  • For example, if the task is to write a poem, the prompt could be:請寫一首關於[主題]的詩。首先,請列出幾個關鍵詞。然後,選擇一個關鍵詞,並寫下一個句子。以此類推,直到完成一首詩。
  1. Utilize Active Prompting:
  • Dynamically adjust the prompt based on the model's previous responses.
  • Provide more specific examples or constraints as needed.
  • For instance, if the model's initial response is off-topic, the prompt could be refined to:請確保你的回答與主題[主題]相關。請重新嘗試。
  1. Consider Context:
  • Incorporate relevant context into the prompt to guide the model's understanding.
  • For example, if the task is to translate a sentence, the prompt could include information about the source and target languages.
Revised Code (Example with ReAct and Active Prompting):
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)
Explanation of the Revised Code:
  • The react_prompt function now takes both a task and an example as input.
  • The function provides different prompts based on the specified task, incorporating elements of both ReAct (breaking down the task into steps) and Active Prompting (adjusting the prompt based on the task).
  • Additional features like context-aware prompting and error handling can be added to further enhance the functionality.
By combining the principles of ReAct and Active Prompting, we can create more sophisticated and effective prompts that guide language models to produce high-quality outputs.
4.語境設置(Contextual Setting): 供豐富的背景信息,使模型能更準確理解使用場景,特別是在多步驟的解決方案中,這對miniAGI的模擬和長期目標設定有幫助
Gemini 回覆 4. 語境設置(Contextual Setting):
miniAGI 的目標是模擬人类的思维过程,并逐步实现通用人工智能 (AGI)。在多步骤的任务中,为 miniAGI 提供丰富的背景信息至关重要。
例如,用户可能会要求 miniAGI "写一篇关于探索火星的科幻小说开头”。 理解这个任务需要知道科幻小说的典型元素以及火星探索的背景知识。
通过为 miniAGI 提供上下文信息,我们可以:
  • 提高任务完成率:
  • 改善输出的质量:
  • 使 miniAGI 能夠学习和适应更复杂的任务:
Sources
  • AI News Roundup: GPT-4o Mini, AGI Developments, and Industry Updates | LinkedIn [invalid URL removed] [4]
完善後的程式碼
def contextual_setting(context): """ 提供背景信息,用於 miniAGI 理解任務上下文。 Args: context: 字符串,描述任务的背景信息。 Returns: 字符串,格式为 "在以下背景下完成任務:\n 背景: {context}" """ return f"在以下背景下完成任務:\n 背景:{context}" context = "這是一個商業會議的背景。" prompt = contextual_setting(context) print(prompt)
改進之處
  1. 添加函数注释 (docstring),解釋函數的功能、参数和返回值 [1]
  1. 修改部分用語,使其更清晰易懂。
引用資料
其他可能的改进
  • 根據任務的需要,可以加入額外的上下文信息,例如會議議題、參與者身份等等。
  • 可以考慮加入不同的模板,用於不同的上下文設定類型。
5.正規的軟體開發工程(OOA/OOD/OOP/OOT): 使用物件導向開發技術與術語,配合UML圖形(4+1 views)來讓Prompt Engineering和開發團隊始終專注在軟體架構的分析,設計與驗證上
5. 正規的軟體開發工程(OOA/OOD/OOP/OOT): 使用物件導向開發技術與術語,配合UML圖形(4+1 views)來讓Prompt Engineering和開發團隊始終專注在軟體架構的分析,設計與驗證上
回答
結合物件導向開發與提示工程,打造更強大的 AI 應用
將物件導向分析與設計 (OOA/OOD) 的嚴謹方法與彈性的提示工程 (Prompt Engineering) 結合,可以為軟體開發帶來巨大的優勢。
為什麼要結合?
  • 提升模型可解釋性: OOA/OOD 強調將系統分解成可管理的物件,並定義它們之間的關係。這種結構化的方式可以幫助我們更好地理解大型語言模型 (LLM) 的行為,並提高模型的可解釋性。
  • 改善模型性能: 通過使用 UML 圖形 (如類圖、序列圖、用例圖等),我們可以更清晰地表達系統的靜態結構和動態行為。這些圖形可以作為生成提示的藍圖,幫助 LLM 更好地理解任務和生成更相關的回應。
  • 促進團隊協作: OOA/OOD 提供了一種通用的語言和視覺化工具,可以促進開發團隊之間的溝通和協作。提示工程則可以讓團隊更靈活地調整模型的行為。
如何結合?
  1. 使用 UML 建模:
  • 用例圖: 確定系統的功能需求,並將這些需求轉換為提示。
  • 類圖: 定义系统的静态结构,包括类、属性和方法。这些信息可以用来生成更具针对性的提示。
  • 序列图: 描述对象之间的交互,可以用来生成多步骤的提示。
  1. 將 UML 模型轉換為提示:
  • 類轉換為對象: 將類的属性和方法轉換為提示中的參數和指令。
  • 關係轉換為提示: 將類之間的關係(例如繼承、關聯)轉換為提示中的條件或限制。
  1. 利用提示工程優化模型:
  • 精細調整提示: 根據模型的輸出,不斷調整提示,以獲得更好的結果。
  • 利用上下文: 將上下文信息(例如用戶的偏好、歷史數據)融入提示中,以提供更個性化的服務。
範例: 假設我們要開發一個智能客服系統。我們可以使用 UML 建模來定義客戶、產品、訂單等類,以及它們之間的關係。然後,我們可以將這些模型轉換為提示,例如:
  • 用例: 客戶查詢訂單狀態
  • 提示: "請你扮演一個客服人員,回答客戶關於訂單狀態的查詢。客戶的訂單號是 [訂單號],請查詢訂單的配送狀態並告知客戶。"
總結
通過將 OOA/OOD 和提示工程相結合,我們可以:
  • 提高開發效率: 減少開發錯誤,提高軟體質量。
  • 增强模型能力: 讓模型更好地理解複雜的任務。
  • 促進團隊協作: 提供一個共同的語言和視覺化工具。
參考資料
注意: 雖然 UML 可以提供良好的結構,但提示工程的靈活性也同樣重要。我們需要根據具體的應用場景和模型的能力來調整提示。
想要了解更多嗎? 可以進一步探討以下主題:
  • UML 的各種圖形 如何應用於提示工程
  • 如何將大型語言模型 與 UML 模型集成
  • 如何評估 基於 UML 和提示工程的系統
歡迎提出更多問題!
Prompt Analysis and Response
Prompt Breakdown:
The provided Python code aims to create a prompt for a language model, designed to generate a UML diagram based on a given system description. However, it assumes a pre-existing function generate_uml_diagram that is not defined.
Key Requirements:
  1. OOA/OOD Integration: The prompt should clearly articulate the need for an object-oriented approach in the UML diagram generation.
  1. 4+1 Views: While the code doesn't explicitly mention the 4+1 views, it's implied that the generated diagram should consider multiple perspectives.
  1. Prompt Engineering: The prompt should be clear, concise, and guide the language model towards generating a comprehensive and accurate UML diagram.
Improved Response:
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
Explanation of Changes:
  1. Enhanced Prompt: The prompt now explicitly mentions key OOA/OOD concepts like entities, relationships, and behaviors, guiding the language model to generate a more comprehensive UML diagram.
  1. 4+1 Views: While not explicitly mentioned in the prompt, the request for a "comprehensive view" implies consideration of multiple perspectives, which aligns with the 4+1 views.
  1. UML Elements: A list of common UML elements is provided to remind the language model of the possibilities.
  1. Output Format: The prompt specifies that the output should be in a textual format that can be easily converted to a visual representation, allowing for further processing or visualization.
  1. Function Modification: The generate_uml_diagram function now takes both the system description and the enhanced prompt as inputs.
Additional Considerations:
  • UML Tool Integration: The generate_uml_diagram function could potentially interface with a UML modeling tool to directly create visual diagrams.
  • Prompt Refinement: The prompt could be further refined based on the specific requirements of the project and the capabilities of the language model.
  • Contextual Information: Additional context, such as domain-specific knowledge or constraints, could be added to the prompt to improve the quality of the generated diagrams.
Why this is an improvement:
  • More comprehensive guidance: The enhanced prompt provides a more detailed and structured guide for the language model.
  • Better alignment with OOA/OOD principles: The emphasis on entities, relationships, and behaviors ensures that the generated UML diagrams adhere to object-oriented design principles.
  • Flexibility: The prompt allows for the generation of various UML diagram types, providing a more comprehensive view of the system.
By incorporating these improvements, the provided code effectively combines the strengths of object-oriented analysis and design with the power of prompt engineering to generate high-quality UML diagrams.
6.智慧論的整合運用
核心模組
通用型基礎知識管理平台
輕鬆整合各類結構化與非結構化資料,提供資料清洗、分類、查詢等功能。 來處理"專業知識", "常識", "雜識"等三大類知識管理, 擷取與儲存.
自然語言處理(輸出入)
利用先進的NLP技術,實現人機自然對話、文本分析、問答系統等功能。
知識/經驗/智慧建構專家平台
基於知識圖譜技術,構建圖形化/結構化的向量知識庫,支援複雜的知識推理與邏輯計算。
通用型基礎知識管理平台

1

資料整合
通過ETL工具輕鬆整合各類結構化與非結構化資料,包括文檔、表格、訊息等。

2

資料清洗
運用機器學習技術對資料進行清洗和標準化,確保數據質量。

3

資料倉儲
採用分層式資料倉儲設計,對資料進行有效的組織、儲存和管理。
自然語言處理(輸出入)
文本分析
能夠分析文本內容,識別情感、主題、實體等。
對話系統
提供人機自然對話能力,了解使用者意圖並給出適當回應。
問答系統
基於豐富的知識庫/向量庫,回答使用者提出的各類問題。
多語種支持
支持多種語言的輸入輸出,實現跨語言的溝通。
知識/經驗/智慧建構專家平台
知識圖譜技術…產生可供快速檢索的向量圖型知識庫
基於知識圖譜的技術,建立結構化、可推理的知識庫,支援複雜的邏輯推理和知識查詢。
知識抽取與整合
  • 從非結構化資料中自動抽取知識
  • 整合各類異質知識源,形成豐富的知識網絡
知識推理與應用
利用知識圖譜進行推理、演算,提供智能決策支援、知識問答等功能。
經驗/智慧產生
推理與決策
要推敲出適合miniAGI的軟體架構真的非常不容易, 它必須在"設計模式", "架構模式"以及"自然關聯環境"這三大類交互影響的環境, 條件或限制下, 找出合理解; 首先入選的是在"設計模式"中的"輕量級Flyweight Pattern"
1
邏輯推理
基於知識圖譜和規則引擎,提供複雜的邏輯推理和演算能力。 https://m.mobile01.com/topicdetail.php?f=506&t=7022885
2
特殊整合式機器學習
運用半監督學習、深度強化學習等技術,實現預測、分類、優化等決策支援。

PDF file

3
智慧分析決策支援平台
整合邏輯推理和機器學習,為用戶提供智能化的決策建議和方案。

hdl.handle.net

臺灣博碩士論文知識加值系統:自由的博碩士學位論文全文資料庫

學習與優化
在"架構模式"中入選的是"平台服務模式"包含AaaS, SaaS, PaaS, IaaS 而其都架構在SOA(服務導向架構)之上

1

持續學習
系統可以根據使用者反饋和新資料,持續學習和優化,提高性能和智慧。

2

模型微調
針對特定場景,可以對LLM模型進行微調和優化,增強針對性的能力。

3

性能監控
系統會持續監控關鍵指標,及時發現問題並作出調整,確保系統穩定運行。
未來發展
跨領域融合
要與心理學門, 腦神經學門合作, 發展評估miniAGI人格特質/本徵觀點參數平衡, 迷你通用型人工智慧就可以與各行各業的應用程式無縫整合,賦能行業轉型升級。
技術持續進化
系統會持續吸收行業前沿技術,如元宇宙、量子運算等, 進行系統移轉至高速平行電腦/量子電腦上,不斷提升智慧水準。
智慧生活助手
未來,系統可以成為人們日常生活中的偉人級智慧助手,提供全方位的智慧服務與學習教導。
再次感謝"遊戲成癮風險的神經心理機制與其AI預測模型"國科會專案的御圻老師, 志仁老師讓我們自行嘗試發展可解決問題的AI模型, 所以才有這個緣分參賽, 再一次感謝大家!!! Alex 雲謙
Made with Gamma