ChatGPT 的应用场景也很广泛。它可以用于处理多种类型的对话,包括对话机器人、问答机器人和客服机器人等。
它还可以用于各种自然语言处理任务,比如文本摘要、情感分析和信息提取等。例如,在一个问答系统中,ChatGPT 可以提供准确的答案,解决用户的疑惑;在一个客服机器人中,它可以帮助用户解决问题,提供更好的服务体验。
ChatGPT 是一款由 OpenAl 开发的语言模型产品,它能够模拟人类的语言行为,与用户进行自然的交互。ChatGPT 基于GPT-3.5(Generative Pretrained Transformer 3.5)的语言模型建造,通过使用大量的训练数据来模拟人类的语言行为,并通过语法和语义分析,生成人类可以理解的文本。它可以根据上下文的语境,提供准确和恰当的回答,并模拟多种情绪和语气,可以让用户在与视器交互时,感受到更加真实和自然的对话体验。
本服务仅供个人学习、学术研究目的使用,未经许可,请勿分享、传播输入及生成的文本、图片内容。您在从事与本服务相关的所有行为(包括但不限于访问浏览、利用、转载、宣传介绍)时,必须以善意且谨慎的态度行事;您确保不得利用本服务故意或者过失的从事危害国家安全和社会公共利益、扰乱经济秩序和社会秩序、侵犯他人合法权益等法律、行政法规禁止的活动,并确保自定义输入文本不包含违反法律法规、政治相关、侵害他人合法权益的内容。
进行对话
请求Header:
名称 | 值 | |
---|---|---|
Content-Type | application/x-www-form-urlencoded |
请求参数说明:
名称 | 必填 | 类型 | 说明 | |
---|---|---|---|---|
q | 是 | string | 需要对话的内容,内容不超过512字符,如:帮我写一封情书。 | |
chat_id | 否 | string | 对话标识,支持6-32位字母数字。(用于同一组会话上下文关联) | |
key | 是 | string | 在个人中心->我的数据,接口名称上方查看 |
请求代码示例:
curl -k -i "http://gpt.juhe.cn/chatgpt/query?key=key&q=%E5%B8%AE%E6%88%91%E5%86%99%E4%B8%80%E5%B0%81%E6%83%85%E4%B9%A6&chat_id="
<?php
/**
* 1799-进行对话 - 代码参考(根据实际业务情况修改)
*/
// 基本参数配置
$apiUrl = "http://gpt.juhe.cn/chatgpt/query"; // 接口请求URL
$method = "GET"; // 接口请求方式
$headers = ["Content-Type: application/x-www-form-urlencoded"]; // 接口请求header
$apiKey = "您申请的调用APIkey"; // 在个人中心->我的数据,接口名称上方查看
// 接口请求入参配置
$requestParams = [
'key' => $apiKey,
'q'=> '帮我写一封情书',
'chat_id'=> '',
];
$requestParamsStr = http_build_query($requestParams);
// 发起接口网络请求
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $apiUrl . '?' . $requestParamsStr);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
if (1 == strpos("$" . $apiUrl, "https://")) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
$response = curl_exec($curl);
$httpInfo = curl_getinfo($curl);
curl_close($curl);
// 解析响应结果
$responseResult = json_decode($response, true);
if ($responseResult) {
// 网络请求成功。可依据业务逻辑和接口文档说明自行处理。
var_dump($responseResult);
} else {
// 网络异常等因素,解析结果异常。可依据业务逻辑自行处理。
// var_dump($httpInfo);
var_dump("请求异常");
}
import requests
# 1799-进行对话 - 代码参考(根据实际业务情况修改)
# 基本参数配置
apiUrl = 'http://gpt.juhe.cn/chatgpt/query' # 接口请求URL
apiKey = '您申请的调用APIkey' # 在个人中心->我的数据,接口名称上方查看
# 接口请求入参配置
requestParams = {
'key': apiKey,
'q': '帮我写一封情书',
'chat_id': '',
}
# 发起接口网络请求
response = requests.get(apiUrl, params=requestParams)
# 解析响应结果
if response.status_code == 200:
responseResult = response.json()
# 网络请求成功。可依据业务逻辑和接口文档说明自行处理。
print(responseResult)
else:
# 网络异常等因素,解析结果异常。可依据业务逻辑自行处理。
print('请求异常')
package main
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
)
func main() {
// 基本参数配置
apiUrl := "http://gpt.juhe.cn/chatgpt/query"
apiKey := "您申请的调用APIkey"
// 接口请求入参配置
requestParams := url.Values{}
requestParams.Set("key", apiKey)
requestParams.Set("q", "帮我写一封情书")
requestParams.Set("chat_id", "")
// 发起接口网络请求
resp, err := http.Get(apiUrl + "?" + requestParams.Encode())
if err != nil {
fmt.Println("网络请求异常:", err)
return
}
defer resp.Body.Close()
var responseResult map[string]interface{}
err = json.NewDecoder(resp.Body).Decode(&responseResult)
if err != nil {
fmt.Println("解析响应结果异常:", err)
return
}
fmt.Println(responseResult)
}
using System;
using System.Net;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
namespace Common_API_Test.Test_Demo
{
class Csharp_get
{
static void Main(string[] args)
{
string url = "http://gpt.juhe.cn/chatgpt/query";
string apiKey = "您申请的调用APIkey";
Dictionary<string, string> data = new Dictionary<string, string>();
data.Add("key", apiKey);
data.Add( "q", "帮我写一封情书");
data.Add( "chat_id", "");
using (WebClient client = new WebClient())
{
string fullUrl = url + "?" + string.Join("&", data.Select(x => x.Key + "=" + x.Value));
try
{
string responseContent = client.DownloadString(fullUrl);
dynamic responseData = JsonConvert.DeserializeObject(responseContent);
if (responseData != null)
{
Console.WriteLine("Return Code: " + responseData["error_code"]);
Console.WriteLine("Return Message: " + responseData["reason"]);
}
else
{
Console.WriteLine("json解析异常!");
}
}
catch (Exception)
{
Console.WriteLine("请检查其它错误");
}
}
}
}
}
const axios = require('axios'); // npm install axios
// 基本参数配置
const apiUrl = 'http://gpt.juhe.cn/chatgpt/query'; // 接口请求URL
const apiKey = '您申请的调用APIkey'; // 在个人中心->我的数据,接口名称上方查看
// 接口请求入参配置
const requestParams = {
key: apiKey,
q: '帮我写一封情书',
chat_id: '',
};
// 发起接口网络请求
axios.get(apiUrl, {params: requestParams})
.then(response => {
// 解析响应结果
if (response.status === 200) {
const responseResult = response.data;
// 网络请求成功。可依据业务逻辑和接口文档说明自行处理。
console.log(responseResult);
} else {
// 网络异常等因素,解析结果异常。可依据业务逻辑自行处理。
console.log('请求异常');
}
})
.catch(error => {
// 网络请求失败,可以根据实际情况进行处理
console.log('网络请求失败:', error);
});
package cn.juhe.test;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class JavaGet {
public static void main(String[] args) throws Exception {
String apiKey = "你申请的key";
String apiUrl = "http://gpt.juhe.cn/chatgpt/query";
HashMap<String, String> map = new HashMap<>();
map.put("key", apiKey);
map.put("q", "帮我写一封情书");
map.put("chat_id", "");
URL url = new URL(String.format("%s?%s", apiUrl, params(map)));
BufferedReader in = new BufferedReader(new InputStreamReader((url.openConnection()).getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
System.out.println(response);
}
public static String params(Map<String, String> map) {
return map.entrySet().stream()
.map(entry -> {
try {
return entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), StandardCharsets.UTF_8.toString());
} catch (Exception e) {
e.printStackTrace();
return entry.getKey() + "=" + entry.getValue();
}
})
.collect(Collectors.joining("&"));
}
}
// 基本参数配置
NSString *apiUrl = @"http://gpt.juhe.cn/chatgpt/query"; // 接口请求URL
NSString *apiKey = @"您申请的调用APIkey"; // 在个人中心->我的数据,接口名称上方查看
// 接口请求入参配置
NSDictionary *requestParams = @{
@"key": apiKey,
@"q": @"帮我写一封情书",
@"chat_id": @"",
};
// 发起接口网络请求
NSURLComponents *components = [NSURLComponents componentsWithString:apiUrl];
NSMutableArray *queryItems = [NSMutableArray array];
[requestParams enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) {
[queryItems addObject:[NSURLQueryItem queryItemWithName:key value:value]];
}];
components.queryItems = queryItems;
NSURL *url = components.URL;
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error) {
// 网络请求异常处理
NSLog(@"请求异常");
} else {
NSError *jsonError;
NSDictionary *responseResult = [NSJSONSerialization JSONObjectWithData:data options:0 error:&jsonError];
if (!jsonError) {
// 网络请求成功处理
// NSLog(@"%@", [responseResult objectForKey:@"error_code"]);
NSLog(@"%@", responseResult);
} else {
// 解析结果异常处理
NSLog(@"解析结果异常");
}
}
}];
[task resume];
返回参数说明:
名称 | 类型 | 说明 | |
---|---|---|---|
error_code | int | 返回码 | |
reason | string | 返回说明 | |
result | object | 返回结果集 | |
order_id | string | 请求单号 | |
resp | array | 返回结果 |
JSON返回示例:JSON在线格式化工具 >
{
"reason": "success",
"result": {
"order_id": "G230212215051900690324838",
"resp": [
"亲爱的:\n\n我想对你说,你是我生命中最重要的人,你是我最爱的人,你是我最亲密的朋友。\n\n我们在一起的时光是最美好的,你的笑容是我最珍贵的记忆,你的温柔是我最温暖的抚慰。\n\n我爱你,不仅仅是因为你的美丽,更是因为你的心灵,你的善良,你的勇敢,你的坚强。\n\n我们一起走过的日子,一起度过的岁月,一起分享的欢乐,一起承受的痛苦,都是我永远不会忘记的。\n\n我会一直爱你,直到永远,直到地老天荒,直到海枯石烂。\n\n爱你,\n\n你的心上人"
]
},
"error_code": 0
}
服务级错误码参照(error_code):
错误码 | 说明 | |
---|---|---|
274701 | 输入的内容为空或内容过长(512字符以内) | |
274702 | 查询失败 | |
274703 | 数据源网络异常,请重试 | |
274704 | 该内容暂时无法回答 |
系统级错误码参照:
错误码 | 说明 | 旧版本(resultcode) | |
---|---|---|---|
10001 | 错误的请求KEY | 101 | |
10002 | 该KEY无请求权限 | 102 | |
10003 | KEY过期 | 103 | |
10004 | 错误的OPENID | 104 | |
10005 | 应用未审核超时,请提交认证 | 105 | |
10007 | 未知的请求源 | 107 | |
10008 | 被禁止的IP | 108 | |
10009 | 被禁止的KEY | 109 | |
10011 | 当前IP请求超过限制 | 111 | |
10012 | 请求超过次数限制 | 112 | |
10013 | 测试KEY超过请求限制 | 113 | |
10014 | 系统内部异常(调用充值类业务时,请务必联系客服或通过订单查询接口检测订单,避免造成损失) | 114 | |
10020 | 接口维护 | 120 | |
10021 | 接口停用 | 121 |
错误码格式说明(示例:200201):
2 | 002 | 01 | |
---|---|---|---|
服务级错误(1为系统级错误) | 服务模块代码(即数据ID) | 具体错误代码 |