mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-25 05:54:53 +00:00
feat(greenpt): add flagship and rerank support
This commit is contained in:
parent
f9dec7e45d
commit
2d2124cfce
8 changed files with 109 additions and 2 deletions
1
litellm/llms/greenpt/__init__.py
Normal file
1
litellm/llms/greenpt/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
1
litellm/llms/greenpt/rerank/__init__.py
Normal file
1
litellm/llms/greenpt/rerank/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
|
||||
42
litellm/llms/greenpt/rerank/transformation.py
Normal file
42
litellm/llms/greenpt/rerank/transformation.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
from typing import Dict
|
||||
|
||||
from litellm.llms.hosted_vllm.rerank.transformation import HostedVLLMRerankConfig
|
||||
from litellm.secret_managers.main import get_secret_str
|
||||
|
||||
|
||||
class GreenPTRerankConfig(HostedVLLMRerankConfig):
|
||||
def get_supported_cohere_rerank_params(self, model: str) -> list:
|
||||
return ["query", "documents", "top_n", "return_documents"]
|
||||
|
||||
def validate_environment(
|
||||
self,
|
||||
headers: dict,
|
||||
model: str,
|
||||
api_key: str | None = None,
|
||||
optional_params: dict | None = None,
|
||||
) -> dict:
|
||||
api_key = api_key or get_secret_str("GREENPT_API_KEY")
|
||||
if api_key is None:
|
||||
raise ValueError("GreenPT API key is required. Set GREENPT_API_KEY.")
|
||||
return super().validate_environment(
|
||||
headers=headers,
|
||||
model=model,
|
||||
api_key=api_key,
|
||||
optional_params=optional_params,
|
||||
)
|
||||
|
||||
def transform_rerank_request(
|
||||
self,
|
||||
model: str,
|
||||
optional_rerank_params: Dict,
|
||||
headers: dict,
|
||||
litellm_params: dict | None = None,
|
||||
) -> dict:
|
||||
request = super().transform_rerank_request(
|
||||
model=model,
|
||||
optional_rerank_params=optional_rerank_params,
|
||||
headers=headers,
|
||||
litellm_params=litellm_params,
|
||||
)
|
||||
request.setdefault("top_n", len(request["documents"]))
|
||||
return request
|
||||
|
|
@ -31,7 +31,7 @@ async def arerank(
|
|||
query: str,
|
||||
documents: List[Union[str, Dict[str, Any]]],
|
||||
custom_llm_provider: (
|
||||
Literal["cohere", "together_ai", "deepinfra", "fireworks_ai", "voyage", "watsonx"] | None
|
||||
Literal["cohere", "together_ai", "deepinfra", "fireworks_ai", "voyage", "watsonx", "greenpt"] | None
|
||||
) = None,
|
||||
top_n: int | None = None,
|
||||
rank_fields: List[str] | None = None,
|
||||
|
|
@ -89,6 +89,7 @@ def rerank(
|
|||
"fireworks_ai",
|
||||
"voyage",
|
||||
"watsonx",
|
||||
"greenpt",
|
||||
]
|
||||
| None
|
||||
) = None,
|
||||
|
|
|
|||
|
|
@ -8008,6 +8008,10 @@ class ProviderConfigManager:
|
|||
)
|
||||
|
||||
return DashScopeRerankConfig()
|
||||
elif litellm.LlmProviders.GREENPT == provider:
|
||||
from litellm.llms.greenpt.rerank.transformation import GreenPTRerankConfig
|
||||
|
||||
return GreenPTRerankConfig()
|
||||
return litellm.CohereRerankConfig()
|
||||
|
||||
@staticmethod
|
||||
|
|
|
|||
|
|
@ -46295,6 +46295,14 @@
|
|||
"output_cost_per_token": 0,
|
||||
"source": "https://docs.greenpt.ai/pricing"
|
||||
},
|
||||
"greenpt/green-rerank": {
|
||||
"input_cost_per_token": 1.36524e-07,
|
||||
"litellm_provider": "greenpt",
|
||||
"max_input_tokens": 32768,
|
||||
"max_tokens": 32768,
|
||||
"mode": "rerank",
|
||||
"source": "https://docs.greenpt.ai/pricing"
|
||||
},
|
||||
"greenpt/green-l": {
|
||||
"input_cost_per_token": 2.84425e-07,
|
||||
"litellm_provider": "greenpt",
|
||||
|
|
@ -46370,6 +46378,19 @@
|
|||
"supports_tool_choice": true,
|
||||
"supports_vision": true
|
||||
},
|
||||
"greenpt/kimi-k2.7-code": {
|
||||
"input_cost_per_token": 9.44291e-07,
|
||||
"litellm_provider": "greenpt",
|
||||
"max_input_tokens": 262144,
|
||||
"max_output_tokens": 262144,
|
||||
"max_tokens": 262144,
|
||||
"mode": "chat",
|
||||
"output_cost_per_token": 4.380145e-06,
|
||||
"source": "https://docs.greenpt.ai/pricing",
|
||||
"supports_function_calling": true,
|
||||
"supports_reasoning": true,
|
||||
"supports_tool_choice": true
|
||||
},
|
||||
"greenpt/minimax-m2.5": {
|
||||
"input_cost_per_token": 1.93409e-07,
|
||||
"litellm_provider": "greenpt",
|
||||
|
|
@ -46383,6 +46404,16 @@
|
|||
"supports_reasoning": true,
|
||||
"supports_tool_choice": true
|
||||
},
|
||||
"greenpt/qwen3-embedding-8b": {
|
||||
"input_cost_per_token": 2.84425e-07,
|
||||
"litellm_provider": "greenpt",
|
||||
"max_input_tokens": 32768,
|
||||
"max_output_tokens": 4096,
|
||||
"max_tokens": 32768,
|
||||
"mode": "embedding",
|
||||
"output_cost_per_token": 0,
|
||||
"source": "https://docs.greenpt.ai/pricing"
|
||||
},
|
||||
"fallback_generalizations": {
|
||||
"rules": [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2955,7 +2955,7 @@
|
|||
"audio_speech": false,
|
||||
"moderations": false,
|
||||
"batches": false,
|
||||
"rerank": false,
|
||||
"rerank": true,
|
||||
"a2a": false
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "../.
|
|||
|
||||
from litellm.llms.openai_like.dynamic_config import create_config_class
|
||||
from litellm.llms.openai_like.json_loader import JSONProviderRegistry
|
||||
from litellm.types.utils import LlmProviders
|
||||
from litellm.utils import ProviderConfigManager
|
||||
|
||||
GREENPT_BASE_URL = "https://api.greenpt.ai/v1"
|
||||
|
||||
|
|
@ -69,3 +71,28 @@ def test_greenpt_provider_resolution():
|
|||
assert model == "gemma4"
|
||||
assert provider == "greenpt"
|
||||
assert api_base == GREENPT_BASE_URL
|
||||
|
||||
|
||||
def test_greenpt_rerank_config():
|
||||
config = ProviderConfigManager.get_provider_rerank_config(
|
||||
model="green-rerank",
|
||||
provider=LlmProviders.GREENPT,
|
||||
api_base=GREENPT_BASE_URL,
|
||||
present_version_params=[],
|
||||
)
|
||||
assert config.get_complete_url(GREENPT_BASE_URL, "green-rerank") == (f"{GREENPT_BASE_URL}/rerank")
|
||||
assert config.transform_rerank_request(
|
||||
model="green-rerank",
|
||||
optional_rerank_params={
|
||||
"query": "low-carbon inference",
|
||||
"documents": ["GreenPT", "Other provider"],
|
||||
"return_documents": False,
|
||||
},
|
||||
headers={},
|
||||
) == {
|
||||
"model": "green-rerank",
|
||||
"query": "low-carbon inference",
|
||||
"documents": ["GreenPT", "Other provider"],
|
||||
"top_n": 2,
|
||||
"return_documents": False,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue