Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release 0.0.2 #209

Open
wants to merge 7 commits into
base: dipper
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
node_modules
package-lock.json
./index.py
.vscode
target
.vscode
25 changes: 25 additions & 0 deletions web-framework/java/springai/hook/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
async function preInit(inputObj) {
console.log(`
Serverless Devs Application Case

Cloud services required:
- FC : https://fc.console.aliyun.com/

Tips:
- FC3 Component: https://docs.serverless-devs.com/user-guide/aliyun/#fc3`)

}

async function postInit(inputObj) {
console.log(`
* Before using, please check whether the actions command in Yaml file is available
* Carefully reading the notes in s.yaml is helpful for the use of the tool
* Recommended Python version: python3.7;
* If need help in the use process, please apply to join the Dingtalk Group: 33947367
`)
}

module.exports = {
postInit,
preInit
}
65 changes: 65 additions & 0 deletions web-framework/java/springai/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
Edition: 3.0.0
Type: Project
Name: start-springaialibaba-hk-cap
Provider:
- 阿里云
Version: 0.0.2
Description: 本案例提供了一个基于 Spring AI Alibaba 框架开发的 AI 智能机票助手,您可以将应用部署到阿里云函数计算 FC 上快速体验运行效果。
HomePage: https://github.com/chickenlj/start-web-framework/tree/dipper/web-framework/java/springai
Organization: 阿里云函数计算(FC)
Effective: Public
Tags:
- Web框架
- Spring Boot
- Custom Runtime
Category: Web框架
Service:
函数计算:
Authorities:
- AliyunFCFullAccess
Parameters:
type: object
additionalProperties: false # 不允许增加其他属性
required: # 必填项
- region
- functionName
- apiKey
properties:
region:
title: 地域
type: string
default: cn-hangzhou
description: 创建应用所在的地区
enum:
- cn-beijing
- cn-hangzhou
- cn-shanghai
- cn-qingdao
- cn-zhangjiakou
- cn-huhehaote
- cn-shenzhen
- cn-chengdu
- cn-hongkong
- ap-southeast-1
- ap-southeast-2
- ap-southeast-3
- ap-southeast-5
- ap-northeast-1
- ap-northeast-2
- eu-central-1
- eu-west-1
- us-west-1
- us-east-1
- ap-south-1
functionName:
title: 函数名
type: string
default: springai-${default-suffix}
pattern: "^[a-zA-Z_][a-zA-Z0-9-_]{0,127}$"
description: 函数名称,只能包含字母、数字、下划线和中划线。不能以数字、中划线开头。长度在 1-128 之间
apiKey:
title: 访问模型的API-KEY
type: string
default: ""
pattern: "^[a-zA-Z_][a-zA-Z0-9-_]{0,127}$"
description: "请访问阿里云百炼模型服务平台了解如何获取API-KEY,https://help.aliyun.com/zh/model-studio/developer-reference/get-api-key"
82 changes: 82 additions & 0 deletions web-framework/java/springai/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

