星火大模型接入及文本生成HTTP流式、非流式接口(JAVA)

Python调用讯飞星火AI大模型v3.x API接口使用教程 阅读详情
AI摘要

本文介绍如何使用Java实现与星火大模型的HTTP非流式和流式接口对接,涵盖配置、请求构造、响应处理及上下文记忆功能测试,适用于Spark Lite模型,提供完整的代码结构和调用流程。

一、接入星火大模型

首先,需要在讯飞开放平台(https://passport.xfyun.cn/login)进行登录:

在这里插入图片描述

  • 点击这个+创建应用:
    在这里插入图片描述

  • 创建应用:
    在这里插入图片描述

  • 查看创建好的应用:

在这里插入图片描述

点击创建的应用可以查看各种鉴权信息,如调用http接口需要的APIPassword。

二、基于JAVA实现HTTP非流式接口

非流式,即一次性返回生成的内容,返回为一个接口;流式,即一边生成一边返回,会返回多个接口,所有接口的文本内容拼接起来构成完整的回答。

本文以模型Spark Lite为例,重要信息(APIPassword、接口地址)在这个页面查看:https://console.xfyun.cn/services/cbm
接口文档在这个地址查看:https://www.xfyun.cn/doc/spark/HTTP%E8%B0%83%E7%94%A8%E6%96%87%E6%A1%A3.html#_1-%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E

1.配置

  • 需要先创建好Spring Boot项目,配置applicaiton.yml如下:
port: 9000

# 星火大模型相关配置
spark:
  # http鉴权相关配置
  http:
    httpApiPassword: ""
  # 模型相关配置,参考https://console.xfyun.cn/services/cbm
  model:
    temperature: 0.5 #核采样阈值,用于决定结果随机性,取值越高随机性越强,即相同的问题得到的不同答案的可能性越高。取值范围 (0,1],默认为0.5
    topK: 4 # 平衡生成文本的质量和多样性,较小的 k 值会减少随机性,使得输出更加稳定;而较大的 k 值会增加随机性,产生更多新颖的输出。取值范围[1, 6],默认为4
    max_tokens: 1024 # 允许回复的最大tokens数量
    modelName: "lite"
    apiHttpUrl: "https://spark-api-open.xf-yun.com/v1/chat/completions"
    historyRememberCount: 100 # 记录的上下文条数,为0则表示单轮问答不记住上下文
  • pom.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>spark</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.7.6</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.30</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>2.0.43</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>2.7.18</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-websocket</artifactId>
            <version>2.7.18</version>
        </dependency>
    </dependencies>

</project>

2.接口实现

(1)分析接口请求

  • 请求头:
Content-Type: application/json
Authorization: Bearer 123456
  • 请求体:
{
    "model": "generalv3.5",
    "user": "用户唯一id",
    "messages": [
        {
            "role": "system",
            "content": "你是知识渊博的助理"
        },
        {
            "role": "user",
            "content": "你好,讯飞星火"
        }
    ],
    // 下面是可选参数
    "temperature": 0.5,
    "top_k": 4,
    "stream": false,
    "max_tokens": 1024
}
  • 正常响应:
{
    "code": 0,
    "message": "Success",
    "sid": "cha000b0003@dx1905cd86d6bb86d552",
    "choices": [
        {
            "message": {
                "role": "assistant",
                "content": "你好,我是由科大讯飞构建的星火认知智能模型。\n如果你有任何问题或者需要帮助的地方,请随时告诉我!我会尽力为你提供解答和支持。请问有什么可以帮到你的吗?"
            },
            "index": 0
        }
    ],
    "usage": {
        "prompt_tokens": 6,
        "completion_tokens": 42,
        "total_tokens": 48
    }
}
  • 错误响应:
{
    "error": {
        "message": "invalid user",
        "type": "api_error",
        "param": null,
        "code": null
    }
}

(2)代码实现

  • 主方法:
	//从application.yml中引入一些必要的配置
	@Value("${spark.http.httpApiPassword}")
    private String httpApiPassword;

    @Value("${spark.model.apiHttpUrl}")
    private String apiUrl;

    @Value("${spark.model.temperature}")
    private float temperature;

    @Value("${spark.model.topK}")
    private int topK;

    @Value("${spark.model.modelName}")
    private String model;

    @Value("${spark.model.max_tokens}")
    private int maxTokens;

    @Value("${spark.model.historyRememberCount}")
    private int historyRememberCount;

    private final ObjectMapper objectMapper = new ObjectMapper();
    
    public SparkResponse completions(String systemContent, String userContent, String userId) throws IOException {
        URL url = new URL(apiUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        // 设置请求头
        connection.setRequestProperty("Authorization", "Bearer " + httpApiPassword);
        connection.setRequestProperty("Content-Type", "application/json");
        // 设置请求体,发起请求
        connection.setDoOutput(true);
        connection.getOutputStream().write(buildRequestBody(systemContent, userContent, userId,false).toJSONString().getBytes());
        // 获取响应
        SparkResponse res = parseResponse(connection);
        // 将响应加到上下文中
        if(historyRememberCount>0){
            rememberCompletionsAnswer(userId,res);
        }
        return res;
    }
  • 构建请求体:
private JSONObject buildRequestBody(String systemContent, String userContent, String userId, boolean isStreaming) {
        // 加入一些大模型参数
        JSONObject requestBody = new JSONObject();
        requestBody.put("model", model);
        requestBody.put("temperature", temperature);
        requestBody.put("top_k", topK);
        requestBody.put("max_tokens", maxTokens);
        requestBody.put("stream", isStreaming);
        JSONArray messages = new JSONArray();
        // 将历史上下文加入请求中
        if (historyRememberCount > 0&&!historyDialoguesMap.isEmpty()&&historyDialoguesMap.containsKey(userId)) {
            messages.addAll(historyDialoguesMap.get(userId));
        }
        // 构建此轮dialogue并加入到上下文中
        Dialogue messageSystem = null;
        if (StringUtils.isNotEmpty(systemContent)) {
            messageSystem = new Dialogue("system", systemContent);
            messages.add(messageSystem);
        }
        Dialogue messageUser = new Dialogue("user", userContent);
        messages.add(messageUser);
        if(historyRememberCount > 0){
            historyInsert(userId,messageSystem);
            historyInsert(userId,messageUser);
        }
        requestBody.put("messages", messages);
        return requestBody;
    }

	/**
     * 上下文添加方法
     */
    public void historyInsert(String userId, Dialogue dialogue) {
        if(dialogue == null){
            return;
        }
        if (historyDialoguesMap.containsKey(userId)) {
            List<Dialogue> historyDialogues = historyDialoguesMap.get(userId);
            historyDialogues.add(dialogue);
            if (historyDialogues.size() > historyRememberCount) {
                historyDialogues.remove(0);
            }
        }else{
            List<Dialogue> historyDialogues = new ArrayList<>();
            historyDialogues.add(dialogue);
            historyDialoguesMap.put(userId,historyDialogues);
            if (historyDialogues.size() > historyRememberCount) {
                historyDialogues.remove(0);
            }
        }
    }
  • 定义响应体类:
/**
 * 星火大模型返回类型封装
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
public class SparkResponse implements Serializable {
    private static final long serialVersionUID = 1L;

    private Integer code;
    private String message;
    private String sid;
    private String id;
    private Long created;
    private List<Choices> choices;
    private JSONObject usage;
    private JSONObject error;
}
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Choices implements Serializable {

    private static final long serialVersionUID = 1L;

    private Dialogue message;
    private Dialogue delta;
    private int index;
}
/**
 * 与大模型的会话
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Dialogue {
    /**
     * 角色:system  user  assistant
     */
    private String role;
    private String content;
    private int index;

    public Dialogue(String role, String content) {
        this.role=role;
        this.content=content;
    }
}
  • 获取响应:
    private SparkResponse parseResponse(HttpURLConnection connection) throws IOException {
        int responseCode = connection.getResponseCode();
        log.info("SparkHttpAPI completions responseCode:{}", responseCode);
        if (responseCode == HttpURLConnection.HTTP_OK) {
            try (InputStream inputStream = connection.getInputStream()) {
                return objectMapper.readValue(inputStream, SparkResponse.class);
            }
        } else {
            throw new SparkResponseParseException("NonStreaming Completions Result Parse Error");
        }
    }
  • 将响应加到上下文中:
 public void rememberCompletionsAnswer(String userId, SparkResponse res){
        historyInsert(userId, res.getChoices().get(0).getMessage());
    }

3.功能测试

(1)测试对话功能

 @Autowired
    private SparkHttpAPI sparkHttpAPITest;

    @Test
    void completions() {
        String systemContent = "你是知识渊博的助理";
        String userContent = "告诉我讯飞星火认知大模型的应用场景有哪些?";
        try{
            SparkResponse ans= sparkHttpAPITest.completions(systemContent,userContent,"111");
            System.out.println(ans);
        }catch (Exception e){
            log.error("测试不通过",e);
        }
    }

在这里插入图片描述

(2)测试记住上下文功能

 @Test
    void historyTest() {
        String systemContent = "你是知识渊博的律师";
        String userContent = "小王偷了小李门口的鞋子,小王犯法吗?";
        try {
            SparkResponse ans = sparkHttpAPITest.completions(systemContent, userContent, "111");
            System.out.println(ans);
            userContent = "小王犯了什么罪";
            ans = sparkHttpAPITest.completions(null, userContent, "111");
            System.out.println(ans);
        } catch (Exception e) {
            log.error("测试不通过", e);
        }
    }

在这里插入图片描述

三、基于JAVA实现HTTP流式接口

接口文档也在这个地址查看:https://www.xfyun.cn/doc/spark/HTTP%E8%B0%83%E7%94%A8%E6%96%87%E6%A1%A3.html#_1-%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E

1.接口实现

(1)分析接口请求

  • 响应格式:

相比非流式略微有一些不同,响应分成了多次,最后一个data:[DONE]为结束标志。

data:{"code":0,"message":"Success","sid":"cha000b000c@dx1905cf38fc8b86d552","id":"cha000b000c@dx1905cf38fc8b86d552","created":1719546385,"choices":[{"delta":{"role":"assistant","content":"你好"},"index":0}]}

data:{"code":0,"message":"Success","sid":"cha000b000c@dx1905cf38fc8b86d552","id":"cha000b000c@dx1905cf38fc8b86d552","created":1719546385,"choices":[{"delta":{"role":"assistant","content":",很高兴"},"index":0}]}

data:{"code":0,"message":"Success","sid":"cha000b000c@dx1905cf38fc8b86d552","id":"cha000b000c@dx1905cf38fc8b86d552","created":1719546385,"choices":[{"delta":{"role":"assistant","content":"为你解答问题"},"index":0}]}

data:{"code":0,"message":"Success","sid":"cha000b000c@dx1905cf38fc8b86d552","id":"cha000b000c@dx1905cf38fc8b86d552","created":1719546385,"choices":[{"delta":{"role":"assistant","content":"。\n"},"index":0}]}

data:{"code":0,"message":"Success","sid":"cha000b000c@dx1905cf38fc8b86d552","id":"cha000b000c@dx1905cf38fc8b86d552","created":1719546387,"choices":[{"delta":{"role":"assistant","content":"我是讯飞星火认知大模型,由科大讯飞构建的认知智能系统。"},"index":0}]}

data:{"code":0,"message":"Success","sid":"cha000b000c@dx1905cf38fc8b86d552","id":"cha000b000c@dx1905cf38fc8b86d552","created":1719546388,"choices":[{"delta":{"role":"assistant","content":"我具备与人类进行自然交流的能力,可以高效地满足各领域的认知智能需求。"},"index":0}]}

data:{"code":0,"message":"Success","sid":"cha000b000c@dx1905cf38fc8b86d552","id":"cha000b000c@dx1905cf38fc8b86d552","created":1719546389,"choices":[{"delta":{"role":"assistant","content":"无论你有什么问题或者需要帮助的地方,我都将尽我所能提供支持和解决方案。请随时告诉我你的需求!"},"index":0}]}

data:{"code":0,"message":"Success","sid":"cha000b000c@dx1905cf38fc8b86d552","id":"cha000b000c@dx1905cf38fc8b86d552","created":1719546389,"choices":[{"delta":{"role":"assistant","content":""},"index":0}],"usage":{"prompt_tokens":6,"completion_tokens":68,"total_tokens":74}}

data:[DONE]

(2)代码实现

  • 主方法:
    public void streamingCompletions(String systemContent, String userContent, Consumer<SparkResponse> responseConsumer, String userId) throws IOException {
        URL url = new URL(apiUrl);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        // 设置请求头
        connection.setRequestProperty("Authorization", "Bearer " + httpApiPassword);
        connection.setRequestProperty("Content-Type", "application/json");
        // 设置请求体
        connection.setDoOutput(true);
        connection.getOutputStream().write(buildRequestBody(systemContent, userContent, userId,true).toJSONString().getBytes());
        // 获取响应
        parseResponseStreaming(connection, responseConsumer, userId);
    }
  • 解析响应:
private void parseResponseStreaming(HttpURLConnection connection, Consumer<SparkResponse> responseConsumer, String userId) throws IOException {
        int responseCode = connection.getResponseCode();
        log.info("SparkHttpAPI completions responseCode:{}", responseCode);
        if (responseCode == HttpURLConnection.HTTP_OK) {
            try (InputStream inputStream = connection.getInputStream();
                 BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
                String line;
                while ((line = reader.readLine()) != null) {
                    if (!line.trim().isEmpty()) {
                        line = line.replaceFirst("data: ", "");
                        if (line.equals("[DONE]")) {
                            return;
                        }
                        try {
                            SparkResponse response = objectMapper.readValue(line, SparkResponse.class);
                            if(historyRememberCount>0){
                                rememberStreamingAnswer(userId,response);
                            }
                            responseConsumer.accept(response); // 将解析的响应传递给调用方
                        } catch (Exception e) {
                            log.error("Failed to parse response line: {}", line, e);
                        }
                    }
                }
            }
        } else {
            throw new SparkResponseParseException("Streaming Completions Result Parse Error");
        }
    }
  • 记住响应到上下文中:
public void rememberStreamingAnswer(String userId, SparkResponse res){
        historyInsert(userId, res.getChoices().get(0).getDelta());
    }

2.功能测试

(1)测试对话功能

    @Test
    void streamingCompletions() {
        String systemContent = "你是知识渊博的助理";
        String userContent = "告诉我讯飞星火认知大模型的应用场景有哪些?";
        try {
            sparkHttpAPITest.streamingCompletions(systemContent, userContent, SparkHttpResponseHandler::handleResponse, "111");
        } catch (Exception e) {
            log.error("测试不通过", e);
        }
    }
  • 其中的SparkHttpResponseHandler用于处理流式响应:
/**
 * 处理流式接口响应
 */
public class SparkHttpResponseHandler {
    public static void handleResponse(SparkResponse response) {
        System.out.println("Received response: " + response);
    }
}
  • 执行结果:
2025-01-24 10:21:29.901  INFO 25120 --- [           main] org.example.llm.SparkHttpAPI             : SparkHttpAPI completions responseCode:200
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685289, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=我是科大讯飞研发, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685289, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=的以中文为核心的, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685290, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=新一代认知智能大, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685290, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=模型,我能够在与, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685290, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=人自然的对话互动, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685290, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=的过程中,同时提, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685290, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=供以下多种能力:, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685290, choices=[Choices(message=null, delta=Dialogue(role=assistant, content= 1. 内容生成, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685290, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=能力:我可以生成, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685290, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=多种类型多种风格, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685290, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=的内容,例如邮件, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685290, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=、文案、公文、作, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685291, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=文、对话等; 2, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685291, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=. 自然语言理解, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685291, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=能力:我可以理解, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685291, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=对话和篇章,并可, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685291, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=以实现文本摘要、, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685291, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=信息抽取、多语言, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685291, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=翻译、阅读理解、, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685291, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=情感分析等能力;, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685291, choices=[Choices(message=null, delta=Dialogue(role=assistant, content= 3. 知识问答, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685292, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=能力:我可以回答, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685292, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=各种各样的问题,, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685292, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=包括医学知识、百, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685292, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=科知识、天文地理, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685292, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=等; 4. 推理, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685292, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=能力:我拥有基于, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685292, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=思维链的推理能力, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685292, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=,能够进行科学推, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685292, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=理、常识推理等;, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685292, choices=[Choices(message=null, delta=Dialogue(role=assistant, content= 5. 数学能力, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685293, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=:我具备数学思维, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685293, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=,能理解数学问题, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685293, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=,进行计算、推理, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685293, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=、证明,并能给出, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685293, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=解题步骤。 6., index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685293, choices=[Choices(message=null, delta=Dialogue(role=assistant, content= 代码理解与生成, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685293, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=能力:我可以进行, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685293, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=代码理解、代码修, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685293, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=改以及代码生成等, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685293, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=工作; 此外,我, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685294, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=还具备对话游戏、, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685294, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=角色扮演等特色能, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685294, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=力,等待你的探索, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685294, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=。 我可以对多元, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685294, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=能力实现融合统一, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685294, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=,对真实场景下的, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685294, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=需求,我具备提出, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685294, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=问题、规划问题、, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685294, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=解决问题的闭环能, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685294, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=力。进一步地,我, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685295, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=可以持续从海量数, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685295, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=据和大规模知识中, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685295, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=不断学习进化,这, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685295, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=些能力使得我能够, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685295, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=在多个行业和领域, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685295, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=发挥越来越重要的, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685295, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=作用。 同时基于, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685295, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=我的能力,我将结, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685295, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=合科大讯飞以及行, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685295, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=业生态伙伴的相关, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685296, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=产品,完成多模态, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685296, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=理解和生成等相关, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685296, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=工作。, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000beda5@dx194961d49a99a4b532, id=cha000beda5@dx194961d49a99a4b532, created=1737685296, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=null, index=0), index=0)], usage={"prompt_tokens":12,"completion_tokens":304,"total_tokens":316}, error=null)

(2)测试记住上下文功能

    @Test
    void historyTest() {
        String systemContent = "你是知识渊博的律师";
        String userContent = "小王偷了小李门口的鞋子,小王犯法吗?";
        try {
            sparkHttpAPITest.streamingCompletions(systemContent, userContent, SparkHttpResponseHandler::handleResponse,"111");
            userContent = "小王犯了什么罪";
            sparkHttpAPITest.streamingCompletions(null, userContent, SparkHttpResponseHandler::handleResponse,"111");
        } catch (Exception e) {
            log.error("测试不通过", e);
        }
    }
  • 执行结果:
2025-01-24 10:24:38.667  INFO 33000 --- [           main] org.example.llm.SparkHttpAPI             : SparkHttpAPI completions responseCode:200
Received response: SparkResponse(code=0, message=Success, sid=cha000bf839@dx19496202bdeb8f2532, id=cha000bf839@dx19496202bdeb8f2532, created=1737685478, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=小, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000bf839@dx19496202bdeb8f2532, id=cha000bf839@dx19496202bdeb8f2532, created=1737685478, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=王的行为, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000bf839@dx19496202bdeb8f2532, id=cha000bf839@dx19496202bdeb8f2532, created=1737685478, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=是否构成犯罪, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000bf839@dx19496202bdeb8f2532, id=cha000bf839@dx19496202bdeb8f2532, created=1737685478, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=,取决于具体的法律, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000bf839@dx19496202bdeb8f2532, id=cha000bf839@dx19496202bdeb8f2532, created=1737685478, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=条文和司法解释, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000bf839@dx19496202bdeb8f2532, id=cha000bf839@dx19496202bdeb8f2532, created=1737685479, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=。, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000bf839@dx19496202bdeb8f2532, id=cha000bf839@dx19496202bdeb8f2532, created=1737685479, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=在大多数情况下,偷窃是一种违法行为,因为它侵犯了他人的财产权。然而,如果小王只是出于好奇或者误认为鞋子属于他而拿走,那么这种行为可能不会被视为犯罪。

, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000bf839@dx19496202bdeb8f2532, id=cha000bf839@dx19496202bdeb8f2532, created=1737685480, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=此外,如果小王的行为是出于善意,例如他误以为鞋子是自己的,那么这种行为可能不会被认定为犯罪。但是,如果他的行为导致了小李的财产损失,那么他可能需要承担相应的赔偿责任。

, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000bf839@dx19496202bdeb8f2532, id=cha000bf839@dx19496202bdeb8f2532, created=1737685480, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=总之,小王是否犯法需要根据具体情况来判断。如果您有关于这个问题的疑问,建议您咨询专业的律师以获取准确的法律建议。, index=0), index=0)], usage={"prompt_tokens":35,"completion_tokens":129,"total_tokens":164}, error=null)
2025-01-24 10:24:41.009  INFO 33000 --- [           main] org.example.llm.SparkHttpAPI             : SparkHttpAPI completions responseCode:200
Received response: SparkResponse(code=0, message=Success, sid=cha000bf847@dx194962034c8b8f2532, id=cha000bf847@dx194962034c8b8f2532, created=1737685481, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=小, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000bf847@dx194962034c8b8f2532, id=cha000bf847@dx194962034c8b8f2532, created=1737685481, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=王的行为, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000bf847@dx194962034c8b8f2532, id=cha000bf847@dx194962034c8b8f2532, created=1737685481, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=可能构成盗窃, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000bf847@dx194962034c8b8f2532, id=cha000bf847@dx194962034c8b8f2532, created=1737685481, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=罪。, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000bf847@dx194962034c8b8f2532, id=cha000bf847@dx194962034c8b8f2532, created=1737685482, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=根据《中华人民共和国刑法》第二百六十四条,盗窃公私财物,数额较大或者多次盗窃的,处三年以下有期徒刑、拘役或者管制,并处或者单处罚金;数额巨大或者有其他严重情节的,处三年以上十年以下有期徒刑,并处罚金;, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000bf847@dx194962034c8b8f2532, id=cha000bf847@dx194962034c8b8f2532, created=1737685482, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=数额特别巨大或者有其他特别严重情节的,处十年以上有期徒刑或者无期徒刑,并处罚金或者没收财产。

然而,如果小王是出于好奇或者误认为鞋子属于他而拿走,那么这种行为可能不会被视为犯罪。, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000bf847@dx194962034c8b8f2532, id=cha000bf847@dx194962034c8b8f2532, created=1737685483, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=此外,如果小王的行为导致了小李的财产损失,那么他可能需要承担相应的赔偿责任。

请注意,这只是一般情况下的法律解释,具体情况需要根据案件的具体事实和证据来判断。, index=0), index=0)], usage=null, error=null)
Received response: SparkResponse(code=0, message=Success, sid=cha000bf847@dx194962034c8b8f2532, id=cha000bf847@dx194962034c8b8f2532, created=1737685483, choices=[Choices(message=null, delta=Dialogue(role=assistant, content=如果您有关于这个问题的疑问,建议您咨询专业的律师以获取准确的法律建议。, index=0), index=0)], usage={"prompt_tokens":218,"completion_tokens":175,"total_tokens":393}, error=null)

星火大模型API接入实战:鉴权、流式响应与生产级调优 大模型API接入不仅是发送HTTP请求,更涉及鉴权协议、流式传输、上下文管理等核心工程能力。理解其基于HMAC-SHA384的动态签名机制和SSE流式响应原理,是保障高可用与低延迟的基础;技术价值体现在将不稳定的远程服务转化为可控、可观测、可运维的系统组件;典型应用场景包括智能客服、会议纪要生成、内部知识问答等需实时交互与成本敏感的业务;本文聚焦星火大模型API接入中的鉴权失效、流式卡顿、超时抖动等高频问题,提供经阿里云真实集群验证的SDK封装策略、连接池配置与token精细化管控方案。 阅读详情

相关推荐

SpringBoot接入讯飞星火大模型:构建智能数据分析助手的完整实战

在Java后端开发中,如何将大模型能力无缝集成到业务系统,是当前企业级应用的热点问题。大模型API的接入涉及鉴权、流式响应、结构化输出解析等关键技术,而SpringBoot凭借其成熟的生态与分层架构,成为连接AI能力与传统数据服务的理想桥梁。本文从大模型API的基础调用原理出发,讲解WebSocket鉴权机制、请求封装与流式数据接收的核心方法,并深入探讨如何通过提示词工程让模型生成可执行的SQL查询,进而实现自然语言驱动的智能数据分析。该方案不仅适用于构建企业内部的AI数据分析助手,也为大模型在Java项目

weixin_33462927的博客 251

如何提供流式(chunked)接口

springboot、egg(node)实现chunked接口创建,使用nginx进行转发,给前端应用提供chunked接口。实现实时数据接受、大接口及时响应等场景

kan进博客 4078

从零接入讯飞星火大模型API:实战指南与避坑详解

大语言模型(LLM)通过海量数据训练,具备了强大的自然语言理解和生成能力,其核心原理是基于Transformer架构的深度神经网络。这项技术的价值在于能够将通用智能能力以API形式输出,极大降低了AI应用开发门槛。在智能客服、内容创作、代码生成等应用场景中,开发者可通过集成大模型API快速构建智能功能。本文以讯飞星火大模型为例,详细解析其API的**签名认证**机制与**流式响应**实现,指导开发者从密钥申请、环境配置到实战集成的完整流程,帮助读者高效、稳定地将大模型能力接入自有项目。

weixin_29032337的博客 256

项目接入星火认知大模型!!!

下载该项目到讯飞开发平台注册账户,这样可以添加应用到讯飞控制台添加一个应用,这样可以获取 APPID,APISecret,APIKey等打开我们项目修改xinghuodemo/main.js中的代码,填写自己的APPID,APISecret,APIKey然后执行下面指令然后访问地址,可以开始使用啦。

redrun博客 3177

从零接入讯飞星火大模型API:Python实战指南与避坑手册

大语言模型(LLM)通过API接口为开发者提供了强大的自然语言处理能力,其核心原理是基于海量数据训练的深度神经网络,能够理解和生成类人文本。这项技术的价值在于极大降低了AI应用开发门槛,使开发者无需掌握复杂的模型训练细节,即可快速集成智能对话、文本生成与代码补全等功能,广泛应用于聊天机器人、内容创作与编程辅助等场景。本文聚焦于国内领先的讯飞星火大模型,详细解析其API的鉴权机制、WebSocket连接以及使用Python库sparkai进行高效集成的完整流程,涵盖从环境配置、密钥安全到流式对话与Web应用部

weixin_29054195的博客 324

SpringBoot集成讯飞星火API:打造自然语言数据分析助手实战

随着大模型技术走向落地,如何将自然语言理解能力与现有Java后端架构结合,成为企业智能化升级的关键课题。以SpringBoot为代表的Java生态具备成熟的权限体系、数据源管理和服务治理能力,非常适合承接大模型API的集成工作。通过HTTP接口鉴权、请求签名、动态URL生成等机制,开发者可以安全地调用讯飞星火大模型API,并借助提示词编排与JSON结构化输出约束,将模糊的自然语言问题转化为可执行的查询意图。配合SSE流式推送与异步任务设计,系统能够在无阻塞的前提下实现边生成边返回的交互体验,显著降低数据查询

weixin_31155097的博客 68

GPT-WEB-JAVA多模型支持:星火大模型、Kimi Chat与Bard集成终极指南

想要构建一个功能强大的AI聊天机器人平台吗?GPT-WEB-JAVA作为基于JDK8的AI聊天机器人框架,不仅支持传统的ChatGPT,还集成了**星火大模型**、**Kimi Chat**和**Google Bard**三大主流AI模型,为企业级应用提供了全面的多模型支持解决方案!🚀 ## 📊 为什么选择GPT-WEB-JAVA的多模型架构? 在AI技术快速发展的今天,单一模型已经无法满

gitblog_00924的博客 737

2026 MaaS平台选型指南:API调用、私有化部署与成本对比方法

大模型技术持续演进,MaaS平台已成为企业接入AI能力的核心入口。所谓MaaS(模型即服务),就是将模型服务、API调用与底层算力封装为标准化能力,让开发者无需关注复杂基础设施,即可快速构建智能应用。其技术价值在于通过统一协议与弹性架构,降低模型集成门槛,提升系统扩展性。在智能客服、知识问答、代码生成、文档处理等典型场景中,如何挑选合适的模型服务,往往决定业务落地成效。然而,平台间的接口兼容性、私有化部署条件、调用成本与限流策略差异显著,单纯对比模型参数难以支撑真实选型。从更全面的技术视角出发,本文通过实际

weixin_33769125的博客 345

星火大模型API接入实战:构建高可用AI网关的5个生死线

大模型API接入不是简单调用,而是涉及认证、协议、语义三层契约的系统工程。其核心原理在于Token生命周期管理、HTTP流式响应(SSE)的字节级解析、强约束请求体校验与错误码语义化封装。技术价值体现在保障生产环境稳定性、规避密钥泄露风险、实现毫秒级容错及统一限流审计。典型应用场景包括教育智能批改、政务知识问答、制造业语义检索等需私有化集成AI能力的业务系统。本文聚焦科大讯飞星火V3.5 API,深入解析FastAPI网关实现中Token自动续期、SSE安全拼接、Pydantic字段强校验等关键实践。

dianqi0560的博客 384

星火认知大模型API接入Python教程,中文回答效果非常友好

星火认知大模型API接入Python教程,中文回答效果非常友好

全栈川川 9219

Java接入讯飞语音转文字:WebSocket实时流式接口全解析

语音识别技术是人工智能领域的重要分支,它让机器能够将人类语音转化为可处理的文本数据。在众多实现方案中,基于WebSocket的实时流式语音转文字技术,凭借低延迟、高实时性的优势,成为语音对话、会议纪要、客服质检等场景的首选。其核心原理包括音频数据分帧传输、服务端流式解码以及基于HMAC-SHA256的鉴权机制,确保数据传输的安全与稳定。对于Java开发者而言,理解这些底层机制,并借助成熟的WebSocket客户端库,可以高效地集成语音识别能力。本文将围绕讯飞开放平台的语音转文字接口,从环境准备、鉴权URL生

weixin_32050773的博客 237

GPT-WEB-JAVA流式对话技术:SSE与WebSocket实现详解

想要打造一个实时流畅的AI聊天机器人体验吗?GPT-WEB-JAVA项目通过**SSE流式对话技术**和**WebSocket实时通信**,为用户提供了无缝的AI交互体验。本文将深入解析这个基于Java 8的智能聊天机器人项目如何实现高效的流式响应,让您轻松理解现代AI应用的核心通信机制。 ## 📊 为什么需要流式对话技术? 传统的AI对话系统通常采用请求-响应模式,用户需要等待AI完全生成

gitblog_00716的博客 386

C#快速对接讯飞星火API的可运行工程模板(含密钥配置与请求示例)

直接下载就能跑的C#项目,封装了讯飞星火大模型官方API调用逻辑,支持文本生成、智能问答等基础能力。项目结构完整:包含Program.cs主入口、ceshidemo.csproj工程文件、.gitignore和.vscode配置,以及清晰的使用说明.txt和readme.txt文档。开发者只需在讯飞开放平台注册账号、创建应用并获取AppID、APIKey、APISecret三项凭证,填入代码中指定位置,即可发起HTTP请求并解析JSON响应。整个流程覆盖签名生成(HMAC-SHA256)、WebSocket

banana的博客 252

解构星火认知大模型http协议调用demo代码-spark x2

通过分析这段代码,我们可以提炼出构建一个功能完整的大模型应用所必需的核心知识体系。这段代码虽然不长,但堪称“麻雀虽小,五脏俱全”。它浓缩了从API鉴权到流式交互,再到对话状态管理的一整套大模型应用开发范式。深入理解它,你就掌握了构建一个专业级AI对话应用的底层逻辑和核心方法论,为探索更复杂的应用场景打下了坚实的基础。

Liuwenqia的博客 589

讯飞星火大模型的Java SDK 易使用、开箱即用、支持异常、输出、会话结束、会话结束Token信息返回等多种自定义回调处理

讯飞星火大模型的Java SDK。易使用、开箱即用、支持异常、输出、会话结束、会话结束Token信息返回等多种自定义回调处理。

大模型越狱指令数据集全解析:从AdvBench到HarmBench

本文全面解析了AdvBench、HarmBench等主流大模型越狱指令数据集。AdvBench作为基础测试集,用于快速评估模型安全基线;HarmBench则以其全面的文本、多模态及对抗性攻击评估,成为当前权威的深度安全审计工具。文章还介绍了MaliciousInstruct、JailbreakBench等特色数据集,并提供了根据实际场景选择与使用这些数据集的具体实战指南。

weixin_29327525的博客 616

Dify + FastAPI + 讯飞WebSocket实现方言识别

本文介绍如何利用Dify平台和讯飞方言识别API构建方言语音转写服务。系统采用FastAPI作为中转层,实现音频格式转换(PCM)和WebSocket协议适配,解决大模型方言识别难题。通过Docker容器化部署,实现与Dify平台的无缝集成。

weixin_62934777的博客 820

100kHz手持LCR表设计:高频阻抗测量与校准实战解析

阻抗测量是电子元件测试的基础,LCR表通过施加正弦激励并分析电压电流的幅值与相位,即可获取电容、电感、电阻的等效参数。在开关电源、无线充电等高频应用场景中,元件在100kHz下的ESR和阻抗特性尤为关键,传统10kHz手持仪表难以满足需求。本文从自动平衡桥原理出发,探讨如何将台式电桥的核心能力浓缩至手持设备,重点剖析高频寄生参数抑制、模拟链路设计、数字相敏检波算法及开路短路校准方法。通过实测数据验证,在100kHz频率下基本精度可达0.5%以内,为维修现场、产线抽检及硬件调试提供了可携带的精密测量方案。全文

weixin_33910191的博客 397

微信消息防撤回:RevokeMsgPatcher 安装与回滚实操指南

RevokeMsgPatcher 是一个 Windows 桌面工具,用于修改 PC 版微信(以及 QQ、TIM)的核心 DLL 文件,使已撤回的消息仍能在本地聊天窗口中显示。它适合需要保留完整聊天记录存档的开发者或办公用户;不适合对二进制文件完全无兴趣、只希望"装完即忘"的场景——微信每次大版本更新后你都需要重新打补丁。 ## 场景切入 工作群里,组长发了一条文件下载链接,三秒后撤回。朋友转发

gitblog_00803的博客 383

运算放大器电路仿真实践:从零实现完整示例

通过一个完整的运算放大器电路仿真示例,深入掌握电路仿真的关键步骤与技巧,帮助电子爱好者和工程师快速上手实际项目设计。

weixin_34725745的博客 1318

ardupilot 为什么要采样四元数姿态控制

本节主要说明清楚ardupilot姿态控制为什么要用到四元数,欢迎批评指正!!!

陌城烟雨 1117

astronAgent 完整部署实战指南:Casdoor 认证、RagFlow 知识库与核心服务集群的 Docker Compose 编排

本指南围绕 [docs/zh/DEPLOYMENT_GUIDE.md](https://link.gitcode.com/i/25e4ca171f7222b2ea86654bf14db4a6) 的完整部署流程展开,系统讲解 astronAgent 企业级 Agent 工作流平台的三大组件——Casdoor 身份认证、RagFlow 知识库与 astronAgent 核心业务服务集群——的启动顺序、

gitblog_00281的博客 1055

AI Agent Harness Engineering 的“热插拔”能力:模块化设计思路

本文我会结合我在大厂做AI Agent平台的实战经验,从核心概念、架构设计、代码实现、落地实战多个维度,给大家详细讲解AI Agent Harness Engineering的核心能力——热插拔的模块化设计思路。我们会从问题根源出发,一步步搭建一个完整的支持热插拔的Agent Harness框架,包含组件抽象、注册中心、生命周期管理、配置驱动、容错机制等核心模块。

AI天才研究院 501
上一篇: 分布式算法(五):初识ZAB协议
下一篇: 使用Spring boot的@Transactional进行事务管理
TracyCoder123
博客等级 码龄8年 1万+粉丝 226原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

TracyCoder123

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值