智增增API
API登录演示ChatAPI应用示例API最新消息
API登录演示ChatAPI应用示例API最新消息
Github地址
智增增官网
  1. 示例代码
  • 欢迎使用智增增
  • 概述
  • HelloWord-第一个示例
  • API最新消息
  • OpenAI接口列表
    • OpenAI概述
    • Introduction介绍
    • Audio 音频
    • Chat 聊天
    • Completions 补全(Legacy)
    • Embeddings 嵌入
    • Fine-tuning 微调
    • Batch 批处理
    • Files 文件
    • Images 图像
    • Models 模型
    • Moderations 审核
  • Anthropic接口列表
    • Claude概述
    • Claude消息
    • Claude深度思考
  • Google接口列表
    • Gemini概述
    • Gemini文本生成
    • Gemini深度思考
    • Gemini函数调用
    • Gemini图片生成
    • Gemini支持谷歌搜索
  • Xai接口列表
    • Grok概述
    • Grok的chat
    • Grok深度思考
  • 自有API接口
    • 查询余额
    • Modify fine-tune
  • 模型说明
    • 模型和价格说明
    • 其它模型示例
    • 费用计算说明
    • 深度思考
    • 模型微调
  • 其它说明
    • 主要概念
    • 常见问题
    • base_url地址到底是哪个?
    • 更新记录
    • 退款说明
    • 错误码
  • 接口示例
    • 模型调用示例
    • API应用示例
    • 示例场景
    • 示例代码
      • audio_transcriptions(语音识别)
      • c#语言(支持Unity)
      • c++语言
      • curl
      • gpt-4-vision.图片理解
      • java语言(支持android)
      • js
      • langchain的支持
      • object-c语言(支持苹果IOS)
      • php
      • python
      • translation(识别并翻译成英文)
      • tts.speech.语音合成
      • 兼容openai的Node.js库
      • 兼容openai的python库
      • 兼容openai的其它各种库
      • 函数调用
      • 文字生成图片
      • 流式示例stream
  • fine-tune.微调
    • 微调常见错误
    • 微调示例
    • finetune特别注意事项
  • assistant.助手
    • assistant示例
  • batch.批处理
    • batch示例
    • batch特别注意事项
  • Documentation 使用手册
  • 文章列表
    • 智增增-AI工具配置使用指南
    • 大模型怎么实现连续对话(记忆上下文)
    • ChatGPT-Next-Web使用指南
    • 为什么调用chatgpt的api接口没有返回??怎么查问题
  1. 示例代码

java语言(支持android)

java语言的示例代码:(只需换成自己的key)
package gpt.zhizengzeng.utils;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.IOException;

public class ChatDemo
{
    public static void main(String[] args) throws Exception
    {
        String url = "https://api.zhizengzeng.com/v1/chat/completions";
        String key = "你在智增增获取的API_SECRET_KEY";
        GPTConnectorServer(url, key);
    }

    public static void GPTConnectorServer(String paramUrl, String paramKey) throws IOException {
        // 设置 API 密钥和模型 ID
        String apiKey = paramKey;
        String modelId = "gpt-3.5-turbo";

        // 构建 API 请求 URL
        String apiUrl = paramUrl;

        // 构建请求数据
        String requestData = "{\"model\": \"" + modelId + "\", \"messages\": [{\"role\": \"system\", \"content\": \"You are a helpful assistant.\"}, {\"role\": \"user\", \"content\": \"Translate the following English text to French: 'Hello, how are you?'\"}]}";

        // 创建 URL 对象
        URL url = new URL(apiUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();

        // 设置请求方法为 POST
        connection.setRequestMethod("POST");

        // 设置请求头部
        connection.setRequestProperty("Authorization", "Bearer " + apiKey);
        connection.setRequestProperty("Content-Type", "application/json");
        connection.setRequestProperty("Accept", "application/json");

        // 启用输入输出流
        connection.setDoOutput(true);

        // 将请求数据写入输出流
        try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) {
            outputStream.write(requestData.getBytes());
            outputStream.flush();
        }

        // 获取响应
        int responseCode = connection.getResponseCode();
        if (responseCode == HttpURLConnection.HTTP_OK) {
            // 读取响应数据
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
                String line;
                StringBuilder response = new StringBuilder();
                while ((line = reader.readLine()) != null) {
                    response.append(line);
                }
                System.out.println("API 响应:\n" + response.toString());
            }
        } else {
            System.err.println("API 请求失败,响应码: " + responseCode);
        }
        // 关闭连接
        connection.disconnect();
    }
}

修改于 2024-05-15 01:25:59
上一页
gpt-4-vision.图片理解
下一页
js
Built with