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-我在示例代码元标记中包含一个选项,以指定技术或关键字。这些可以用作编织查询中的硬过滤器,但是我目前不使用它们,因为结果当前非常准确。但是随着示例目录的增长,这可能变得有必要。