Skip to content

Commit 49b98b2

Browse files
author
Wyatt Cannon
committed
Removed extra imports and fixed formatting
1 parent 1f081bb commit 49b98b2

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

src/hayhooks/server/pipelines/models.py

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
from typing import get_args, get_origin, List, get_type_hints
21
from hayhooks.server.utils.create_valid_type import create_valid_type
32
from pandas import DataFrame
43
from pydantic import BaseModel, create_model, ConfigDict
5-
from haystack.dataclasses import Document, ExtractedAnswer
6-
import json
74

85

9-
class HaystackDocument(BaseModel):
10-
id: str
11-
content: str
12-
136
class PipelineDefinition(BaseModel):
147
name: str
158
source_code: str
@@ -62,21 +55,18 @@ def get_response_model(pipeline_name: str, pipeline_outputs):
6255

6356
def convert_component_output(component_output):
6457
"""
58+
Converts outputs from a component as a dict so that it can be validated against response model
59+
6560
Component output has this form:
6661
6762
"documents":[
6863
{"id":"818170...", "content":"RapidAPI for Mac is a full-featured HTTP client."}
6964
]
7065
71-
We inspect the output and convert haystack.Document into the HaystackDocument pydantic model as needed
7266
"""
7367
result = {}
7468
for output_name, data in component_output.items():
75-
# Empty containers, None values, empty strings and the likes: do nothing
76-
if not data:
77-
result[output_name] = data
7869
get_value = lambda data: data.to_dict()["init_parameters"] if hasattr(data, "to_dict") else data
79-
# Output contains a list of Document
8070
if type(data) is list:
8171
result[output_name] = [get_value(d) for d in data]
8272
else:

0 commit comments

Comments
 (0)