spring-ai-zhipuai

Configure ZhipuAI, apply Swagger, and run tests in Spring AI projects

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "spring-ai-zhipuai" with this command: npx skills add hwiesung/spring-ai-zhipuai/hwiesung-spring-ai-zhipuai-spring-ai-zhipuai

Spring AI ZhipuAI & Swagger Configuration Skill

This skill automates migrating Spring AI projects to ZhipuAI and configuring Swagger.

Prerequisites

  • Kotlin-based Spring Boot project
  • Gradle (Kotlin DSL recommended)
  • JDK 21 or higher
  • ZhipuAI API Key (obtain from ZhipuAI Platform)

Steps

1. Install/Update Gradle Wrapper (Run First!)

⚠️ Important: This step must be executed first. The build will fail without Gradle Wrapper.

# Navigate to the folder containing the nearest gradle configuration file (build.gradle.kts or build.gradle)
cd path/to/project
gradle wrapper --gradle-version=8.12

Verification:

  • Check if gradle/wrapper/gradle-wrapper.jar exists
  • Verify gradlew, gradlew.bat scripts are executable

2. Modify build.gradle.kts

JDK 21 Configuration:

java {
    toolchain {
        languageVersion = JavaLanguageVersion.of(21)
    }
}

Add Spring AI ZhipuAI Dependency:

dependencies {
    // Spring AI ZhipuAI (replace existing Ollama/OpenAI dependency)
    implementation("org.springframework.ai:spring-ai-starter-model-zhipuai:1.1.2")

    // Swagger (SpringDoc OpenAPI) - Compatible with Spring Boot 3.3.x
    implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0")
}

Kotlin JVM Target Configuration:

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs = listOf("-Xjsr305=strict")
        jvmTarget = "21"
    }
}

3. Configure application.yml

spring:
  ai:
    zhipuai:
      api-key: ${ZHIPUAI_API_KEY} # or enter directly
      chat:
        options:
          model: glm-4.7-flash # or glm-4-air, glm-4.5, glm-4.6
          temperature: 0.7

# SpringDoc OpenAPI (Swagger)
springdoc:
  api-docs:
    path: /api-docs
  swagger-ui:
    path: /swagger-ui.html
    tags-sorter: alpha
    operations-sorter: alpha

4. Add Swagger Annotations (with Testable Example Data)

💡 Example Data Guidelines: Reference *.http files if available. Otherwise, refer to Controller comments (e.g., POST http://localhost:8080/api/xxx Body: {...}) or generate appropriate example data based on API logic.

Add @Schema to Model Classes (with example data):

import io.swagger.v3.oas.annotations.media.Schema

@Schema(description = "AI 파싱 요청")
data class ParseRequest(
    @Schema(
        description = "AI에게 질문할 내용",
        example = "5가지 프로그래밍 언어를 나열해주세요",
        required = true
    )
    val question: String
)

@Schema(description = "카테고리 항목")
data class CategoryItem(
    @Schema(description = "카테고리 이름", example = "프로그래밍 언어")
    val name: String,
    @Schema(description = "항목 목록", example = "[\"Python\", \"Java\", \"JavaScript\"]")
    val items: List<String>
)

Add @Tag, @Operation to Controllers:

import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag

@RestController
@RequestMapping("/api/example")
@Tag(name = "Example API", description = "예제 API 설명")
class ExampleController {

    @Operation(
        summary = "기능 요약",
        description = "상세 설명"
    )
    @PostMapping("/endpoint")
    fun example(@RequestBody request: ParseRequest): Map<String, Any> {
        // ...
    }
}

Example Data Format Tips:

Field TypeExample Format
Stringexample = "text value"
Int/Longexample = "123"
Booleanexample = "true"
Listexample = "[\"item1\", \"item2\"]"
Objectexample = "{\"key\": \"value\"}"

5. Build and Test

# Build test
./gradlew clean build -x test

# Run unit tests
./gradlew test

# Run application
./gradlew bootRun
# Or pass API Key via environment variable
ZHIPUAI_API_KEY=your-api-key ./gradlew bootRun

6. Verification

Testing in Swagger UI:

  1. Access Swagger UI
  2. Select API to test
  3. Click "Try it out" button
  4. Verify example data is auto-filled
  5. Click "Execute" button to test

HTTP Test:

curl -X POST http://localhost:8080/api/client/list/parse \
  -H "Content-Type: application/json" \
  -d '{"question": "5가지 프로그래밍 언어를 나열해주세요"}'

Version Compatibility

ComponentRecommended Version
Spring Boot3.3.x
Spring AI1.1.2
SpringDoc OpenAPI2.5.0
Gradle8.12+
JDK21

ZhipuAI Model Options

Model NameDescription
glm-4.7-flashFast response, general purpose
glm-4-airLightweight model
glm-4.5Standard performance
glm-4.6Enhanced performance

Troubleshooting

Gradle Wrapper Missing (GradleWrapperMain ClassNotFoundException)

# Error: java.lang.ClassNotFoundException: org.gradle.wrapper.GradleWrapperMain
# Solution: Regenerate gradle wrapper
gradle wrapper --gradle-version=8.12

Port Already in Use

lsof -ti:8080 | xargs kill -9

SpringDoc Compatibility Error

  • Use springdoc-openapi-starter-webmvc-ui:2.5.0 for Spring Boot 3.3.x
  • Version 2.8.x causes compatibility issues (LiteWebJarsResourceResolver ClassNotFoundException)

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

Csv Analyzer Cn

CSV数据分析工具。数据统计摘要、SVG图表生成、条件筛选、文件合并、数据清洗、格式转换(JSON/HTML/Markdown/SQL)、HTML分析报告。CSV analyzer with stats, SVG charts, filtering, merging, cleaning, format conve...

Registry SourceRecently Updated
General

Tripit Calendar

Read upcoming TripIt travel plans from a TripIt iCal feed; use for next trip, upcoming travel, itinerary, flight or hotel bookings already in TripIt; do not...

Registry SourceRecently Updated
General

Css Helper

CSS代码生成助手。Flexbox布局、Grid布局、CSS动画、渐变色、阴影、响应式断点。CSS helper for flexbox, grid, animation, gradient, shadow, responsive breakpoints. Use when you need css helper...

Registry SourceRecently Updated
General

pdf-to-word

�� PDF �ļ�ת��Ϊ Word �ĵ���.docx��

Registry SourceRecently Updated