rag coding assistant
1.0.0
Rag Coding Assistant는 새로운 생성 AI 프로토 타입을 신속하게 개발하기 위해 Langchain 표현 언어 (LCEN)의 작업 코드를 출력합니다.
GPT-4는 현재 교육 데이터에 LCEN에 대한 지식이 없으므로이 도구는 맞춤형 검색-예술 생성 (RAG) 기술을 사용하여 관련 적, 완전한 코딩 예제를 식별하고 컨텍스트 창에 몇 가지 예제로 추가합니다.
/data 디렉토리에는 작업 코드 예제 및 검색을 지원하는 일부 메타 컨텐츠가 채워집니다./data 디렉토리의 모든 코드 예제는 weaviate 벡터 데이터베이스에 포함됩니다.Subsack에서 프로세스에 대해 더 자세히 읽을 수 있습니다.
또는 비디오 연습을보십시오.
이것은 지역 개발을 위해 설계된 작업 프로토 타입입니다.
임베딩 및 검색 프로세스 향상 : 고품질 일치를 얻으려면 접근 방식의 주요 세부 사항을 추출하는 각 코드 예제에 대한 속기 설명 만 포함됩니다. 임베딩에 사용 된 설명이 예제 코드에서 전체 코드 주석의 단축 버전 인 아래의 예를 참조하십시오.
"""
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?")
예제가 충분하면 코드 예제와 사용자 요청을 포함시키기 위해 세부 코드 주석을 해당 속기 설명으로 변환하기 위해 미세 조정 된 모델을 작성하는 것을 탐색 할 수 있습니다.
LCEN 이외의 확장 - 예제 코드 메타 태그에 옵션이 포함되어 기술이나 키워드를 지정합니다. 이들은 Weaviate 쿼리에서 하드 필터로 사용될 수 있지만 결과는 현재 매우 정확하기 때문에 현재 사용하지 않습니다. 그러나 예제 디렉토리가 커짐에 따라 필요할 수 있습니다.