Skip to content

Commit caf53a6

Browse files
Fixing lint error
1 parent 217ff14 commit caf53a6

14 files changed

Lines changed: 79 additions & 45 deletions

File tree

src/datacustomcode/llm_gateway/base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@
1616

1717
from abc import abstractmethod
1818

19+
from datacustomcode.llm_gateway.types.generate_text_request import GenerateTextRequest
20+
from datacustomcode.llm_gateway.types.generate_text_response import GenerateTextResponse
21+
22+
1923
class LLMGateway:
2024
def __init__(self):
2125
pass
2226

2327
@abstractmethod
24-
def generate_text(self, GenerateTextRequest) -> GenerateTextResponse: ...
28+
def generate_text(self, request: GenerateTextRequest) -> GenerateTextResponse: ...

src/datacustomcode/llm_gateway/default.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,18 @@
1616
from datacustomcode.llm_gateway.base import LLMGateway
1717
from datacustomcode.llm_gateway.types.generate_text_request import GenerateTextRequest
1818
from datacustomcode.llm_gateway.types.generate_text_response import GenerateTextResponse
19+
from datacustomcode.llm_gateway.types.generate_text_response_builder import (
20+
GenerateTextResponseBuilder,
21+
)
1922

20-
from datacustomcode.llm_gateway.types.generate_text_response_builder import GenerateTextResponseBuilder
2123

2224
class DefaultLLMGateway(LLMGateway):
23-
def generate_text(
24-
self,
25-
request: GenerateTextRequest
26-
) -> GenerateTextResponse:
27-
25+
def generate_text(self, request: GenerateTextRequest) -> GenerateTextResponse:
2826

2927
response_data = {
30-
'version': 'v1',
31-
'status_code': 200,
32-
'data' : {
33-
'generation': {'generatedText': 'Hello World'}
34-
}
28+
"version": "v1",
29+
"status_code": 200,
30+
"data": {"generation": {"generatedText": "Hello World"}},
3531
}
3632

3733
return GenerateTextResponseBuilder.build(response_data)

src/datacustomcode/llm_gateway/types/generate_text_request.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,34 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
from typing import Optional, Dict, Any, Literal
17-
from pydantic import BaseModel, Field, ConfigDict
16+
from typing import (
17+
Any,
18+
Dict,
19+
Literal,
20+
Optional,
21+
)
22+
23+
from pydantic import (
24+
BaseModel,
25+
ConfigDict,
26+
Field,
27+
)
1828
from pydantic.alias_generators import to_camel
1929

2030

2131
class GenerateTextRequest(BaseModel):
2232

2333
model_config = ConfigDict(
2434
alias_generator=to_camel,
25-
populate_by_name=True # Allows both snake_case and camelCase input
35+
populate_by_name=True, # Allows both snake_case and camelCase input
2636
)
2737

28-
version: Literal["v1"] = Field(default="v1", description="API version, must be 'v1'")
38+
version: Literal["v1"] = Field(
39+
default="v1", description="API version, must be 'v1'"
40+
)
2941
model_name: str = Field(..., min_length=1, description="Name of the model to use")
3042
prompt: str = Field(..., min_length=1, max_length=1000, description="Input prompt")
31-
localization: Optional[Dict[str, Any]] = Field(default=None, description="Localization settings")
43+
localization: Optional[Dict[str, Any]] = Field(
44+
default=None, description="Localization settings"
45+
)
3246
tags: Optional[Dict[str, Any]] = Field(default=None, description="Additional tags")

src/datacustomcode/llm_gateway/types/generate_text_request_builder.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,21 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16+
from typing import (
17+
Any,
18+
Dict,
19+
Optional,
20+
)
21+
1622
from datacustomcode.llm_gateway.types.generate_text_request import GenerateTextRequest
1723

1824

1925
class GenerateTextRequestBuilder:
2026
def __init__(self):
2127
self._prompt = ""
2228
self._model_name = ""
23-
self._localization = None
24-
self._tags = None
29+
self._localization: Optional[Dict[str, Any]] = None
30+
self._tags: Optional[Dict[str, Any]] = None
2531

