Skip to content

Commit 1f2aece

Browse files
make llm gateway impl configurable
1 parent da5062c commit 1f2aece

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

src/datacustomcode/function/runtime.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
from datacustomcode.einstein_predictions_config import einstein_predictions_config
2222
from datacustomcode.file.path.default import DefaultFindFilePath
2323
from datacustomcode.function.base import BaseRuntime
24-
from datacustomcode.llm_gateway.default import DefaultLLMGateway
24+
from datacustomcode.llm_gateway.base import LLMGateway
25+
from datacustomcode.llm_gateway_config import llm_gateway_config
2526

2627

2728
class Runtime(BaseRuntime):
@@ -46,7 +47,7 @@ def __new__(cls):
4647
raise RuntimeError(
4748
"Runtime can only be instantiated once by the SDK.\n\n"
4849
"Do not instantiate it yourself. Accept it as a parameter:\n\n"
49-
" from datacustomcode.runtime.function.RunTime import Function\n"
50+
" from datacustomcode.function.runtime import Runtime\n"
5051
" \n"
5152
" def function(request: dict, runtime: Runtime) -> dict:\n"
5253
" response = {...}\n"
@@ -65,13 +66,19 @@ def __init__(self) -> None:
6566
super().__init__()
6667

6768
# Initialize resources
68-
self._llm_gateway = DefaultLLMGateway()
69+
self._llm_gateway: Optional[LLMGateway] = None
6970
self._file = DefaultFindFilePath()
7071
self._einstein_predictions: Optional[EinsteinPredictions] = None
7172

7273
@property
73-
def llm_gateway(self) -> DefaultLLMGateway:
74-
"""Access LLM operations."""
74+
def llm_gateway(self) -> LLMGateway:
75+
if self._llm_gateway is None:
76+
if llm_gateway_config.llm_gateway_config is None:
77+
raise RuntimeError(
78+
"LLM Gateway is not configured. "
79+
"Add 'llm_gateway_config' section to config.yaml"
80+
)
81+
self._llm_gateway = llm_gateway_config.llm_gateway_config.to_object()
7582
return self._llm_gateway
7683

7784
@property

src/datacustomcode/llm_gateway/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,11 @@
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
15+
16+
from datacustomcode.llm_gateway.base import LLMGateway
17+
from datacustomcode.llm_gateway.default import DefaultLLMGateway
18+
19+
__all__ = [
20+
"DefaultLLMGateway",
21+
"LLMGateway",
22+
]

0 commit comments

Comments
 (0)