tanlie hai 1 ano
pai
achega
22fcb58a17

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
+.idea/
+chatgpt/target/

+ 79 - 0
chatgpt/pom.xml

@@ -0,0 +1,79 @@
+<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.springframework.boot</groupId>
+        <artifactId>spring-boot-starter-parent</artifactId>
+        <version>3.2.5</version>
+        <relativePath/> <!-- lookup parent from repository -->
+    </parent>
+    <groupId>cn.qinys.ai</groupId>
+    <artifactId>chatgpt</artifactId>
+    <version>0.0.1</version>
+    <name>chatgpt</name>
+    <description>Demo project for Spring Boot</description>
+    <properties>
+        <java.version>17</java.version>
+        <spring-ai.version>0.8.1</spring-ai.version>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+       <dependency>
+            <groupId>org.springframework.ai</groupId>
+            <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-devtools</artifactId>
+            <scope>runtime</scope>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
+    <dependencyManagement>
+        <dependencies>
+            <dependency>
+                <groupId>org.springframework.ai</groupId>
+                <artifactId>spring-ai-bom</artifactId>
+                <version>${spring-ai.version}</version>
+                <type>pom</type>
+                <scope>import</scope>
+            </dependency>
+        </dependencies>
+    </dependencyManagement>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+        </plugins>
+    </build>
+    <repositories>
+        <repository>
+            <id>spring-milestones</id>
+            <name>Spring Milestones</name>
+            <url>https://repo.spring.io/milestone</url>
+            <snapshots>
+                <enabled>false</enabled>
+            </snapshots>
+        </repository>
+    </repositories>
+
+</project>

+ 14 - 0
chatgpt/src/main/java/cn/qinys/ai/ChatApplication.java

@@ -0,0 +1,14 @@
+package cn.qinys.ai;
+
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class ChatApplication {
+
+    public static void main(String[] args) {
+        SpringApplication.run(ChatApplication.class, args);
+    }
+
+}

+ 29 - 0
chatgpt/src/main/java/cn/qinys/ai/chatgpt/controller/MessageController.java

@@ -0,0 +1,29 @@
+package cn.qinys.ai.chatgpt.controller;
+
+import cn.qinys.ai.chatgpt.req.MsgReq;
+import jakarta.annotation.Resource;
+import org.springframework.ai.openai.OpenAiChatClient;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * description:
+ *
+ * @author: tanlie
+ * @date: 2024/5/12
+ */
+@RestController
+@RequestMapping("/openai")
+public class MessageController {
+
+    @Resource
+    private OpenAiChatClient openAiChatClient;
+
+    @PostMapping("/test")
+    public String test(@RequestBody MsgReq req){
+        String result = openAiChatClient.call(req.getMsg());
+        return result;
+    }
+}

+ 17 - 0
chatgpt/src/main/java/cn/qinys/ai/chatgpt/req/MsgReq.java

@@ -0,0 +1,17 @@
+package cn.qinys.ai.chatgpt.req;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * description:
+ *
+ * @author: tanlie
+ * @date: 2024/5/12
+ */
+@Data
+public class MsgReq implements Serializable {
+
+    private String msg;
+}

+ 5 - 0
chatgpt/src/main/resources/application.yml

@@ -0,0 +1,5 @@
+spring:
+  ai:
+    openai:
+      api-key: sk-zCUZT5DJCnAubc10517470Ce06C544Bd8a7c3726608517Fe
+      base-url: https://api.pumpkinaigc.online