|
1 |
| -from typing import get_args, get_origin, List, get_type_hints |
2 | 1 | from hayhooks.server.utils.create_valid_type import create_valid_type
|
3 | 2 | from pandas import DataFrame
|
4 | 3 | from pydantic import BaseModel, create_model, ConfigDict
|
5 |
| -from haystack.dataclasses import Document, ExtractedAnswer |
6 |
| -import json |
7 | 4 |
|
8 | 5 |
|
9 |
| -class HaystackDocument(BaseModel): |
10 |
| - id: str |
11 |
| - content: str |
12 |
| - |
13 | 6 | class PipelineDefinition(BaseModel):
|
14 | 7 | name: str
|
15 | 8 | source_code: str
|
@@ -62,21 +55,18 @@ def get_response_model(pipeline_name: str, pipeline_outputs):
|
62 | 55 |
|
63 | 56 | def convert_component_output(component_output):
|
64 | 57 | """
|
| 58 | + Converts outputs from a component as a dict so that it can be validated against response model |
| 59 | +
|
65 | 60 | Component output has this form:
|
66 | 61 |
|
67 | 62 | "documents":[
|
68 | 63 | {"id":"818170...", "content":"RapidAPI for Mac is a full-featured HTTP client."}
|
69 | 64 | ]
|
70 | 65 |
|
71 |
| - We inspect the output and convert haystack.Document into the HaystackDocument pydantic model as needed |
72 | 66 | """
|
73 | 67 | result = {}
|
74 | 68 | 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 |
78 | 69 | get_value = lambda data: data.to_dict()["init_parameters"] if hasattr(data, "to_dict") else data
|
79 |
| - # Output contains a list of Document |
80 | 70 | if type(data) is list:
|
81 | 71 | result[output_name] = [get_value(d) for d in data]
|
82 | 72 | else:
|
|
0 commit comments