File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed
Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,29 @@ curl -v http://127.0.0.1:8080/v1/chat/completions \
6464 }'
6565```
6666
67+ 也可以使用 OpenAI 官方 SDK 进行调用,或者任意兼容 OpenAI 的开源软件进行使用(更多例子,参考 [ example] ( ./example/ ) ):
68+
69+ ``` python
70+ from openai import OpenAI
71+
72+ client = OpenAI(
73+ api_key = " your-key-or-input-something-as-you-like" ,
74+ base_url = " http://127.0.0.1:8080/v1"
75+ )
76+
77+ chat_completion = client.chat.completions.create(
78+ messages = [
79+ {
80+ " role" : " user" ,
81+ " content" : " Say this is a test" ,
82+ }
83+ ],
84+ model = " gpt-3.5-turbo" ,
85+ )
86+
87+ print (chat_completion)
88+ ```
89+
6790你如果你希望不要将 API Key 暴露给应用,或者不放心各种复杂的开源软件是否有 API Key 泄漏风险,我们可以多配置一个 ` AZURE_API_KEY=你的 API Key ` 环境变量,然后各种开源软件在请求的时候就无需再填写 API key 了(或者随便填写也行)。
6891
6992当然,因为 Azure 的一些限制,以及一些开源软件中的模型调用名称不好调整,我们可以通过下面的方式,来将原始请求中的模型,映射为我们真实的模型名称。比如,将 GPT 3.5/4 都替换为 ` yi-34b-chat ` :
You can’t perform that action at this time.
0 commit comments