1. Deepbricks 中转平台
Deepbricks 可以使用支付宝付款
获取 API keys
API keys
在 ~/.bashrc 中写入
export API_KEY=sk-xxxxx
然后查看
$ echo $API_KEY
sk-xxxxx
2. Usage examples(curl)
使用文档
检查代理服务器是否启动
$ curl -x socks5h://127.0.0.1:1080 https://www.google.com
然后
$ curl -x socks5h://127.0.0.1:1080 -X POST https://api.deepbricks.ai/v1/chat/completions \-H "Content-Type: application/json" \-H "Authorization: Bearer $API_KEY" \-d '{"model": "GPT-4o-mini","messages": [{"role": "user","content": "Hello!"}]}'
返回
{"id":"chatcmpl-vEoevOEoKRW7CrBSm5QBv0U6HijtJmK0","object":"chat.completion","created":1725418263,"model":"gpt-4o-mini","system_fingerprint":"fp_f33667828e","choices":[{"index":0,"finish_reason":"stop","message":{"content":"Hello! How can I assist you today?","role":"assistant"},"logprobs":null}],"usage":{"prompt_tokens":9,"completion_tokens":9,"total_tokens":18}}
3. Usage examples(Use openai official package)
test_bricks.py
from openai import OpenAI
import os
import httpxAPI_KEY = os.getenv("API_KEY")
BASE_URL = "https://api.deepbricks.ai/v1/"# 设置代理服务器
proxy_url = 'socks5://127.0.0.1:1080'
# 创建一个 HTTPX 客户端并配置代理
proxy_client = httpx.Client(proxies={"http://": proxy_url,"https://": proxy_url,
})client = OpenAI(api_key=API_KEY, base_url=BASE_URL,http_client=proxy_client)
completion = client.chat.completions.create(model="GPT-4o-mini",messages=[{"role": "user","content": "You are a scientist, help me explain the binaural effect in concise language"}]
)
print(completion.choices[0].message)
返回
ChatCompletionMessage
(content='The binaural effect refers to the perception of sound localization and depth created when two ears receive slightly different audio signals. When a sound originates from one side, the ear nearest to the source hears it slightly earlier and with a different intensity compared to the far ear. This difference, known as interaural time difference (ITD) and interaural level difference (ILD), helps the brain accurately identify the direction and distance of the sound. The binaural effect is crucial for spatial awareness in our auditory experience, enhancing how we perceive our environment.',
refusal=None,
role='assistant',
function_call=None,
tool_calls=None)
期间报错:
ImportError: Using SOCKS proxy, but the 'socksio' package is not installed. Make sure to install httpx using `pip install httpx[socks]`.
解决方法参考:
使用 requests 库和 SOCKS 代理时遇到的 ImportError 异常及其解决方法
pip install httpx[socks]