Text files Comparion - Need Help #28119
Replies: 1 comment 7 replies
-
To refine and optimize your code for matching tasks from File 1 with detailed content from File 2 and generating enriched outputs using LangChain, you can follow these steps:
Here's a refined version of your code: from langchain.embeddings import HuggingFaceEmbeddings
from langchain.vectorstores import FAISS
from langchain.document_loaders import TextLoader
from langchain.llms import OpenAI
# Load documents
loader1 = TextLoader("C:/Users/file1.txt")
docs1 = loader1.load()
loader2 = TextLoader("C:/Users/file2.txt")
docs2 = loader2.load()
# Create embeddings
embeddings = HuggingFaceEmbeddings()
# Create vector stores
db1 = FAISS.from_documents(docs1, embeddings)
db2 = FAISS.from_documents(docs2, embeddings)
# Initialize the LLM
llm = OpenAI()
# Match and enhance tasks
for doc1 in docs1:
# Find the most relevant document in File 2
similar_docs = db2.similarity_search(doc1.content, k=1)
if similar_docs:
detailed_content = similar_docs[0].content
# Generate enriched description
enriched_description = llm.generate(
prompt=f"Enhance the following task description: {detailed_content}",
max_tokens=150
)
print(f"Task: {doc1.content}\nEnhanced Description: {enriched_description}\n") Key Changes:
This should help you achieve the objective of matching and enhancing task descriptions using LangChain. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Project Description: Text-Based Task Comparison with Creative Enhancement
I have two text files containing task-related content.
File 1 lists high-level tasks, providing brief descriptions.
File 2 contains more detailed content, covering descriptions not only for the tasks in File 1 but also for hundreds of other tasks.
Example:
File 1: “Langchain work”
File 2: “Build a Langchain application using OpenAI technology for enhanced functionality and performance”
Objective: I want to establish a relationship between the high-level tasks in File 1 and the relevant, detailed content from File 2. Specifically, the goal is to:
Match each high-level task in File 1 with its most relevant, detailed counterpart in File 2.
Generate an enriched and creative output using both files. For each matched task, the output should:
Draw content from File 2 as a primary reference.
Use an LLM to add depth, creativity, and a comprehensive explanation to the task description, going beyond what’s in File 2.
Requirements: The LLM, using Langchain, should systematically:
Pick each task from File 1.
Identify the closest matching or related content in File 2.
Produce a detailed and creatively enhanced description, using information from File 2 as a foundation and further enriched with LLM capabilities.
The code I’ve been using so far is below. Could you help refine or optimize it to better align with these objectives?
Beta Was this translation helpful? Give feedback.
All reactions