🔨 refactor(conftest.py): reformat code for better readability and maintainability
✨ feat(conftest.py): add MyCustomChain class as an example of a custom chain ✨ feat(conftest.py): add CustomChain class as a custom component for building a document ✨ feat(conftest.py): add CSVLoaderComponent class as a custom component for loading CSV files and converting rows to documents
This commit is contained in:
parent
10c0b3871c
commit
99ef7c728d
1 changed files with 120 additions and 90 deletions
|
|
@ -235,3 +235,33 @@ def custom_chain():
|
||||||
def build(self, prompt, llm, input: str) -> Document:
|
def build(self, prompt, llm, input: str) -> Document:
|
||||||
chain = MyCustomChain(prompt=prompt, llm=llm)
|
chain = MyCustomChain(prompt=prompt, llm=llm)
|
||||||
return chain(input)'''
|
return chain(input)'''
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def data_processing():
|
||||||
|
return """import pandas as pd
|
||||||
|
from langchain.schema import Document
|
||||||
|
from langflow.interface.custom.base import CustomComponent
|
||||||
|
|
||||||
|
class CSVLoaderComponent(CustomComponent):
|
||||||
|
display_name: str = "CSV Loader"
|
||||||
|
field_config = {
|
||||||
|
"filename": {"field_type": "str", "required": True},
|
||||||
|
"column_name": {"field_type": "str", "required": True},
|
||||||
|
}
|
||||||
|
|
||||||
|
def build(self, filename: str, column_name: str) -> List[Document]:
|
||||||
|
# Load the CSV file
|
||||||
|
df = pd.read_csv(filename)
|
||||||
|
|
||||||
|
# Verify the column exists
|
||||||
|
if column_name not in df.columns:
|
||||||
|
raise ValueError(f"Column '{column_name}' not found in the CSV file")
|
||||||
|
|
||||||
|
# Convert each row of the specified column to a document object
|
||||||
|
documents = []
|
||||||
|
for content in df[column_name]:
|
||||||
|
metadata = {"filename": filename}
|
||||||
|
documents.append(Document(page_content=str(content), metadata=metadata))
|
||||||
|
|
||||||
|
return documents"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue