|
@@ -34,9 +34,10 @@ OPENAI_API_TOKEN = 'sk-proj-6LsybsZSinbMIUzqttDt8LxmNbi-i6lEq-AUMzBhCr3jS8sme9AG
|
|
|
OPENAI_BASE_URL = 'https://api.openai.com/v1'
|
|
|
OPENAI_MODEL_GPT_4o = 'gpt-4o'
|
|
|
OPENAI_MODEL_GPT_4o_mini = 'gpt-4o-mini'
|
|
|
-OPENROUTER_API_TOKEN = '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'
|
|
|
+OPENROUTER_API_TOKEN = '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'
|
|
|
OPENROUTER_BASE_URL = 'https://openrouter.ai/api/v1/'
|
|
|
OPENROUTER_MODEL_CLAUDE_3_7_SONNET = 'anthropic/claude-3.7-sonnet'
|
|
|
+OPENROUTER_MODEL_GEMINI_2_5_PRO = 'google/gemini-2.5-pro'
|
|
|
ALIYUN_API_TOKEN = 'sk-47381479425f4485af7673d3d2fd92b6'
|
|
|
ALIYUN_BASE_URL = 'https://dashscope.aliyuncs.com/compatible-mode/v1'
|
|
|
|
|
@@ -73,6 +74,11 @@ class ModelPrice:
|
|
|
total_cost *= conversion_rate
|
|
|
return total_cost
|
|
|
|
|
|
+ def get_cny_brief(self) -> str:
|
|
|
+ input_price = self.input_price * self.EXCHANGE_RATE_TO_CNY.get(self.currency, 1.0)
|
|
|
+ output_price = self.output_price * self.EXCHANGE_RATE_TO_CNY.get(self.currency, 1.0)
|
|
|
+ return f"{input_price:.0f}/{output_price:.0f}"
|
|
|
+
|
|
|
def __repr__(self):
|
|
|
return f"ModelPrice(input_price={self.input_price}, output_price={self.output_price}, currency={self.currency})"
|
|
|
|
|
@@ -92,6 +98,7 @@ class OpenAICompatible:
|
|
|
]
|
|
|
openrouter_models = [
|
|
|
OPENROUTER_MODEL_CLAUDE_3_7_SONNET,
|
|
|
+ OPENROUTER_MODEL_GEMINI_2_5_PRO
|
|
|
]
|
|
|
|
|
|
model_prices = {
|
|
@@ -103,6 +110,7 @@ class OpenAICompatible:
|
|
|
OPENAI_MODEL_GPT_4o: ModelPrice(input_price=2.5, output_price=10, currency='USD'),
|
|
|
OPENAI_MODEL_GPT_4o_mini: ModelPrice(input_price=0.15, output_price=0.6, currency='USD'),
|
|
|
OPENROUTER_MODEL_CLAUDE_3_7_SONNET: ModelPrice(input_price=3, output_price=15, currency='USD'),
|
|
|
+ OPENROUTER_MODEL_GEMINI_2_5_PRO: ModelPrice(input_price=1.25, output_price=10, currency='USD'),
|
|
|
}
|
|
|
|
|
|
@staticmethod
|
|
@@ -112,20 +120,31 @@ class OpenAICompatible:
|
|
|
elif model_name in OpenAICompatible.deepseek_models:
|
|
|
llm_client = OpenAI(api_key=DEEPSEEK_API_TOKEN, base_url=DEEPSEEK_BASE_URL, **kwargs)
|
|
|
elif model_name in OpenAICompatible.openai_models:
|
|
|
- socks_conf = configs.get().get('system', {}).get('outside_proxy', {}).get('socks5', {})
|
|
|
- if socks_conf:
|
|
|
- http_client = httpx.Client(
|
|
|
- timeout=httpx.Timeout(600, connect=5.0),
|
|
|
- proxy=f"socks5://{socks_conf['hostname']}:{socks_conf['port']}"
|
|
|
- )
|
|
|
- kwargs['http_client'] = http_client
|
|
|
+ kwargs['http_client'] = OpenAICompatible.create_outside_proxy_http_client()
|
|
|
llm_client = OpenAI(api_key=OPENAI_API_TOKEN, base_url=OPENAI_BASE_URL, **kwargs)
|
|
|
elif model_name in OpenAICompatible.openrouter_models:
|
|
|
+ # kwargs['http_client'] = OpenAICompatible.create_outside_proxy_http_client()
|
|
|
llm_client = OpenAI(api_key=OPENROUTER_API_TOKEN, base_url=OPENROUTER_BASE_URL, **kwargs)
|
|
|
else:
|
|
|
raise Exception("Unsupported model: %s" % model_name)
|
|
|
return llm_client
|
|
|
|
|
|
+ @staticmethod
|
|
|
+ def create_outside_proxy_http_client() -> httpx.Client:
|
|
|
+ """
|
|
|
+ Create an HTTP client with outside proxy settings.
|
|
|
+ :return: Configured httpx.Client instance
|
|
|
+ """
|
|
|
+ socks_conf = configs.get().get('system', {}).get('outside_proxy', {}).get('socks5', {})
|
|
|
+ if socks_conf:
|
|
|
+ return httpx.Client(
|
|
|
+ timeout=httpx.Timeout(600, connect=5.0),
|
|
|
+ proxy=f"socks5://{socks_conf['hostname']}:{socks_conf['port']}"
|
|
|
+ )
|
|
|
+ # If no proxy is configured, return a standard client
|
|
|
+ logger.error("Outside proxy not configured, using default httpx client.")
|
|
|
+ return httpx.Client(timeout=httpx.Timeout(600, connect=5.0))
|
|
|
+
|
|
|
@staticmethod
|
|
|
def get_price(model_name: str) -> ModelPrice:
|
|
|
"""
|