diff --git a/src/__init__.py b/src/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/datacustomcode/function_runtime/FunctionRuntime.py b/src/datacustomcode/function_runtime/FunctionRuntime.py new file mode 100644 index 0000000..e69de29 diff --git a/src/datacustomcode/llm_gateway/LLMGateway.py b/src/datacustomcode/llm_gateway/LLMGateway.py new file mode 100644 index 0000000..f8ff490 --- /dev/null +++ b/src/datacustomcode/llm_gateway/LLMGateway.py @@ -0,0 +1,12 @@ +class LLMGateway(BaseLLMGateway): + def generate_text( + self, + request: GenerateTextRequest + ) -> GenerateTextResponse: + + + response_data = { + 'generation' : {'generatedText' : "I am dreaming!!"}, + } + + return GenerateTextResponse(200, {"data": response_data}) \ No newline at end of file diff --git a/src/datacustomcode/llm_gateway/__init__.py b/src/datacustomcode/llm_gateway/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/datacustomcode/proxy/client/base.py b/src/datacustomcode/llm_gateway/base.py similarity index 87% rename from src/datacustomcode/proxy/client/base.py rename to src/datacustomcode/llm_gateway/base.py index 85e304a..5cae6c9 100644 --- a/src/datacustomcode/proxy/client/base.py +++ b/src/datacustomcode/llm_gateway/base.py @@ -19,12 +19,12 @@ from datacustomcode.proxy.base import BaseProxyAccessLayer -class BaseProxyClient(BaseProxyAccessLayer): +class BaseLLMGateway: def __init__(self): pass @abstractmethod - def call_llm_gateway(self, llmModelId: str, prompt: str, maxTokens: int) -> str: ... + def generate_text(self, GenerateTextRequest) -> GenerateTextResponse: ... @abstractmethod def llm_gateway_generate_text( diff --git a/src/datacustomcode/llm_gateway/types/GenerateTextRequest.py b/src/datacustomcode/llm_gateway/types/GenerateTextRequest.py new file mode 100644 index 0000000..dddd4b4 --- /dev/null +++ b/src/datacustomcode/llm_gateway/types/GenerateTextRequest.py @@ -0,0 +1,22 @@ +# Generated by the protocol buffer compiler. DO NOT EDIT! +# sources: llm_gateway.proto +# plugin: python-betterproto +from dataclasses import dataclass +from typing import Optional + +import betterproto +import grpclib + +from .google import protobuf + + +@dataclass +class GenerateTextRequest(betterproto.Message): + version: str = betterproto.string_field(1) + model_name: str = betterproto.string_field(2) + prompt: str = betterproto.string_field(3) + localization: protobuf.Struct = betterproto.message_field(4) + tags: protobuf.Struct = betterproto.message_field(5) + + + diff --git a/src/datacustomcode/llm_gateway/types/GenerateTextResponse.py b/src/datacustomcode/llm_gateway/types/GenerateTextResponse.py new file mode 100644 index 0000000..83f09d9 --- /dev/null +++ b/src/datacustomcode/llm_gateway/types/GenerateTextResponse.py @@ -0,0 +1,16 @@ + +from dataclasses import dataclass +from typing import Optional + +import betterproto +import grpclib + +from .google import protobuf + + + +@dataclass +class GenerateTextResponse(betterproto.Message): + version: str = betterproto.string_field(1) + status_code: int = betterproto.uint32_field(2) + data: protobuf.Struct = betterproto.message_field(3) diff --git a/src/datacustomcode/llm_gateway/types/__init__.py b/src/datacustomcode/llm_gateway/types/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/datacustomcode/proxy/__init__.py b/src/datacustomcode/proxy/__init__.py deleted file mode 100644 index 93988ff..0000000 --- a/src/datacustomcode/proxy/__init__.py +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2025, Salesforce, Inc. -# SPDX-License-Identifier: Apache-2 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/src/datacustomcode/proxy/base.py b/src/datacustomcode/proxy/base.py deleted file mode 100644 index 71cf314..0000000 --- a/src/datacustomcode/proxy/base.py +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright (c) 2025, Salesforce, Inc. -# SPDX-License-Identifier: Apache-2 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from __future__ import annotations - -from abc import ABC - -from datacustomcode.mixin import UserExtendableNamedConfigMixin - - -class BaseProxyAccessLayer(ABC, UserExtendableNamedConfigMixin): - def __init__(self): - pass diff --git a/src/datacustomcode/proxy/client/LocalProxyClientProvider.py b/src/datacustomcode/proxy/client/LocalProxyClientProvider.py deleted file mode 100644 index 9c08b54..0000000 --- a/src/datacustomcode/proxy/client/LocalProxyClientProvider.py +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright (c) 2025, Salesforce, Inc. -# SPDX-License-Identifier: Apache-2 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -from __future__ import annotations - -from datacustomcode.proxy.client.base import BaseProxyClient - - -class LocalProxyClientProvider(BaseProxyClient): - """Default proxy client provider.""" - - CONFIG_NAME = "LocalProxyClientProvider" - - def __init__(self, **kwargs: object) -> None: - pass - - def call_llm_gateway(self, llmModelId: str, prompt: str, maxTokens: int) -> str: - return f"Hello, thanks for using {llmModelId}. So many tokens: {maxTokens}" - - def llm_gateway_generate_text( - self, template, values, llmModelId: str, maxTokens: int - ): - return f"Using Generate Text with {llmModelId} and maxTokens: {maxTokens}" diff --git a/src/datacustomcode/proxy/client/__init__.py b/src/datacustomcode/proxy/client/__init__.py deleted file mode 100644 index 93988ff..0000000 --- a/src/datacustomcode/proxy/client/__init__.py +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2025, Salesforce, Inc. -# SPDX-License-Identifier: Apache-2 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. diff --git a/src/datacustomcode/templates/function/payload/entrypoint.py b/src/datacustomcode/templates/function/payload/entrypoint.py index f90e110..5b314c8 100644 --- a/src/datacustomcode/templates/function/payload/entrypoint.py +++ b/src/datacustomcode/templates/function/payload/entrypoint.py @@ -2,6 +2,10 @@ from typing import List from uuid import uuid4 +import datacustomcode.ll_gateway.types.GenerateTextRequest +import datacustomcode.file +import datacustomcode.function_runtime.FunctionRuntime + logger = logging.getLogger(__name__) @@ -33,7 +37,7 @@ def chunk_text(text: str, chunk_size: int = 1000) -> List[str]: return chunks -def function(request: dict) -> dict: +def function(request: dict, runTime: FunctionRuntime) -> dict: logger.info("Inside Function") logger.info(request) @@ -41,6 +45,18 @@ def function(request: dict) -> dict: output_chunks = [] current_seq_no = 1 # Start sequence number from 1 + + request = GenerateTextRequest.with_locale(modelName= "", prompt="How are you doing?", locale="en_EN") + response = client.llm_gateway.genearte_text(request) + if response.is_success: + print(response.text) + else: + print(response.error_code) + + file_path = runTime.file.find_path("data.csv") + content = open(file_path, 'r').read() + logger.info(content) + for item in items: # Item is DocElement as dict logger.info(f"Processing item: {item}")