Use 3.9 compat syntax (#164)

This commit is contained in:
Christian Byrne 2025-05-05 23:12:12 -07:00 committed by GitHub
parent a75d35e982
commit ec89560fad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 22 deletions

View File

@ -89,6 +89,7 @@ operation = PollingOperation(
result = operation.execute(client=api_client) # Returns the final ImageGenerationResult when done
"""
from __future__ import annotations
import logging
import time
import io
@ -196,7 +197,6 @@ class ApiClient:
"headers": headers,
}
def get_headers(self) -> Dict[str, str]:
"""Get headers for API requests, including authentication if available"""
headers = {"Content-Type": "application/json", "Accept": "application/json"}
@ -251,13 +251,14 @@ class ApiClient:
logging.debug(f"[DEBUG] Params: {params}")
logging.debug(f"[DEBUG] Data: {data}")
match content_type:
case "application/x-www-form-urlencoded":
payload_args = self._create_urlencoded_form_data_args(data, request_headers)
case "multipart/form-data":
payload_args = self._create_form_data_args(data, files, request_headers, multipart_parser)
case _:
payload_args = self._create_json_payload_args(data, request_headers)
if content_type == "application/x-www-form-urlencoded":
payload_args = self._create_urlencoded_form_data_args(data, request_headers)
elif content_type == "multipart/form-data":
payload_args = self._create_form_data_args(
data, files, request_headers, multipart_parser
)
else:
payload_args = self._create_json_payload_args(data, request_headers)
try:
response = requests.request(

View File

@ -99,19 +99,18 @@ def model_field_to_node_input(
field_info: FieldInfo = base_model.model_fields[field_name]
result: NodeInput
match input_type:
case IO.IMAGE:
result = _model_field_to_image_input(field_info, **kwargs)
case IO.STRING:
result = _model_field_to_string_input(field_info, **kwargs)
case IO.FLOAT:
result = _model_field_to_float_input(field_info, **kwargs)
case IO.INT:
result = _model_field_to_int_input(field_info, **kwargs)
case IO.COMBO:
result = _model_field_to_combo_input(field_info, **kwargs)
case _:
message = f"Invalid input type: {input_type}"
raise ValueError(message)
if input_type == IO.IMAGE:
result = _model_field_to_image_input(field_info, **kwargs)
elif input_type == IO.STRING:
result = _model_field_to_string_input(field_info, **kwargs)
elif input_type == IO.FLOAT:
result = _model_field_to_float_input(field_info, **kwargs)
elif input_type == IO.INT:
result = _model_field_to_int_input(field_info, **kwargs)
elif input_type == IO.COMBO:
result = _model_field_to_combo_input(field_info, **kwargs)
else:
message = f"Invalid input type: {input_type}"
raise ValueError(message)
return result

View File

@ -4,6 +4,7 @@ For source of truth on the allowed permutations of request fields, please refere
- [Compatibility Table](https://app.klingai.com/global/dev/document-api/apiReference/model/skillsMap)
"""
from __future__ import annotations
from typing import Optional, TypeVar, Any
import math
import logging