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

Chronos

通用周期任务管理器 - 支持6种周期类型、每月N次配额、自动cron、统一视图,适用于所有定时任务场景

Registry SourceRecently Updated
General

Football

Analyze football and soccer matches, squads, players, and training plans with tactical frameworks, scouting grids, and session blueprints.

Registry SourceRecently Updated
General

Cctv News Fetcher Litiao

Fetch and parse news highlights from CCTV News Broadcast (Xinwen Lianbo) for a given date.

Registry SourceRecently Updated
General

WeRead Book Finder

输入图书名称,优先在微信读书搜索并加入书架;若微信读书没有可信命中或无法加入书架,则自动回退到 Z-Library 搜索并优先下载非 PDF 格式。适用于“把《xxx》加入微信读书书架,不行就去 Z-Library 下载”这类请求。

Registry SourceRecently Updated