forked from digibooms25/n8n-docs-complete
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_langchain_essentials.py
More file actions
245 lines (196 loc) · 8.15 KB
/
Copy pathcreate_langchain_essentials.py
File metadata and controls
245 lines (196 loc) · 8.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#!/usr/bin/env python3
"""
Create curated LangChain essentials bundle - only the most important files
"""
import os
import shutil
import json
def create_langchain_essentials():
print("🎯 Creating curated LangChain essentials bundle...")
source_dir = "n8n_docs_final"
output_dir = "claude_context_bundles/ai_workflows_compact"
# Create output directory
os.makedirs(output_dir, exist_ok=True)
# Essential LangChain files (hand-picked for maximum impact)
essential_langchain_files = [
# Core concepts
"overview",
"langchain_n8n",
"basic_llm_chain",
"conversational_agent",
"question_and_answer_chain",
# Most important nodes
"ai_agent",
"openai_chat_model",
"anthropic_chat_model",
"simple_memory",
"vector_store",
"text_classifier",
"information_extractor",
# Essential tools
"calculator",
"custom_code_tool",
"workflow_tool",
"vector_store_tool",
# Key integrations
"openai",
"anthropic",
"embeddings_openai",
"pinecone_vector_store",
# Critical concepts
"understand_agents",
"understand_chains",
"understand_memory",
"understand_tools",
"agent_chain_comparison"
]
# Priority order for file selection
priority_keywords = [
"overview", "basic", "simple", "getting", "started", "introduction",
"agent", "chain", "memory", "tool", "openai", "anthropic",
"chat", "model", "vector", "embeddings", "examples"
]
def get_file_priority(filename):
"""Calculate priority score for a file"""
score = 0
filename_lower = filename.lower()
# Check for essential files
for essential in essential_langchain_files:
if essential in filename_lower:
score += 100
# Check for priority keywords
for i, keyword in enumerate(priority_keywords):
if keyword in filename_lower:
score += (20 - i) # Higher score for earlier keywords
# Boost for shorter filenames (usually more focused)
if len(filename) < 30:
score += 5
return score
def copy_curated_files(source_folder, dest_folder, max_files=50):
"""Copy only the most essential files"""
if not os.path.exists(source_folder):
return 0
os.makedirs(dest_folder, exist_ok=True)
# Get all markdown files with priority scores
files_with_scores = []
for filename in os.listdir(source_folder):
if filename.endswith('.md') and filename != 'README.md':
score = get_file_priority(filename)
files_with_scores.append((filename, score))
# Sort by priority score (highest first)
files_with_scores.sort(key=lambda x: x[1], reverse=True)
# Copy top files
copied = 0
for filename, score in files_with_scores[:max_files]:
if score > 0: # Only copy files with some relevance
source_path = os.path.join(source_folder, filename)
dest_path = os.path.join(dest_folder, filename)
shutil.copy2(source_path, dest_path)
copied += 1
print(f" ✅ {filename} (priority: {score})")
return copied
total_files = 0
# Copy core essentials
print("📦 Adding core essentials...")
core_source = os.path.join(source_dir, "getting_started")
core_dest = os.path.join(output_dir, "core_essentials")
if os.path.exists(core_source):
copied = copy_curated_files(core_source, core_dest, max_files=10)
total_files += copied
print(f" 📁 Core essentials: {copied} files")
# Copy essential workflow docs
print("\n📦 Adding essential workflow docs...")
workflow_source = os.path.join(source_dir, "workflows")
workflow_dest = os.path.join(output_dir, "workflows_essentials")
if os.path.exists(workflow_source):
copied = copy_curated_files(workflow_source, workflow_dest, max_files=15)
total_files += copied
print(f" 📁 Workflow essentials: {copied} files")
# Copy curated LangChain docs (the main focus)
print("\n📦 Adding curated LangChain docs...")
langchain_source = os.path.join(source_dir, "ai_langchain")
langchain_dest = os.path.join(output_dir, "ai_langchain_curated")
if os.path.exists(langchain_source):
copied = copy_curated_files(langchain_source, langchain_dest, max_files=60)
total_files += copied
print(f" 📁 LangChain curated: {copied} files")
# Copy essential code/expressions
print("\n📦 Adding essential code docs...")
code_source = os.path.join(source_dir, "code_expressions")
code_dest = os.path.join(output_dir, "code_essentials")
if os.path.exists(code_source):
copied = copy_curated_files(code_source, code_dest, max_files=10)
total_files += copied
print(f" 📁 Code essentials: {copied} files")
# Copy most important integrations
print("\n📦 Adding key integrations...")
nodes_source = os.path.join(source_dir, "nodes_integrations")
nodes_dest = os.path.join(output_dir, "key_integrations")
if os.path.exists(nodes_source):
# Focus on AI-related nodes only
essential_nodes = ["openai", "anthropic", "langchain", "code", "webhook", "http"]
copied = 0
os.makedirs(nodes_dest, exist_ok=True)
for filename in os.listdir(nodes_source):
if filename.endswith('.md'):
for node in essential_nodes:
if node in filename.lower():
source_path = os.path.join(nodes_source, filename)
dest_path = os.path.join(nodes_dest, filename)
shutil.copy2(source_path, dest_path)
copied += 1
print(f" ✅ {filename}")
break
total_files += copied
print(f" 📁 Key integrations: {copied} files")
# Create bundle README
readme_content = f"""# 🎯 AI Workflows Compact Bundle
**Perfect for Claude projects focused on AI and LangChain workflows**
## 📊 Bundle Stats
- **Total Files:** {total_files}
- **Context Size:** ~70-90% of Claude's limit
- **Focus:** Essential AI workflow building
- **Quality:** Hand-curated for maximum impact
## 📁 Contents
### Core Essentials (~10 files)
Basic n8n concepts you always need
### Workflows Essentials (~15 files)
Key workflow building patterns
### AI LangChain Curated (~60 files)
**The essential LangChain documentation:**
- Core concepts (agents, chains, memory, tools)
- Most important nodes and integrations
- Practical examples and patterns
- Common troubleshooting
### Code Essentials (~10 files)
Essential coding and expressions
### Key Integrations (~15 files)
Critical nodes for AI workflows
## 🎯 What's NOT Included
To keep this bundle compact, we excluded:
- ❌ Rarely used LangChain nodes
- ❌ Advanced deployment docs
- ❌ Detailed API references
- ❌ Legacy/deprecated features
- ❌ Verbose tutorials (kept only essentials)
## 🚀 Usage
This bundle is optimized for:
- ✅ Building AI assistants and chatbots
- ✅ Creating LangChain workflows
- ✅ Integrating OpenAI/Anthropic models
- ✅ Working with vectors and embeddings
- ✅ Implementing memory and context
Perfect context size for Claude projects! 🤖
---
*Curated from the complete n8n documentation collection*
"""
with open(os.path.join(output_dir, "README.md"), 'w', encoding='utf-8') as f:
f.write(readme_content)
print(f"\n🎉 Compact AI workflows bundle created!")
print(f"📁 Location: {output_dir}/")
print(f"📊 Total files: {total_files}")
print(f"🎯 Estimated context usage: 70-90%")
print(f"\n✅ This bundle should work perfectly with Claude!")
return total_files
if __name__ == "__main__":
create_langchain_essentials()