นี่คือการใช้กราฟความคิดอย่างเป็นทางการ: การแก้ปัญหาที่ซับซ้อนด้วยแบบจำลองภาษาขนาดใหญ่
เฟรมเวิร์กนี้ช่วยให้คุณสามารถแก้ปัญหาที่ซับซ้อนได้โดยการสร้างแบบจำลองเป็นกราฟของการดำเนินงาน (GOO) ซึ่งดำเนินการโดยอัตโนมัติด้วยโมเดลภาษาขนาดใหญ่ (LLM) เป็นเครื่องยนต์
เฟรมเวิร์กนี้ได้รับการออกแบบให้มีความยืดหยุ่นและขยายได้ช่วยให้คุณไม่เพียง แต่แก้ปัญหาโดยใช้วิธีการใหม่ แต่ยังใช้ GOOS คล้ายกับวิธีการก่อนหน้านี้เช่น COT หรือ TOT
ในการใช้เฟรมเวิร์กนี้คุณต้องมีการติดตั้ง Python 3.8 หรือใหม่กว่า
ก่อนที่จะใช้วิธีการติดตั้งสองวิธีต่อไปนี้ตรวจสอบให้แน่ใจว่าได้เปิดใช้งานสภาพแวดล้อม Python ของคุณ (ถ้ามี) มาก่อน
หากคุณเป็นผู้ใช้และคุณต้องการใช้ graph_of_thoughts คุณสามารถติดตั้งได้โดยตรงจาก PYPI:
pip install graph_of_thoughtsหากคุณเป็นนักพัฒนาและคุณต้องการแก้ไขรหัสคุณสามารถติดตั้งในโหมดแก้ไขได้จากแหล่งที่มา:
git clone https://github.com/spcl/graph-of-thoughts.git
cd graph-of-thoughts
pip install -e .ในการใช้เฟรมเวิร์กคุณต้องเข้าถึง LLM โปรดทำตามคำแนะนำในคอนโทรลเลอร์ readme เพื่อกำหนดค่า LLM ที่คุณเลือก
ตัวอย่างโค้ดต่อไปนี้แสดงวิธีการใช้เฟรมเวิร์กเพื่อแก้ปัญหาการเรียงลำดับสำหรับรายการหมายเลข 32 โดยใช้วิธีการเหมือนเปล
ตรวจสอบให้แน่ใจว่าคุณได้ติดตามคู่มือการตั้งค่าก่อนเรียกใช้รหัส
from examples . sorting . sorting_032 import SortingPrompter , SortingParser , utils
from graph_of_thoughts import controller , language_models , operations
# Problem input
to_be_sorted = "[0, 2, 6, 3, 8, 7, 1, 1, 6, 7, 7, 7, 7, 9, 3, 0, 1, 7, 9, 1, 3, 5, 1, 3, 6, 4, 5, 4, 7, 3, 5, 7]"
# Create the Graph of Operations
gop = operations . GraphOfOperations ()
gop . append_operation ( operations . Generate ())
gop . append_operation ( operations . Score ( scoring_function = utils . num_errors ))
gop . append_operation ( operations . GroundTruth ( utils . test_sorting ))
# Configure the Language Model (Assumes config.json is in the current directory with OpenAI API key)
lm = language_models . ChatGPT ( "config.json" , model_name = "chatgpt" )
# Create the Controller
ctrl = controller . Controller (
lm ,
gop ,
SortingPrompter (),
SortingParser (),
# The following dictionary is used to configure the initial thought state
{
"original" : to_be_sorted ,
"current" : "" ,
"method" : "cot"
}
)
# Run the Controller and generate the output graph
ctrl . run ()
ctrl . output_graph ( "output_cot.json" )ในการเรียกใช้วิธีการที่มีความซับซ้อนมากขึ้นคุณสามารถใช้ตัวอย่างโค้ดต่อไปนี้
from examples . sorting . sorting_032 import SortingPrompter , SortingParser , got , utils
from graph_of_thoughts import controller , language_models , operations
# Problem input
to_be_sorted = "[0, 2, 6, 3, 8, 7, 1, 1, 6, 7, 7, 7, 7, 9, 3, 0, 1, 7, 9, 1, 3, 5, 1, 3, 6, 4, 5, 4, 7, 3, 5, 7]"
# Retrieve the Graph of Operations
gop = got ()
# Configure the Language Model (Assumes config.json is in the current directory with OpenAI API key)
lm = language_models . ChatGPT ( "config.json" , model_name = "chatgpt" )
# Create the Controller
ctrl = controller . Controller (
lm ,
gop ,
SortingPrompter (),
SortingParser (),
# The following dictionary is used to configure the initial thought state
{
"original" : to_be_sorted ,
"current" : "" ,
"phase" : 0 ,
"method" : "got"
}
)
# Run the Controller and generate the output graph
ctrl . run ()
ctrl . output_graph ( "output_got.json" ) คุณสามารถเปรียบเทียบผลลัพธ์ทั้งสองได้โดยการตรวจสอบกราฟเอาต์พุต output_cot.json และ output_got.json
คะแนนสถานะความคิดสุดท้ายระบุจำนวนข้อผิดพลาดในรายการที่เรียงลำดับ
กระดาษให้ภาพรวมระดับสูงของเฟรมเวิร์กและส่วนประกอบ
เพื่อที่จะเข้าใจกรอบการทำงานในรายละเอียดเพิ่มเติมคุณสามารถอ่านเอกสารของแต่ละโมดูล
โดยเฉพาะอย่างยิ่งโมดูลคอนโทรลเลอร์และการดำเนินงานมีความสำคัญต่อการทำความเข้าใจวิธีการใช้ประโยชน์สูงสุดจากกรอบ
เราใช้ความระมัดระวังเป็นพิเศษในการจัดทำเอกสารโค้ดอย่างเต็มที่เพื่อให้คุณสามารถเข้าใจวิธีการทำงานและวิธีการขยาย
ไดเรกทอรีตัวอย่างมีตัวอย่างหลายประการของปัญหาที่สามารถแก้ไขได้โดยใช้เฟรมเวิร์กรวมถึงสิ่งที่นำเสนอในกระดาษ
มันเป็นจุดเริ่มต้นที่ดีสำหรับการเรียนรู้วิธีการใช้กรอบเพื่อแก้ปัญหาที่แท้จริง
แต่ละตัวอย่างมีไฟล์ README.md พร้อมคำแนะนำเกี่ยวกับวิธีการเรียกใช้และเล่นกับมัน รหัสได้รับการบันทึกไว้อย่างสมบูรณ์และควรติดตามได้ง่าย นอกจากนี้คุณยังสามารถเรียกใช้ตัวอย่างได้โดยตรงจากไดเรกทอรีหลัก โปรดทราบว่าผลลัพธ์จะถูกเก็บไว้ในไดเรกทอรีย่อยตัวอย่างที่เกี่ยวข้อง
ลองตัวอย่างเช่น:
python -m examples.sorting.sorting_032
python -m examples.keyword_counting.keyword_counting คุณสามารถเรียกใช้การทดลองจากกระดาษโดยทำตามคำแนะนำในไดเรกทอรีตัวอย่าง
อย่างไรก็ตามหากคุณต้องการตรวจสอบและแทนที่ผลลัพธ์คุณสามารถใช้ไดเรกทอรีกระดาษได้
หากคุณพบว่าพื้นที่เก็บข้อมูลนี้มีค่าโปรดให้ดาว!
มีคำถามหรือข้อเสนอแนะหรือไม่? อย่าลังเลที่จะเข้าถึง [email protected] หรือเปิดปัญหา
ใช้สิ่งนี้ในงานของคุณ? โปรดอ้างอิงเราโดยใช้การอ้างอิงที่ให้ไว้:
@article { besta2024got ,
title = { {Graph of Thoughts: Solving Elaborate Problems with Large Language Models} } ,
author = { Besta, Maciej and Blach, Nils and Kubicek, Ales and Gerstenberger, Robert and Gianinazzi, Lukas and Gajda, Joanna and Lehmann, Tomasz and Podstawski, Micha{l} and Niewiadomski, Hubert and Nyczyk, Piotr and Hoefler, Torsten } ,
year = 2024 ,
month = { Mar } ,
journal = { Proceedings of the AAAI Conference on Artificial Intelligence } ,
volume = 38 ,
number = 16 ,
pages = { 17682-17690 } ,
publisher = { AAAI Press } ,
doi = { 10.1609/aaai.v38i16.29720 } ,
url = { https://ojs.aaai.org/index.php/AAAI/article/view/29720 }
}