Bladeren bron

init finish!

yangyi 7 maanden geleden
commit
139ef38eba

+ 35 - 0
.gitignore

@@ -0,0 +1,35 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/**/*
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store

+ 32 - 0
pom.xml

@@ -0,0 +1,32 @@
+<?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>space.anyi</groupId>
+    <artifactId>SpringAiAlibaba-learn</artifactId>
+    <version>1.0-SNAPSHOT</version>
+    <description>学习Spring AI Alibaba的项目</description>
+
+    <properties>
+        <maven.compiler.source>21</maven.compiler.source>
+        <maven.compiler.target>21</maven.compiler.target>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    </properties>
+
+    <dependencies>
+        <!-- Source: https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+            <version>3.5.10</version>
+        </dependency>
+        <dependency>
+            <groupId>org.springframework.ai</groupId>
+            <artifactId>spring-ai-starter-model-openai</artifactId>
+            <version>1.1.2</version>
+        </dependency>
+    </dependencies>
+
+</project>

+ 12 - 0
src/main/java/space/anyi/springAiAlibabaLearn/Application.java

@@ -0,0 +1,12 @@
+package space.anyi.springAiAlibabaLearn;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.ConfigurableApplicationContext;
+
+@SpringBootApplication
+public class Application {
+    public static void main(String[] args) {
+        ConfigurableApplicationContext applicationContext = SpringApplication.run(Application.class, args);
+    }
+}

+ 28 - 0
src/main/java/space/anyi/springAiAlibabaLearn/controller/HelloController.java

@@ -0,0 +1,28 @@
+package space.anyi.springAiAlibabaLearn.controller;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.ai.chat.model.ChatModel;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+public class HelloController {
+    private final Logger log = LoggerFactory.getLogger(HelloController.class);
+    private final ChatModel chatModel;
+
+    public HelloController(ChatModel chatModel) {
+        this.chatModel = chatModel;
+    }
+
+    @GetMapping("/hello")
+    public String hello(){
+        return "hello";
+    }
+    @GetMapping("/chat")
+    public String chat(@RequestParam("message") String message){
+        log.debug("message:{}",message);
+        return chatModel.call(message);
+    }
+}

+ 17 - 0
src/main/resources/application.yaml

@@ -0,0 +1,17 @@
+server:
+  servlet:
+    port: 8080
+spring:
+  application:
+    name: 学习Spring AI Alibaba的项目
+  ai:
+    openai:
+      api-key: ${QWEN_APIKEY}
+      base-url: https://dashscope.aliyuncs.com/compatible-mode
+      chat:
+        completions-path: /v1/chat/completions
+        options:
+          model: qwen-flash
+logging:
+  level:
+    root: DEBUG