LLM API 对接
申请API Key
1、开通账号
进入官网 企业服务 ,开通企业账号。
2、联系商务或者技术支持申请 API Key
请求示例
curl https://gate.wujieai.net/wj-open/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <API Key>" \
-d '{
"model": "deepseek-ai/DeepSeek-R1",
"messages": [
{"role": "user", "content": "Hello"}
],
"stream": true
}'
import okhttp3.*;
import okio.BufferedSource;
import org.json.JSONObject;
import java.io.IOException;
public class ChatStreamExample {
private static final String API_URL = "https://gate.wujieai.net/wj-open/v1/chat/completions";
// 替换为你的API Key
private static final String API_KEY = "<API Key>";
public static void main(String[] args) {
OkHttpClient client = new OkHttpClient();
// 构建请求体
JSONObject requestBody = new JSONObject();
requestBody.put("model", "deepseek-ai/DeepSeek-R1");
requestBody.put("stream", true);
requestBody.put("messages", new JSONObject[]{
new JSONObject().put("role", "user").put("content", "Hello")
});
Request request = new Request.Builder()
.url(API_URL)
.post(RequestBody.create(
requestBody.toString(),
MediaType.parse("application/json")))
.addHeader("Authorization", "Bearer " + API_KEY)
.build();
try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) {
System.err.println("请求失败: " + response.code());
return;
}
// 处理流式响应
BufferedSource source = response.body().source();
while (!source.exhausted()) {
String line = source.readUtf8Line();
if (line != null && !line.isEmpty()) {
processResponseLine(line);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
private static void processResponseLine(String line) {
try {
JSONObject json = new JSONObject(line);
JSONObject choice = json.getJSONArray("choices").getJSONObject(0);
String content = choice.getJSONObject("delta").optString("content", "");
if (!content.isEmpty()) {
System.out.print(content);
}
// 检查是否结束
if (!choice.getString("finish_reason").isEmpty()) {
System.out.println("\n\n[对话结束]");
}
} catch (Exception e) {
System.err.println("解析错误: " + e.getMessage());
}
}
}
# Please install OpenAI SDK first: `pip3 install openai`
from openai import OpenAI
client = OpenAI(api_key="<API Key>", base_url="https://gate.wujieai.net/wj-open/v1/chat/completions")
response = client.chat.completions.create(
model="deepseek-ai/DeepSeek-R1",
messages=[
{"role": "user", "content": "Hello"},
],
stream=True
)
print(response.choices[0].message.content)
// Please install OpenAI SDK first: `npm install openai`
import OpenAI from "openai";
const openai = new OpenAI({
baseURL: 'https://gate.wujieai.net/wj-open/v1/chat/completions',
apiKey: '<API Key>'
});
async function main() {
const completion = await openai.chat.completions.create({
messages: [{ role: "user", content: "Hello" }],
model: "deepseek-ai/DeepSeek-R1",
});
console.log(completion.choices[0].message.content);
}
main();
最后修改时间: 22 天前