mirror of
https://github.com/magnus919/agent-skills.git
synced 2026-09-17 06:26:31 +03:00
Greenfield SkillOpt: 3 epochs optimizing discoverability, decision guidance, and troubleshooting for a brand-new LangChain skill. Epoch 1 — Prominence: - Added critical AgentExecutor deprecation callout at top - Framework Routing Guide for cross-portfolio decisions Epoch 2 — Decision Guidance: - Where to Start table with AgentExecutor migration row - Pipeline Mode table (Quick/RAG/Agent/Production) Epoch 3 — Pattern Expansion: - Troubleshooting table with reference file links - FAQ section covering installation, migration, performance 13 files: SKILL.md, 7 references, 4 templates, 1 script. v1.0.0 -> v1.0.3 across 3 SkillOpt epochs. Signed-off-by: Magnus Hedemark <magnus919@pm.me>
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
#!/usr/bin/env python3
|
|
"""RAG pipeline: load, split, embed, retrieve, generate."""
|
|
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
|
|
from langchain_community.document_loaders import WebBaseLoader
|
|
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
|
from langchain_community.vectorstores import Chroma
|
|
from langchain_core.prompts import ChatPromptTemplate
|
|
from langchain_core.output_parsers import StrOutputParser
|
|
from langchain_core.runnables import RunnablePassthrough
|
|
|
|
# Load
|
|
loader = WebBaseLoader("https://example.com/docs")
|
|
docs = loader.load()
|
|
|
|
# Split
|
|
splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=200)
|
|
chunks = splitter.split_documents(docs)
|
|
|
|
# Embed + index
|
|
embeddings = OpenAIEmbeddings()
|
|
vectorstore = Chroma.from_documents(chunks, embeddings)
|
|
retriever = vectorstore.as_retriever(search_kwargs={"k": 3})
|
|
|
|
# RAG chain
|
|
prompt = ChatPromptTemplate.from_template(
|
|
"Answer using the context.\n\nContext: {context}\n\nQuestion: {question}"
|
|
)
|
|
model = ChatOpenAI(model="gpt-4o-mini")
|
|
|
|
def fmt(docs):
|
|
return "\n\n".join(d.page_content for d in docs)
|
|
|
|
chain = (
|
|
{"context": retriever | fmt, "question": RunnablePassthrough()}
|
|
| prompt | model | StrOutputParser()
|
|
)
|
|
|
|
result = chain.invoke("What is this documentation about?")
|
|
print(result)
|