一、接口信息
接口地址:https://www.1bit.asia/openai/api/ask
类型:POST
参数:{"prompt":"写一个修仙小说目录","userName":"apiuser002","token":"链接页面获取"
}
说明:userName参数和token需要对应。多组不同账号token请查看
https://blog.csdn.net/liuhenghui5201/article/details/129721995
二、Java调用方式
package com.xiaohui.bird;import com.alibaba.fastjson2.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;public class ApplicationMain {public static void main(String[] args) {String question = "李白的著名古诗有哪些";System.out.println("问: "+question);String respStr = ask(question);System.out.println("答: "+respStr);}public static String ask(String question) {try {String questionInfo = getQuestionInfo(question);JSONObject questionJson = JSONObject.parseObject(questionInfo);String questionId = questionJson.getString("data");String answer = null;do{try { Thread.sleep(3000L); } catch (InterruptedException e) { e.printStackTrace(); }URL url = new URL("https://www.1bit.asia/openai/api/answer/"+questionId);HttpURLConnection con = (HttpURLConnection) url.openConnection();con.setRequestMethod("GET");BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));String inputLine;StringBuffer response = new StringBuffer();while ((inputLine = in.readLine()) != null) {response.append(inputLine);response.append(System.lineSeparator());}in.close();String answerString =response.toString();if(!"思考中...".equals(answerString)){answer = answerString;}} while (answer == null);return answer;} catch (Exception e) {e.printStackTrace();return "问答异常";}}private static String getQuestionInfo(String question) throws IOException {URL url = new URL("https://www.1bit.asia/openai/api/ask");HttpURLConnection con = (HttpURLConnection) url.openConnection();con.setRequestMethod("POST");// 设置请求头con.setRequestProperty("Content-Type", "application/json");// 设置请求体String requestBody = "{\"prompt\":\""+ question +"\",\"token\":\"6865725-27a9-4385-a7f5-97b09e434fw\",\"userName\":\"apiuser033\"}";con.setDoOutput(true);con.setDoInput(true);OutputStream os = con.getOutputStream();os.write(requestBody.getBytes());os.flush();os.close();BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));String inputLine;StringBuffer content = new StringBuffer();while ((inputLine = in.readLine()) != null) {content.append(inputLine);}in.close();String questionInfo = content.toString();return questionInfo;}
}
运行效果:
三、python 调用方式
# coding=gbk
import requests
import jsonprompt = input('请输入问题:')
url = 'https://www.1bit.asia/openai/api/ask'
data = {'prompt': prompt, 'token': '链接页面获取', 'userName':'apiuser002'}
headers = {'Content-Type':'application/json'}
response = requests.post(url, data= json.dumps(data), headers=headers)print('答:'+response.text)
运行效果
网页体验地址 https://1bit.asia