Selaa lähdekoodia

Merge branch 'master' of http://47.121.25.205:3000/tanlie/spring-ai

tanlie 1 vuosi sitten
vanhempi
säilyke
827c404f6b

+ 24 - 1
chatgpt/pom.xml

@@ -22,7 +22,7 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
-       <dependency>
+        <dependency>
             <groupId>org.springframework.ai</groupId>
             <artifactId>spring-ai-openai-spring-boot-starter</artifactId>
         </dependency>
@@ -48,6 +48,19 @@
             <artifactId>spring-boot-starter-test</artifactId>
             <scope>test</scope>
         </dependency>
+        <!--fastjson-->
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>2.0.32</version>
+        </dependency>
+        <!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all -->
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.8.32</version>
+        </dependency>
+
     </dependencies>
     <dependencyManagement>
         <dependencies>
@@ -67,6 +80,16 @@
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
             </plugin>
+            <plugin>
+                <groupId>io.github.git-commit-id</groupId>
+                <artifactId>git-commit-id-maven-plugin</artifactId>
+                <version>9.0.0</version>
+                <configuration>
+                    <generateGitPropertiesFile>true</generateGitPropertiesFile>
+                    <format>json</format>
+                    <commitIdGenerationMode>full</commitIdGenerationMode>
+                </configuration>
+            </plugin>
         </plugins>
     </build>
     <repositories>

+ 33 - 0
chatgpt/src/main/java/cn/qinys/ai/chatgpt/envetlistner/ApplicationStartEventListener.java

@@ -0,0 +1,33 @@
+package cn.qinys.ai.chatgpt.envetlistner;
+
+import lombok.val;
+import org.springframework.boot.context.event.ApplicationStartedEvent;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.ConfigurableApplicationContext;
+import org.springframework.core.env.Environment;
+import org.springframework.stereotype.Component;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+/**
+ * description:
+ *
+ * @author: tanlie
+ * @date: 2024/10/1
+ */
+@Component
+public class ApplicationStartEventListener implements ApplicationListener<ApplicationStartedEvent> {
+    @Override
+    public void onApplicationEvent(ApplicationStartedEvent event) {
+        ConfigurableApplicationContext context = event.getApplicationContext();
+        try {
+            System.err.println(InetAddress.getLocalHost().getHostAddress());
+        } catch (UnknownHostException ignored) {
+        }
+        Environment env = context.getEnvironment();
+        System.err.println(env.getProperty("server.port"));
+        System.err.println(env.getProperty("spring.application.name"));
+        System.err.println(event.getTimeTaken().getSeconds());
+    }
+}

+ 0 - 0
chatgpt/src/main/resources/META-INF/spring.factories


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

@@ -1,4 +1,8 @@
+server:
+  port: 8080
 spring:
+  application:
+    name: ai-application
   ai:
     openai:
       api-key: sk-71RyBMlhwTDKC5jABYdYkN0e6QAiFGJ01RW5oAKBTrIKRQGd

+ 33 - 0
chatgpt/src/test/java/cn/qinys/ai/chatgpt/controller/MessageControllerTest.java

@@ -0,0 +1,33 @@
+package cn.qinys.ai.chatgpt.controller;
+
+import cn.hutool.core.io.file.FileReader;
+import com.alibaba.fastjson2.JSON;
+import com.alibaba.fastjson2.JSONObject;
+import org.junit.jupiter.api.Test;
+
+import java.nio.charset.StandardCharsets;
+
+/**
+ * description:
+ *
+ * @author: tanlie
+ * @date: 2024/10/1
+ */
+class MessageControllerTest {
+
+    @Test
+    void test1() {
+    }
+
+
+    @Test
+    void readGitProperties() {
+        FileReader fileReader = new FileReader("git.properties", StandardCharsets.UTF_8);
+        String result = fileReader.readString();
+        //JSONObject jsonObject = JSON.parseObject(result);
+        //中文好像不行。
+        System.err.println(result);
+
+
+    }
+}