Ubuntu 20.04 使用 Deepbricks API中转平台

25 篇文章 0 订阅

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 httpx


API_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]
  • 8
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值