2632
def set_prompt(self, prompt: str):
2733
self._prompt = prompt
@@ -31,7 +37,11 @@ def set_model(self, model_name: str):
3137
self._model_name = model_name
3238
return self
3339

34-
def set_localization(self, localization: dict = None, locale: str = None):
40+
def set_localization(
41+
self,
42+
localization: Optional[Dict[str, Any]] = None,
43+
locale: Optional[str] = None,
44+
):
3545
"""
3646
Set localization either from a dict or a simple locale string.
3747
@@ -52,7 +62,7 @@ def set_localization(self, localization: dict = None, locale: str = None):
5262

5363
return self
5464

55-
def set_tags(self, tags: dict):
65+
def set_tags(self, tags: Dict[str, Any]):
5666
self._tags = tags
5767
return self
5868

@@ -62,7 +72,7 @@ def build(self) -> GenerateTextRequest:
6272
prompt=self._prompt,
6373
model_name=self._model_name,
6474
localization=self._localization,
65-
tags=self._tags
75+
tags=self._tags,
6676
)
6777

6878
return request

src/datacustomcode/llm_gateway/types/generate_text_response.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
from typing import Optional, Dict, Any
16+
from typing import (
17+
Any,
18+
Dict,
19+
Optional,
20+
)
1721

1822
from pydantic import BaseModel, Field
1923

24+
2025
class GenerateTextResponse(BaseModel):
2126
"""Response from LLM text generation"""
2227

@@ -38,12 +43,16 @@ def is_error(self) -> bool:
3843
def text(self) -> str:
3944
"""Generated text (convenience property)."""
4045
if self.is_success and self.data:
41-
return self.data.get('generation', {}).get('generatedText', '')
42-
return ''
46+
generation = self.data.get("generation", {})
47+
if isinstance(generation, dict):
48+
text = generation.get("generatedText", "")
49+
return str(text) if text else ""
50+
return ""
4351

4452
@property
4553
def error_code(self) -> str:
4654
"""Generated text (convenience property)."""
4755
if self.is_error and self.data:
48-
return self.data.get('errorCode', self.status_code)
49-
return ''
56+
error_code = self.data.get("errorCode", str(self.status_code))
57+
return str(error_code)
58+
return ""

src/datacustomcode/llm_gateway/types/generate_text_response_builder.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
from typing import Dict, Any
16+
from typing import Any, Dict
17+
1718
from datacustomcode.llm_gateway.types.generate_text_response import GenerateTextResponse
1819

1920

2021
class GenerateTextResponseBuilder:
2122
def __init__(self):
22-
self._version = "v1" # Hardcoded default for your SDK
23+
self._version = "v1" # Hardcoded default for your SDK
2324
self._status_code = None
2425
self._data = None
2526

@@ -33,4 +34,4 @@ def set_data(self, data: dict):
3334

3435
@staticmethod
3536
def build(response_dict: Dict[str, Any]) -> GenerateTextResponse:
36-
return GenerateTextResponse.model_validate(response_dict)
37+
return GenerateTextResponse.model_validate(response_dict)

src/datacustomcode/proxy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
# distributed under the License is distributed on an "AS IS" BASIS,
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
14-
# limitations under the License.
14+
# limitations under the License.

src/datacustomcode/proxy/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@
2121

2222
class BaseProxyAccessLayer(ABC, UserExtendableNamedConfigMixin):
2323
def __init__(self):
24-
pass
24+
pass

src/datacustomcode/proxy/client/LocalProxyClientProvider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ def call_llm_gateway(self, llmModelId: str, prompt: str, maxTokens: int) -> str:
3131
def llm_gateway_generate_text(
3232
self, template, values, llmModelId: str, maxTokens: int
3333
):
34-
return f"Using Generate Text with {llmModelId} and maxTokens: {maxTokens}"
34+
return f"Using Generate Text with {llmModelId} and maxTokens: {maxTokens}"

src/datacustomcode/proxy/client/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@
1111
# distributed under the License is distributed on an "AS IS" BASIS,
1212
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
# See the License for the specific language governing permissions and
14-
# limitations under the License.
14+
# limitations under the License.

0 commit comments

Comments
 (0)