Upload adapter_layer.py
Browse files- adapter_layer.py +13 -14
adapter_layer.py
CHANGED
|
@@ -1,22 +1,23 @@
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
import json
|
|
|
|
| 4 |
import torch
|
| 5 |
import inspect
|
| 6 |
import logging
|
| 7 |
-
import pydantic
|
| 8 |
-
import codecarbon
|
| 9 |
-
import importlib.util
|
| 10 |
-
from typing import Dict, Any, Optional, List
|
| 11 |
-
from service_registry import registry, MODEL, PRETRAINED_MODEL, TOKENIZER
|
| 12 |
-
import nltk
|
| 13 |
from model_List import PromptAnalyzer
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
| 20 |
|
| 21 |
# Import dependency helpers
|
| 22 |
def is_module_available(module_name):
|
|
@@ -26,8 +27,6 @@ def is_module_available(module_name):
|
|
| 26 |
except ImportError:
|
| 27 |
return False
|
| 28 |
|
| 29 |
-
logger = logging.getLogger(__name__)
|
| 30 |
-
|
| 31 |
class WildnerveModelAdapter:
|
| 32 |
"""Adapter layer that interfaces between HF inference endpoints and the model."""
|
| 33 |
RETRY_COUNT = 5
|
|
@@ -144,7 +143,7 @@ class WildnerveModelAdapter:
|
|
| 144 |
"tokenizer": self.tokenizer
|
| 145 |
}
|
| 146 |
|
| 147 |
-
def _split_prompt(self, prompt: str) ->
|
| 148 |
"""Return (technical_sentences, general_sentences)."""
|
| 149 |
# download punkt if needed
|
| 150 |
try:
|
|
|
|
| 1 |
import os
|
| 2 |
import sys
|
| 3 |
import json
|
| 4 |
+
import nltk
|
| 5 |
import torch
|
| 6 |
import inspect
|
| 7 |
import logging
|
| 8 |
+
import pydantic # required
|
| 9 |
+
import codecarbon
|
| 10 |
+
import importlib.util # required
|
|
|
|
|
|
|
|
|
|
| 11 |
from model_List import PromptAnalyzer
|
| 12 |
+
from typing import Dict, Any, Optional, List, Tuple
|
| 13 |
+
from service_registry import registry, MODEL, PRETRAINED_MODEL, TOKENIZER
|
| 14 |
|
| 15 |
+
# Log versions and fail fast if missing
|
| 16 |
+
logger = logging.getLogger(__name__)
|
| 17 |
+
logger.info(f"Using pydantic v{pydantic.__version__}")
|
| 18 |
+
logger.info(f"Using codecarbon v{codecarbon.__version__}")
|
| 19 |
+
|
| 20 |
+
print(f"Successfully using installed dependencies - pydantic: {pydantic.__version__}, codecarbon: {codecarbon.__version__}")
|
| 21 |
|
| 22 |
# Import dependency helpers
|
| 23 |
def is_module_available(module_name):
|
|
|
|
| 27 |
except ImportError:
|
| 28 |
return False
|
| 29 |
|
|
|
|
|
|
|
| 30 |
class WildnerveModelAdapter:
|
| 31 |
"""Adapter layer that interfaces between HF inference endpoints and the model."""
|
| 32 |
RETRY_COUNT = 5
|
|
|
|
| 143 |
"tokenizer": self.tokenizer
|
| 144 |
}
|
| 145 |
|
| 146 |
+
def _split_prompt(self, prompt: str) -> Tuple[str, str]:
|
| 147 |
"""Return (technical_sentences, general_sentences)."""
|
| 148 |
# download punkt if needed
|
| 149 |
try:
|