handler v10 (#10)
Browse files- added custom handler v10 (5c1c65df923fa28b6b35bb844fb144a7a8509693)
- handler.py +1 -21
handler.py
CHANGED
@@ -95,27 +95,7 @@ class EndpointHandler:
|
|
95 |
response = output_text#[len(prompt):].strip()
|
96 |
logger.info(f"Generated response: {json.dumps(response)}")
|
97 |
|
98 |
-
|
99 |
-
#return {"result": response, "error": None}
|
100 |
-
return {
|
101 |
-
"id": "cmpl-" + str(hash(response))[:10], # Generate a unique ID
|
102 |
-
"object": "chat.completion",
|
103 |
-
"created": int(time.time()),
|
104 |
-
"model": self.model.config.name_or_path,
|
105 |
-
"choices": [{
|
106 |
-
"index": 0,
|
107 |
-
"message": {
|
108 |
-
"role": "assistant",
|
109 |
-
"content": response
|
110 |
-
},
|
111 |
-
"finish_reason": "stop"
|
112 |
-
}],
|
113 |
-
"usage": {
|
114 |
-
"prompt_tokens": len(inputs["input_ids"][0]),
|
115 |
-
"completion_tokens": len(output_tokens[0]) - len(inputs["input_ids"][0]),
|
116 |
-
"total_tokens": len(output_tokens[0])
|
117 |
-
}
|
118 |
-
}
|
119 |
|
120 |
except Exception as e:
|
121 |
logger.error(f"Error during generation: {str(e)}", exc_info=True)
|
|
|
95 |
response = output_text#[len(prompt):].strip()
|
96 |
logger.info(f"Generated response: {json.dumps(response)}")
|
97 |
|
98 |
+
return [{"generations": [{"text": response}]}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
except Exception as e:
|
101 |
logger.error(f"Error during generation: {str(e)}", exc_info=True)
|