SREDWise commited on
Commit
d6490ab
1 Parent(s): e20583e

update handler.py for text generation

Browse files
Files changed (1) hide show
  1. 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 "inputs" and optional "parameters"
31
  Returns:
32
  Generated text
33
  """
34
- # Extract messages from input
35
- messages = data.get("inputs", {}).get("messages", [])
36
- if not messages:
37
- return {"error": "No messages provided"}
38
-
39
- # Format input text
40
- input_text = ""
41
- for msg in messages:
42
- role = msg.get("role", "")
43
- content = msg.get("content", "")
44
- input_text += f"{role}: {content}\n"
 
 
 
 
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}