rag coding assistant
1.0.0
抹布編碼助手以蘭鍊錶達語言(LCEL)輸出工作代碼,以便快速開發新的生成AI原型。
GPT-4目前在其培訓數據中尚不了解LCEL,因此該工具使用自定義檢索型生成(RAG)技術來識別相關,完整的編碼示例,並將它們添加到上下文窗口中,將其添加到少量示例中。
/data目錄填充有效的代碼示例和一些元內容以幫助檢索/data目錄中的所有代碼示例都嵌入編織矢量數據庫中您可以在替代方面更詳細地閱讀有關該過程的信息。
或觀看視頻演練。
這是一個專為本地開發設計的工作原型。
改進嵌入和檢索過程:為了獲得高質量的匹配,我只嵌入每個代碼示例的速記說明,以提取方法的關鍵細節。請參閱下面的一個示例,其中嵌入中使用的描述是示例代碼中的完整代碼註釋的縮短版本:
"""
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-我在示例代碼元標記中包含一個選項,以指定技術或關鍵字。這些可以用作編織查詢中的硬過濾器,但是我目前不使用它們,因為結果當前非常準確。但是隨著示例目錄的增長,這可能變得有必要。