当前位置: 首页 > news >正文

spring-ai

https://github.com/chatanywhere/GPT_API_free

文章目录

    • pom.xml
    • OpenAiApp
    • AiController
    • application.yml

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>

    <parent>
        <artifactId>spring-boot-dependencies</artifactId>
        <groupId>org.springframework.boot</groupId>
        <version>3.2.4</version>
    </parent>

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

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.ai</groupId>
            <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
            <version>1.0.0-M6</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.20</version>
        </dependency>
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>5.8.10</version>
        </dependency>

    </dependencies>

</project>

OpenAiApp

@SpringBootApplication
public class OpenAiApp {
    public static void main(String[] args) {
       SpringApplication.run(OpenAiApp.class, args);
    }
}

AiController

package com.zzhua.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/*

转发Host1: https://api.chatanywhere.tech (国内中转)
转发Host2: https://api.chatanywhere.org (国外使用)
*/
@Controller
public class AiController {

    @Autowired
    private ChatClient.Builder builder;

    @RequestMapping("test01")
    @ResponseBody
    public String test01(@RequestParam("prompt") String prompt) {
        ChatClient chatClient = builder.build();
        String response = chatClient.prompt(prompt).call().content();
        return response;
    }

    @RequestMapping(value = "test02", produces = "text/event-stream")
    @ResponseBody
    public Flux<String> test02(@RequestParam("prompt") String prompt, HttpServletResponse response) {
        response.setCharacterEncoding("utf-8");
        ChatClient chatClient = builder.build();
        Flux<String> flux = chatClient.prompt(prompt).stream().content();
        // flux.subscribe(System.out::println);
        return flux;
    }

}

application.yml

spring:
  ai:
    openai:
      # base-url: https://api.chatanywhere.tech
      # base-url: https://api.chatanywhere.org
      base-url: https://api.deepseek.com
      api-key: sk-xxx
      chat:
        options:
          # model: gpt-3.5-turbo
          model: deepseek-reasoner
          # model: deepseek-chat

相关文章:

  • 基于自监督三维语义表示学习的视觉语言导航
  • linux系统下openwebui重启并使用本地模型(vllm或其他)
  • 江科大51单片机笔记【10】蜂鸣器播放提示器音乐(下)
  • 【无标题】四色拓扑模型与宇宙历史重构的猜想框架
  • 第4章 Function 语意学1: Member的各种调用方式
  • nginx配置反向代理服务器,实现在https网站中请求http资源
  • Redis数据结构,渐进式遍历,数据库管理
  • Ubuntu20.04本地配置IsaacGym Preview 4的G1训练环境(二):训练与推理
  • [Java基础-线程篇]7_线程设计模式与总结
  • MCU-SDRAM-W9825G6KH的存储单元
  • Vue 文件下载功能的跨域处理与前后端实现详解
  • python: DDD using postgeSQL and SQL Server
  • 【STM32】STM32系列产品以及新手入门的STM32F103
  • 深度学习PyTorch之13种模型精度评估公式及调用方法
  • 头歌作业-数据库实验一:数据库和数据表的建立,修改和删除
  • 大模型——使用 Embedding 模型和向量数据库的 Spring AI RAG
  • Linux下磁盘读写流
  • 《几何原本》命题I.12
  • API和SDK
  • 护照阅读器在汽车客运站流程中的应用
  • 云南工程建设信息网站/产品线上营销有哪些方式
  • 南部县人民医院皮肤科/网站seo是什么
  • 济南网站推广公司/谷歌搜索引擎为什么国内用不了
  • 深圳网站建设jm3q/关键词歌词打印
  • 超越时空网上书城网站建设方案/专业网站快速
  • 大型集团网站建设/优化方案模板