1 Star 4 Fork 2

dino9527/spring-ai-examples

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

Spring AI with QIANFAN

This project is a Spring Boot application that demonstrates the integration of an AI chat client using the Spring AI framework. The application provides several endpoints to interact with the AI chat client.

Project Structure

  • Java: The primary programming language used.
  • Maven: Build and dependency management tool.
  • Spring Boot: Framework for building the application.

Configuration

application.yml

The application.yml file contains the configuration for the server and the AI chat client, including retry settings and API keys.

server:
  port: 8888
spring:
  ai:
    retry:
      max-attempts: 3
      backoff:
        initial-interval: 5000ms
        multiplier: 5
        max-interval: 180000ms
      on-client-errors: true
    qianfan:
      api-key: YOUR_API_KEY
      secret-key: YOUR_SECRET_KEY
      chat:
        enabled: true
        options:
          model: yi_34b_chat
          temperature: 0.7
          top-p: 0.9

Endpoints

/chat/ai/simple

Returns a simple chat completion.

  • Method: GET
  • Parameters: message (default: "给我讲个笑话")
  • Response: JSON with the completion message.

/chat/ai/simple2

Returns a chat completion with a specified voice.

  • Method: GET
  • Parameters: message (default: "给我讲个笑话"), voice
  • Response: JSON with the completion message.

/chat/ai/stream

Streams the chat completion.

  • Method: GET
  • Parameters: message (default: "给我讲个笑话"), voice
  • Response: Text event stream.

/chat/ai/actor

Generates the filmography for a random actor.

  • Method: GET
  • Parameters: message (default: "Generate the filmography for a random actor")
  • Response: JSON with the actor's filmography.

/chat/ai/actor2

Generates the filmography of 5 movies for Tom Hanks and Bill Murray.

  • Method: GET
  • Parameters: message (default: "Generate the filmography of 5 movies for Tom Hanks and Bill Murray.")
  • Response: JSON with the filmographies.

/chat/ai/actor3

Generates the filmography for a random actor with a custom format.

  • Method: GET
  • Parameters: message (default: "Generate the filmography for a random actor.")
  • Response: JSON with the actor's filmography.

/chat/ai/context

Maintains a conversation context with the AI.

  • Method: GET
  • Parameters: prompt
  • Response: The AI's response message.

Running the Application

  1. Clone the repository.
  2. Update the application.yml file with your API key and secret key.
  3. Build the project using Maven:
    mvn clean install
    
  4. Run the application:
    mvn spring-boot:run
    

License

This project is licensed under the MIT License.

MIT License Copyright (c) 2024 dino9527 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Spring AI 示例 展开 收起
Java
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/dino9527/spring-ai-examples.git
git@gitee.com:dino9527/spring-ai-examples.git
dino9527
spring-ai-examples
spring-ai-examples
master

搜索帮助