added handler for inference endpoint
Browse files- __pycache__/handler.cpython-311.pyc +0 -0
- test_handler.py +24 -0
__pycache__/handler.cpython-311.pyc
ADDED
|
Binary file (3.28 kB). View file
|
|
|
test_handler.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
from handler import EndpointHandler
|
| 3 |
+
|
| 4 |
+
# Instantiate the handler with a dummy model_dir (replace with actual path if needed)
|
| 5 |
+
# Since we are testing the handler logic and not loading a real model here,
|
| 6 |
+
# we can initialize it with a placeholder. If your __init__ requires a valid path,
|
| 7 |
+
# you might need to adjust this or mock the AutoTokenizer and AutoModelForSeq2SeqLM calls.
|
| 8 |
+
# For a basic test of the __call__ method's structure, this might suffice.
|
| 9 |
+
# If model loading is essential for your test, you'll need to handle that.
|
| 10 |
+
handler = EndpointHandler(model_dir=".")
|
| 11 |
+
|
| 12 |
+
# Example function without a docstring
|
| 13 |
+
def multiply(a, b):
|
| 14 |
+
return a * b
|
| 15 |
+
|
| 16 |
+
# Prepare the data in the expected format for the handler
|
| 17 |
+
test_data = {"inputs": ["def multiply(a, b):\n return a * b"]}
|
| 18 |
+
|
| 19 |
+
# Call the handler
|
| 20 |
+
try:
|
| 21 |
+
response = handler(test_data)
|
| 22 |
+
print(json.dumps(response, indent=2))
|
| 23 |
+
except Exception as e:
|
| 24 |
+
print(f"An error occurred: {e}")
|