ผู้ช่วยการเข้ารหัส RAG เอาต์พุตรหัสการทำงานในภาษานิพจน์ Langchain (LCEL) เพื่อพัฒนาต้นแบบ AI รุ่นใหม่อย่างรวดเร็ว
GPT-4 ไม่ได้มีความรู้เกี่ยวกับ LCEL ในข้อมูลการฝึกอบรมดังนั้นเครื่องมือนี้ใช้เทคนิคการเรียกคืนแบบสืบค้นแบบกำหนดเอง (RAG) เพื่อระบุ ตัวอย่างการเข้ารหัสที่เกี่ยวข้อง และเพิ่มเข้ามาในหน้าต่างบริบทเป็นตัวอย่างไม่กี่ตัวอย่าง
/data มีตัวอย่างรหัสการทำงานและเนื้อหาเมตาบางส่วนเพื่อช่วยในการดึงข้อมูล/data จะถูกฝังอยู่ในฐานข้อมูลเวกเตอร์ทอผ้าทอคุณสามารถอ่านเกี่ยวกับกระบวนการในรายละเอียดเพิ่มเติมเกี่ยวกับ SUDTACK
หรือดูวิดีโอคำแนะนำ
นี่คือต้นแบบการทำงานที่ออกแบบมาเพื่อการพัฒนาในท้องถิ่น
ปรับปรุงกระบวนการฝังและการดึงข้อมูล: เพื่อให้ได้การแข่งขันที่มีคุณภาพสูงฉันแค่ฝังคำอธิบายชวเลขสำหรับแต่ละตัวอย่างรหัสที่แยกข้อมูลเฉพาะของวิธีการ ดูตัวอย่างด้านล่างที่คำอธิบายที่ใช้ในการฝังเป็นเวอร์ชันสั้นลงของความคิดเห็นรหัสเต็มในรหัสตัวอย่าง:
"""
tags: [langchain, rag]
description: |
- Accept string
- Retrieve matching documents using DocArrayInMemorySearch vectorstore
- Format single prompt
- Parse response as string
"""
# Create a chain that does the following:
# - Accept a string as input
# - Retrieve matching documents from a DocArrayInMemorySearch vectorstore, and pass through the results and the original question to a prompt
# - Format the prompt using variables from the object
# - Pass the prompt to OpenAI
# - Parse the OpenAI response as a string
from langchain.chat_models import ChatOpenAI
from langchain.embeddings import OpenAIEmbeddings
from langchain.prompts import ChatPromptTemplate
from langchain.schema.output_parser import StrOutputParser
from langchain.schema.runnable import RunnableParallel, RunnablePassthrough
from langchain.vectorstores import DocArrayInMemorySearch
vectorstore = DocArrayInMemorySearch.from_texts(
["Lisa likes cooking", "Bears like honey"],
embedding=OpenAIEmbeddings(),
)
retriever = vectorstore.as_retriever()
template = """Answer the question:
{context}
Question: {question}
"""
prompt = ChatPromptTemplate.from_template(template)
model = ChatOpenAI()
output_parser = StrOutputParser()
setup_and_retrieval = RunnableParallel(
{"context": retriever, "question": RunnablePassthrough()}
)
chain = setup_and_retrieval | prompt | model | output_parser
chain.invoke("What does Lisa like?")
เมื่อมีตัวอย่างเพียงพอแล้วฉันอาจสำรวจการสร้างแบบจำลองที่ปรับแต่งเพื่อแปลงความคิดเห็นของรหัสโดยละเอียดเป็นคำอธิบายการจดชวเลขนั้นเพื่อฝังตัวอย่างโค้ดทั้งสองรวมถึงคำขอของผู้ใช้
ขยายสิ่งนี้นอกเหนือจาก LCEL - ฉันรวมตัวเลือกไว้ในแท็กตัวอย่างรหัสเพื่อระบุเทคโนโลยีหรือคำหลัก สิ่งเหล่านี้สามารถใช้เป็นตัวกรองที่แข็งในแบบสอบถามทอ แต่ตอนนี้ฉันไม่ได้ใช้งานเนื่องจากผลลัพธ์ค่อนข้างแม่นยำ แต่มันอาจจำเป็นต้องมีความจำเป็นเมื่อไดเรกทอรีตัวอย่างเติบโตขึ้น