【原创】AI聚合平台+AI聚合API+算力平台梳理(超实用)

【原创】AI聚合平台+AI聚合API+算力平台梳理(超实用)

如果需要AI重复发挥效果,模型能力至关重要,目前国外内大家认可的优质的大模型包括 Claude、GPT、Grok、Gemini 等等,国内的包括 Deepseek、Qwen、Doubao 等等。

国内的AI大模型基本有对应网页版+APP版本,个别还有桌面版,但是受限于网络环境和国外的限制,需要访问海外的优质大模型都困难重重,所以经过调研梳理,能够有效方便访问海外的大模型的桌面工具、聚合API,以及个别场景需要进行一些算力租赁场景,梳理了国内外的产品,减少了二次调研时间,可以直接使用。

注意:以下内容非广告,纯个人体验,个人喜好,仅供参考。

(梳理截止时间:2025年3月14日)

【AI聚合工具】POE - 国外模型整合访问(https://poe.com,支持信用卡)

【AI聚合工具】Monica - 国内外主流AI模型整合,方便易用(https://monica.im, 支持信用卡和支付宝)

【AI聚合API】OpenRouter - 海外各大模型访问聚合API(https://openrouter.ai, 支持信用卡、野卡)

实际测试代码:

import aiohttp

import json

import asyncio

from typing import Optional, Dict, Any, AsyncGenerator

# API配置

API_URL = "https://openrouter.ai/api/v1/chat/completions"

API_KEY = "sk-or-v1-YOU-SK"

# 默认超时时间(秒)

DEFAULT_TIMEOUT = 120 # 增加到120秒

# 支持文本和图片的多模态模型

MULTIMODAL_MODELS = [

"anthropic/claude-3.7-sonnet",

"anthropic/claude-3.5-sonnet",

"openai/gpt-4.5-preview",

"openai/gpt-4o-2024-11-20",

"openai/o1",

"google/gemini-2.0-flash-001",

"google/gemma-3-27b-it",

"qwen/qwen-vl-max",

"qwen/qwen-vl-plus"

]

# 仅支持纯文本的模型

TEXT_ONLY_MODELS = [

"deepseek/deepseek-chat",

"deepseek/deepseek-r1",

"qwen/qwq-32b",

"qwen/qwen2.5-32b-instruct",

"mistralai/mistral-saba"

]

def supports_text(model: str) -> bool:

"""检查模型是否支持文本"""

return model in TEXT_ONLY_MODELS or model in MULTIMODAL_MODELS

def supports_image(model: str) -> bool:

"""检查模型是否支持图片"""

return model in MULTIMODAL_MODELS

async def chat_text(model: str, message: str, timeout: int = DEFAULT_TIMEOUT) -> str:

"""

纯文本对话函数

Args:

model: 模型名称

message: 用户消息

timeout: 超时时间(秒)

Returns:

模型的回复文本

"""

if not supports_text(model):

raise ValueError(f"模型 '{model}' 不支持文本对话")

headers = {

"Content-Type": "application/json",

"Authorization": f"Bearer {API_KEY}"

}

data = {

"model": model,

"messages": [{"role": "user", "content": message}]

}

try:

print(f"正在调用模型 {model},请耐心等待...")

async with aiohttp.ClientSession() as session:

async with session.post(

API_URL,

headers=headers,

json=data,

timeout=timeout

) as response:

if response.status != 200:

error_text = await response.text()

print(f"API错误状态码: {response.status}")

raise ValueError(f"API调用失败: {error_text}")

result = await response.json()

if not result.get("choices"):

print(f"API响应: {result}")

raise ValueError(f"API响应格式错误: {result}")

return result["choices"][0]["message"]["content"]

except aiohttp.ClientError as e:

raise ValueError(f"网络请求失败: {str(e)}")

except asyncio.TimeoutError:

raise ValueError(f"请求超时,请增加超时时间或稍后重试")

except Exception as e:

raise ValueError(f"请求失败: {str(e)}")

async def chat_text_stream(model: str, message: str, timeout: int = DEFAULT_TIMEOUT) -> AsyncGenerator[str, None]:

"""

流式文本对话函数

Args:

model: 模型名称

message: 用户消息

timeout: 超时时间(秒)

Yields:

模型响应的文本片段

"""

if not supports_text(model):

raise ValueError(f"模型 '{model}' 不支持文本对话")

headers = {

"Content-Type": "application/json",

"Authorization": f"Bearer {API_KEY}"

}

data = {

"model": model,

"messages": [{"role": "user", "content": message}],

"stream": True

}

try:

print(f"正在流式调用模型 {model},请耐心等待...")

async with aiohttp.ClientSession() as session:

async with session.post(

API_URL,

headers=headers,

json=data,

timeout=timeout

) as response:

if response.status != 200:

error_text = await response.text()

print(f"API错误状态码: {response.status}")

raise ValueError(f"API调用失败: {error_text}")

async for line in response.content:

line = line.decode('utf-8').strip()

if line.startswith('data: '):

if line == 'data: [DONE]':

break

try:

data = json.loads(line[6:])

if content := data.get('choices', [{}])[0].get('delta', {}).get('content'):

yield content

except json.JSONDecodeError:

continue

except aiohttp.ClientError as e:

raise ValueError(f"网络请求失败: {str(e)}")

except asyncio.TimeoutError:

raise ValueError(f"请求超时,请增加超时时间或稍后重试")

except Exception as e:

raise ValueError(f"请求失败: {str(e)}")

async def chat_image(model: str, message: str, image_url: str, timeout: int = DEFAULT_TIMEOUT) -> str:

"""

图文对话函数

Args:

model: 模型名称

message: 用户消息

image_url: 图片URL

timeout: 超时时间(秒)

Returns:

模型的回复文本

"""

if not supports_image(model):

raise ValueError(f"模型 '{model}' 不支持图片处理")

headers = {

"Content-Type": "application/json",

"Authorization": f"Bearer {API_KEY}"

}

content = [

{"type": "text", "text": message},

{"type": "image_url", "image_url": {"url": image_url}}

]

data = {

"model": model,

"messages": [{"role": "user", "content": content}]

}

try:

print(f"正在调用图像模型 {model},请耐心等待...")

async with aiohttp.ClientSession() as session:

async with session.post(

API_URL,

headers=headers,

json=data,

timeout=timeout

) as response:

if response.status != 200:

error_text = await response.text()

print(f"API错误状态码: {response.status}")

raise ValueError(f"API调用失败: {error_text}")

result = await response.json()

if not result.get("choices"):

print(f"API响应: {result}")

raise ValueError(f"API响应格式错误: {result}")

return result["choices"][0]["message"]["content"]

except aiohttp.ClientError as e:

raise ValueError(f"网络请求失败: {str(e)}")

except asyncio.TimeoutError:

raise ValueError(f"请求超时,请增加超时时间或稍后重试")

except Exception as e:

raise ValueError(f"请求失败: {str(e)}")

async def chat_image_stream(model: str, message: str, image_url: str, timeout: int = DEFAULT_TIMEOUT) -> AsyncGenerator[str, None]:

"""

流式图文对话函数

Args:

model: 模型名称

message: 用户消息

image_url: 图片URL

timeout: 超时时间(秒)

Yields:

模型响应的文本片段

"""

if not supports_image(model):

raise ValueError(f"模型 '{model}' 不支持图片处理")

headers = {

"Content-Type": "application/json",

"Authorization": f"Bearer {API_KEY}"

}

content = [

{"type": "text", "text": message},

{"type": "image_url", "image_url": {"url": image_url}}

]

data = {

"model": model,

"messages": [{"role": "user", "content": content}],

"stream": True

}

try:

print(f"正在流式调用图像模型 {model},请耐心等待...")

async with aiohttp.ClientSession() as session:

async with session.post(

API_URL,

headers=headers,

json=data,

timeout=timeout

) as response:

if response.status != 200:

error_text = await response.text()

print(f"API错误状态码: {response.status}")

raise ValueError(f"API调用失败: {error_text}")

async for line in response.content:

line = line.decode('utf-8').strip()

if line.startswith('data: '):

if line == 'data: [DONE]':

break

try:

data = json.loads(line[6:])

if content := data.get('choices', [{}])[0].get('delta', {}).get('content'):

yield content

except json.JSONDecodeError:

continue

except aiohttp.ClientError as e:

raise ValueError(f"网络请求失败: {str(e)}")

except asyncio.TimeoutError:

raise ValueError(f"请求超时,请增加超时时间或稍后重试")

except Exception as e:

raise ValueError(f"请求失败: {str(e)}")

# 使用示例

async def main():

# 测试图片URL

test_image_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png"

print("\n1. 测试纯文本对话")

try:

print("开始测试纯文本对话,这可能需要一些时间...")

response = await chat_text(

model="deepseek/deepseek-chat", # 使用更稳定的模型

message="你是谁?"

)

print("回复:", response)

except ValueError as e:

print("错误:", str(e))

print("\n2. 测试流式文本对话")

try:

print("开始测试流式文本对话,这可能需要一些时间...")

print("回复: ", end='', flush=True)

async for chunk in chat_text_stream(

model="deepseek/deepseek-chat", # 使用更稳定的模型

message="你是谁?"

):

print(chunk, end='', flush=True)

print()

except ValueError as e:

print("错误:", str(e))

print("\n3. 测试图文对话")

try:

print("开始测试图文对话,这可能需要一些时间...")

response = await chat_image(

model="anthropic/claude-3.5-sonnet", # 使用更稳定的模型

message="这个图中是什么?",

image_url=test_image_url

)

print("回复:", response)

except ValueError as e:

print("错误:", str(e))

print("\n4. 测试流式图文对话")

try:

print("开始测试流式图文对话,这可能需要一些时间...")

print("回复: ", end='', flush=True)

async for chunk in chat_image_stream(

model="anthropic/claude-3.5-sonnet", # 使用更稳定的模型

message="这个图中是什么?",

image_url=test_image_url

):

print(chunk, end='', flush=True)

print()

except ValueError as e:

print("错误:", str(e))

if __name__ == "__main__":

asyncio.run(main())

输出结果:

【AI聚合API】其他API

GPT-Router:https://gpt-router.writesonic.com

Neutrino AI:https://www.neutrinoapp.com

【算力租赁】Modal - 国外算力租赁平台,支持直接远程访问生成应用(https://modal.com,支持信用卡)

【算力租赁】AutoDL - 支持从RTX到A800等各类AI卡(https://www.autodl.com,支持国内各种支付方式)

【算力租赁】openbayes - 简单便宜可以支持各操作系统算力平台(https://openbayes.com,支持国内各支付方式)

【大模型介绍电子书】

快速揭秘DeepSeek背后的AI工作原理

要获取本书全文PDF内容,请Follow“黑夜路人技术” VX,然后在VX后台留言:“AI大模型基础” 或者 “大模型基础” 就会获得电子书的PDF。

相关文章

微视移动办公软件怎么用

beat365手机版官方网站正规 09-23

买的股票分红了在哪看?

365bet在线网址 10-10

《王者荣耀》惩戒技能详解及炙热惩击与寒冰惩戒对比

365bet在线网址 10-17

如何在快手给视频添加封面图片

365bet在线网址 09-17