mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 11:43:54 +00:00
fix linting errors
This commit is contained in:
parent
b6f2dad052
commit
d3781dfe36
1 changed files with 35 additions and 44 deletions
|
@ -1,14 +1,14 @@
|
||||||
'''
|
"""
|
||||||
Support for Snowflake REST API
|
Support for Snowflake REST API
|
||||||
'''
|
"""
|
||||||
import httpx
|
|
||||||
from typing import List, Optional, Tuple, Any, TYPE_CHECKING
|
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING, Any, List, Optional, Tuple
|
||||||
|
|
||||||
|
import httpx
|
||||||
|
|
||||||
|
from litellm.secret_managers.main import get_secret_str
|
||||||
from litellm.types.llms.openai import AllMessageValues
|
from litellm.types.llms.openai import AllMessageValues
|
||||||
from litellm.utils import get_secret
|
|
||||||
from litellm.types.utils import ModelResponse
|
from litellm.types.utils import ModelResponse
|
||||||
from litellm.types.llms.openai import ChatCompletionAssistantMessage
|
|
||||||
from litellm.llms.databricks.streaming_utils import ModelResponseIterator
|
|
||||||
|
|
||||||
from ...openai_like.chat.transformation import OpenAIGPTConfig
|
from ...openai_like.chat.transformation import OpenAIGPTConfig
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ if TYPE_CHECKING:
|
||||||
else:
|
else:
|
||||||
LiteLLMLoggingObj = Any
|
LiteLLMLoggingObj = Any
|
||||||
|
|
||||||
|
|
||||||
class SnowflakeConfig(OpenAIGPTConfig):
|
class SnowflakeConfig(OpenAIGPTConfig):
|
||||||
"""
|
"""
|
||||||
source: https://docs.snowflake.com/en/sql-reference/functions/complete-snowflake-cortex
|
source: https://docs.snowflake.com/en/sql-reference/functions/complete-snowflake-cortex
|
||||||
|
@ -27,15 +28,10 @@ class SnowflakeConfig(OpenAIGPTConfig):
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_config(cls):
|
def get_config(cls):
|
||||||
return super().get_config()
|
return super().get_config()
|
||||||
|
|
||||||
def get_supported_openai_params(self, model: str) -> List:
|
def get_supported_openai_params(self, model: str) -> List:
|
||||||
return [
|
return ["temperature", "max_tokens", "top_p", "response_format"]
|
||||||
"temperature",
|
|
||||||
"max_tokens",
|
|
||||||
"top_p",
|
|
||||||
"response_format"
|
|
||||||
]
|
|
||||||
|
|
||||||
def map_openai_params(
|
def map_openai_params(
|
||||||
self,
|
self,
|
||||||
non_default_params: dict,
|
non_default_params: dict,
|
||||||
|
@ -60,8 +56,8 @@ class SnowflakeConfig(OpenAIGPTConfig):
|
||||||
optional_params[param] = value
|
optional_params[param] = value
|
||||||
return optional_params
|
return optional_params
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def transform_response(
|
def transform_response(
|
||||||
|
self,
|
||||||
model: str,
|
model: str,
|
||||||
raw_response: httpx.Response,
|
raw_response: httpx.Response,
|
||||||
model_response: ModelResponse,
|
model_response: ModelResponse,
|
||||||
|
@ -82,26 +78,22 @@ class SnowflakeConfig(OpenAIGPTConfig):
|
||||||
additional_args={"complete_input_dict": request_data},
|
additional_args={"complete_input_dict": request_data},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
returned_response = ModelResponse(**response_json)
|
returned_response = ModelResponse(**response_json)
|
||||||
|
|
||||||
returned_response.model = (
|
returned_response.model = "snowflake/" + (returned_response.model or "")
|
||||||
"snowflake/" + (returned_response.model or "")
|
|
||||||
)
|
|
||||||
|
|
||||||
if model is not None:
|
if model is not None:
|
||||||
returned_response._hidden_params["model"] = model
|
returned_response._hidden_params["model"] = model
|
||||||
return returned_response
|
return returned_response
|
||||||
|
|
||||||
|
|
||||||
def validate_environment(
|
def validate_environment(
|
||||||
self,
|
self,
|
||||||
headers: dict,
|
headers: dict,
|
||||||
model: str,
|
model: str,
|
||||||
api_base: str = None,
|
messages: List[AllMessageValues],
|
||||||
|
optional_params: dict,
|
||||||
api_key: Optional[str] = None,
|
api_key: Optional[str] = None,
|
||||||
messages: dict = None,
|
api_base: Optional[str] = None,
|
||||||
optional_params: dict = None,
|
|
||||||
) -> dict:
|
) -> dict:
|
||||||
"""
|
"""
|
||||||
Return headers to use for Snowflake completion request
|
Return headers to use for Snowflake completion request
|
||||||
|
@ -113,57 +105,56 @@ class SnowflakeConfig(OpenAIGPTConfig):
|
||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
"Authorization": "Bearer " + <JWT>,
|
"Authorization": "Bearer " + <JWT>,
|
||||||
"X-Snowflake-Authorization-Token-Type": "KEYPAIR_JWT"
|
"X-Snowflake-Authorization-Token-Type": "KEYPAIR_JWT"
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if api_key is None:
|
if api_key is None:
|
||||||
raise ValueError(
|
raise ValueError("Missing Snowflake JWT key")
|
||||||
"Missing Snowflake JWT key"
|
|
||||||
)
|
|
||||||
|
|
||||||
headers.update(
|
headers.update(
|
||||||
{
|
{
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
"Authorization": "Bearer " + api_key,
|
"Authorization": "Bearer " + api_key,
|
||||||
"X-Snowflake-Authorization-Token-Type": "KEYPAIR_JWT"
|
"X-Snowflake-Authorization-Token-Type": "KEYPAIR_JWT",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return headers
|
return headers
|
||||||
|
|
||||||
def _get_openai_compatible_provider_info(
|
def _get_openai_compatible_provider_info(
|
||||||
self, api_base: Optional[str], api_key: Optional[str]
|
self, api_base: Optional[str], api_key: Optional[str]
|
||||||
) -> Tuple[Optional[str], Optional[str]]:
|
) -> Tuple[Optional[str], Optional[str]]:
|
||||||
api_base = (
|
api_base = (
|
||||||
api_base
|
api_base
|
||||||
or f"""https://{get_secret("SNOWFLAKE_ACCOUNT_ID")}.snowflakecomputing.com/api/v2/cortex/inference:complete"""
|
or f"""https://{get_secret_str("SNOWFLAKE_ACCOUNT_ID")}.snowflakecomputing.com/api/v2/cortex/inference:complete"""
|
||||||
or get_secret("SNOWFLAKE_API_BASE")
|
or get_secret_str("SNOWFLAKE_API_BASE")
|
||||||
) # type: ignore
|
)
|
||||||
dynamic_api_key = api_key or get_secret("SNOWFLAKE_JWT")
|
dynamic_api_key = api_key or get_secret_str("SNOWFLAKE_JWT")
|
||||||
return api_base, dynamic_api_key
|
return api_base, dynamic_api_key
|
||||||
|
|
||||||
def get_complete_url(
|
def get_complete_url(
|
||||||
self,
|
self,
|
||||||
api_base: Optional[str],
|
api_base: Optional[str],
|
||||||
model: str,
|
model: str,
|
||||||
optional_params: dict,
|
optional_params: dict,
|
||||||
|
litellm_params: dict,
|
||||||
stream: Optional[bool] = None,
|
stream: Optional[bool] = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
"""
|
"""
|
||||||
If api_base is not provided, use the default DeepSeek /chat/completions endpoint.
|
If api_base is not provided, use the default DeepSeek /chat/completions endpoint.
|
||||||
"""
|
"""
|
||||||
if not api_base:
|
if not api_base:
|
||||||
api_base = f"""https://{get_secret("SNOWFLAKE_ACCOUNT_ID")}.snowflakecomputing.com/api/v2/cortex/inference:complete"""
|
api_base = f"""https://{get_secret_str("SNOWFLAKE_ACCOUNT_ID")}.snowflakecomputing.com/api/v2/cortex/inference:complete"""
|
||||||
|
|
||||||
return api_base
|
return api_base
|
||||||
|
|
||||||
def transform_request(
|
def transform_request(
|
||||||
self,
|
self,
|
||||||
model: str,
|
model: str,
|
||||||
messages: dict ,
|
messages: List[AllMessageValues],
|
||||||
optional_params: dict,
|
optional_params: dict,
|
||||||
litellm_params: dict,
|
litellm_params: dict,
|
||||||
headers: dict
|
headers: dict,
|
||||||
) -> dict:
|
) -> dict:
|
||||||
stream: bool = optional_params.pop("stream", None) or False
|
stream: bool = optional_params.pop("stream", None) or False
|
||||||
extra_body = optional_params.pop("extra_body", {})
|
extra_body = optional_params.pop("extra_body", {})
|
||||||
|
@ -173,4 +164,4 @@ class SnowflakeConfig(OpenAIGPTConfig):
|
||||||
"stream": stream,
|
"stream": stream,
|
||||||
**optional_params,
|
**optional_params,
|
||||||
**extra_body,
|
**extra_body,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue