update handler.py for text generation
Browse files- handler.py +16 -12
handler.py
CHANGED
@@ -27,21 +27,25 @@ class EndpointHandler:
|
|
27 |
def __call__(self, data: Dict):
|
28 |
"""
|
29 |
Args:
|
30 |
-
data: Dictionary with
|
31 |
Returns:
|
32 |
Generated text
|
33 |
"""
|
34 |
-
#
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
input_text
|
|
|
|
|
|
|
|
|
45 |
|
46 |
# Get generation parameters
|
47 |
params = {**self.default_params}
|
|
|
27 |
def __call__(self, data: Dict):
|
28 |
"""
|
29 |
Args:
|
30 |
+
data: Dictionary with either string input or structured messages
|
31 |
Returns:
|
32 |
Generated text
|
33 |
"""
|
34 |
+
# Handle input
|
35 |
+
if isinstance(data.get("inputs"), str):
|
36 |
+
input_text = data["inputs"]
|
37 |
+
else:
|
38 |
+
# Extract messages from input
|
39 |
+
messages = data.get("inputs", {}).get("messages", [])
|
40 |
+
if not messages:
|
41 |
+
return {"error": "No messages provided"}
|
42 |
+
|
43 |
+
# Format input text
|
44 |
+
input_text = ""
|
45 |
+
for msg in messages:
|
46 |
+
role = msg.get("role", "")
|
47 |
+
content = msg.get("content", "")
|
48 |
+
input_text += f"{role}: {content}\n"
|
49 |
|
50 |
# Get generation parameters
|
51 |
params = {**self.default_params}
|