欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 时评 > Ubuntu 20.04 使用 Deepbricks API中转平台

Ubuntu 20.04 使用 Deepbricks API中转平台

2024/10/24 20:18:54 来源:https://blog.csdn.net/weixin_40378209/article/details/141886950  浏览:    关键词:Ubuntu 20.04 使用 Deepbricks API中转平台

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]

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com