import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class BaiduWenxinYiYanExample {
public static void main(String[] args) {
try {
String apiUrl = "https://api.baidu.com/wenxin/yiyan"; // 假設(shè)的API URL
URL url = new URL(apiUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
// 設(shè)置請(qǐng)求頭,例如API密鑰等
connection.setRequestProperty("Authorization", "Bearer your_api_key");
int responseCode = connection.getResponseCode();
System.out.println("Response Code: " + responseCode);
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
// 打印結(jié)果
System.out.println(response.toString());
} else {
System.out.println("Failed to get a response");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
python復(fù)制
import requests
# 假設(shè)的API URL,實(shí)際使用時(shí)應(yīng)替換為訊飛星火的實(shí)際API地址
api_url = "https://api.iflytek.com/starfire/question"
# 設(shè)置請(qǐng)求頭和參數(shù)
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer your_access_token" # 替換為你的訪問令牌
}
# 設(shè)置請(qǐng)求數(shù)據(jù)
data = {
"question": "如何預(yù)防電腦病毒?"
}
# 發(fā)送請(qǐng)求并獲取響應(yīng)
response = requests.post(api_url, headers=headers, json=data)
# 打印響應(yīng)內(nèi)容
print(response.json())
python
# 假設(shè)的API URL,實(shí)際使用時(shí)應(yīng)替換為360多模態(tài)大語言模型的實(shí)際API地址
api_url = "https://api.360.com/multimodal/conversation"
import requests
# 設(shè)置請(qǐng)求頭和參數(shù)
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer your_access_token" # 替換為你的訪問令牌
}
# 設(shè)置請(qǐng)求數(shù)據(jù),例如繼續(xù)之前關(guān)于天氣的對(duì)話
data = {
"context": "之前我們討論了關(guān)于天氣的話題。",
"new_input": "今天天氣怎么樣?"
}
# 發(fā)送請(qǐng)求并獲取響應(yīng)
response = requests.post(api_url, headers=headers, json=data)
# 打印響應(yīng)內(nèi)容
print(response.json())
java復(fù)制
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
public class DouBaoAIJokeIntegration {
private static final String API_KEY = "your_api_key_here"; // 替換為您的API密鑰
private static final String API_URL = "https://api.doubaodotcom/ai/joke"; // 假設(shè)的API URL
public static void main(String[] args) {
String jokeRequest = "{ \"type\": \"random\" }"; // 請(qǐng)求隨機(jī)笑話的JSON字符串
try {
// 創(chuàng)建URL對(duì)象
URL url = new URL(API_URL);
// 打開連接
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// 設(shè)置請(qǐng)求方法
connection.setRequestMethod("POST");
// 設(shè)置請(qǐng)求頭信息
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Authorization", "Bearer " + API_KEY);
// 發(fā)送POST請(qǐng)求必須設(shè)置
connection.setDoOutput(true);
// 獲取輸出流并寫入請(qǐng)求體
try(OutputStream os = connection.getOutputStream()) {
byte[] input = jokeRequest.getBytes(StandardCharsets.UTF_8);
os.write(input, 0, input.length);
}
// 讀取響應(yīng)
try(BufferedReader br = new BufferedReader(
new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
StringBuilder response = new StringBuilder();
String responseLine = null;
while ((responseLine = br.readLine()) != null) {
response.append(responseLine.trim());
}
System.out.println("Joke from DouBao AI: " + response.toString());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class MiniMaxIntegration {
public static void main(String[] args) {
try {
String apiKey = "您的 API 密鑰";
String url = "http://www.dlbhg.com/api/scd2024061814753aa6cbc1/v2/scd2024061814753aa6cbc1/tdk-generator";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Authorization", "Bearer " + apiKey);
// 發(fā)送請(qǐng)求
con.setDoOutput(true);
// 處理響應(yīng)
int responseCode = con.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine())!= null) {
response.append(inputLine);
}
in.close();
System.out.println(response.toString());
} else {
System.out.println("Error: " + responseCode);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
冪簡(jiǎn)集成是國內(nèi)領(lǐng)先的API集成管理平臺(tái),專注于為開發(fā)者提供全面、高效、易用的API集成解決方案。冪簡(jiǎn)API平臺(tái)可以通過以下兩種方式找到所需大模型:通過關(guān)鍵詞搜索AI、或者從API Hub分類頁進(jìn)入尋找。
此外,冪簡(jiǎn)集成博客會(huì)編寫API入門指南、多語言API對(duì)接指南、API測(cè)評(píng)等維度的文章,讓開發(fā)者快速使用目標(biāo)API。