> 注:当前项目为 Serverless Devs 应用,由于应用中会存在需要初始化才可运行的变量(例如应用部署地区、函数名等等),所以**不推荐**直接 Clone 本仓库到本地进行部署或直接复制 s.yaml 使用,**强烈推荐**通过 `s init ${模版名称}` 的方法或应用中心进行初始化,详情可参考[部署 & 体验](#部署--体验) 。

# start-springaialibaba-hk-cap 帮助文档

<description>

本案例提供了一个基于 Spring AI Alibaba 框架开发的 AI 智能机票助手,您可以将应用部署到阿里云函数计算 FC 上快速体验运行效果。

</description>


## 前期准备

使用该项目,您需要有开通以下服务并拥有对应权限:

<service>



| 服务/业务 | 权限 | 相关文档 |
| --- | --- | --- |
| 函数计算 | AliyunFCFullAccess | [帮助文档](https://help.aliyun.com/product/2508973.html) [计费文档](https://help.aliyun.com/document_detail/2512928.html) |

</service>

<remark>



</remark>

<disclaimers>



</disclaimers>

## 部署 & 体验

<appcenter>

- :fire: 通过 [云原生应用开发平台 CAP](https://devs.console.aliyun.com/applications/create?template=start-springaialibaba-hk-cap) ,[![Deploy with Severless Devs](https://img.alicdn.com/imgextra/i1/O1CN01w5RFbX1v45s8TIXPz_!!6000000006118-55-tps-95-28.svg)](https://devs.console.aliyun.com/applications/create?template=start-springaialibaba-hk-cap) 该应用。

</appcenter>
<deploy>


</deploy>

## 案例介绍

<appdetail id="flushContent">

本案例提供了一个基于 Spring AI Alibaba 框架开发的 AI 智能机票助手,您可以与智能助手聊天,进行机票预定、改期、退票、咨询等服务。应用底层使用阿里云通义模型服务,是一个使用了 RAG、Function Calling、ChatMemory 等核心能力的智能体应用,支持多轮聊天会话。

Spring AI Alibaba 开源项目基于 Spring AI 构建,是阿里云通义系列模型及服务在 Java AI 应用开发领域的最佳实践,提供高层次的 AI API 抽象与云原生基础设施集成方案,旨在帮助开发者快速构建 AI 应用。使用 Spring AI Alibaba 开发应用与使用普通 Spring Boot 没有什么区别,只需要增加 `spring-ai-alibaba-starter` 依赖,将 `ChatClient` Bean 注入就可以实现与模型聊天了。



</appdetail>

## 使用流程

<usedetail id="flushContent">

1. 部署完成之后,您可以看到系统返回给您的案例地址并打开示例系统。

![图片alt](https://foruda.gitee.com/images/1726307880404008922/9b99200b_1689212.png)

2. 与智能助手开始聊天,以自然语言对话的方式说出您想要的咨询的问题或要办理的业务,并等待助手回复。


</usedetail>

## 注意事项

<matters id="flushContent">

这是一个示例应用,并无法处理真正的机票业务

</matters>
55 changes: 55 additions & 0 deletions web-framework/java/springai/src/code/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# AI powered expert system demo

This app shows how you can use Spring AI Alibaba to build an AI-powered system that:

- Has access to terms and conditions (retrieval augmented generation, RAG)
- Can access tools (Java methods) to perform actions (Function Calling)
- Uses an LLM to interact with the user

![spring-ai-alibaba-flight-booking](diagram.png)

## Requirements

- Java 17+
- Dashscope API key in `AI_DASHSCOPE_API_KEY` environment variable

## Running

Run the app by running `Application.java` in your IDE or `mvn spring-boot:run` in the command line.


Add to the POM the Spring AI Alibaba boot starter:

```xml
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-alibaba-starter</artifactId>
<version>1.0.0-M3.1</version>
</dependency>
```

Add the DashScope configuration to the `application.properties`:

```
spring.ai.dashscope.api-key=${AI_DASHSCOPE_API_KEY}
spring.ai.dashscope.chat.options.model=qwen-max
```

## Build Jar

```shell
./mvnw clean package
```

```shell
java -jar ./target/playground-flight-booking-example-0.0.1-SNAPSHOT.jar
```


## Build Frontend (as needed)

Run the following command to build frontend, this is only necessary when you made changes to frontend.

```shell
mvn clean compile -Pbuild-frontend
```
Binary file added web-framework/java/springai/src/code/diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
155 changes: 155 additions & 0 deletions web-framework/java/springai/src/code/frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
## Startup

```shell
# add vite vue project
# https://vuejs.org/guide/scaling-up/tooling.html
# Vue CLI is the official webpack-based toolchain for Vue.
# It is now in maintenance mode and we recommend starting new projects with Vite unless you rely on specific webpack-only features.
# Vite will provide superior developer experience in most cases.

# note your env version
# node v18.0.0
# yarn 1.22.21

npm create vue@latest

yarn

yarn format

# run it
yarn dev


# main com
yarn add [email protected]


```

## Develop

1. todo
> if a function is not complete but show the entry in your page,
> please use notification.todo to mark it
```shell
/**
* this function is showing some tips about our Q&A
* TODO
*/
function globalQuestion() {
devTool.todo("show Q&A tips")
}
```
2. global css var
```js
// if you want use the global css var, such as primary color
// create a reactive reference to a var by 'ref'
export const PRIMARY_COLOR = ref('#17b392')

// In js
import {PRIMARY_COLOR} from '@/base/constants'

// In CSS, use __null for explicit reference to prevent being cleared by code formatting.
let __null = PRIMARY_COLOR

```

3. provide and inject



4. icon: https://icones.js.org/

```html
<Icon icon="svg-spinners:pulse-ring" />

```

5. api

> Agreement: if your api's path starts with mock, you will get a mock result

1. Declear api

```ts

import request from '@/base/http/request'

export const getClusterInfo = (params: any):Promise<any> => {
return request({
url: '/metrics/cluster',
method: 'get',
params
})
}

```



2. Declear mock api

```ts
// define a mock api
import Mock from 'mockjs'
Mock.mock('/mock/metrics/cluster', 'get', {
code: 200,
message: '成功',
data: {
all: Mock.mock('@integer(100, 500)'),
application: Mock.mock('@integer(80, 200)'),
consumers: Mock.mock('@integer(80, 200)'),
providers: Mock.mock('@integer(80, 200)'),
services: Mock.mock('@integer(80, 200)'),
versions: ["dubbo-golang-3.0.4"],
protocols: ["tri"],
rules: [],
configCenter: "127.0.0.1:2181",
registry: "127.0.0.1:2181",
metadataCenter: "127.0.0.1:2181",
grafana: "127.0.0.1:3000",
prometheus: "127.0.0.1:9090"
}
})

// import in main.ts
import './api/mock/mockCluster.js'

```

3. invoke api

```ts

onMounted(async () => {
let {data} = await getClusterInfo({})
})
```

4. decide where the request is to go : request.ts

```ts
// request.ts

const service: AxiosInstance = axios.create({
// change this to decide where to go
baseURL: '/mock',
timeout: 30 * 1000
})
```


## Build and Deploy

1. Build

```shell
yarn build
```

2. Deploy

Copy the `dist/assets` folder to the path `src/main/resources/static`
Copy the `dist/index.html` file to the path `src/main/resources/templates`

Loading