Skip to content

Commit

Permalink
Merge pull request #35 from yuluo-yx/0928-yuluo/update-example
Browse files Browse the repository at this point in the history
OSPP: Completed Spring Cloud Alibaba's Spring AI model support for Tongyi series models
  • Loading branch information
chickenlj authored Oct 28, 2024
2 parents 5b55475 + d016978 commit 2e69c39
Show file tree
Hide file tree
Showing 32 changed files with 878 additions and 13 deletions.
14 changes: 14 additions & 0 deletions spring-ai-alibaba-examples/README-zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Spring AI Alibaba Example

该目录包含演示 Spring AI Alibaba 的基本和高级用法的示例。

这里的所有示例都被设计为独立的 maven 项目,可以独立复制和导入。因此建议将整个示例目录或每个特定示例子目录作为单独的 Maven 项目导入,
以体验 Spring AI Alibaba 开发框架的能力。

* Client API 示例:此 Example 主要演示使用 Client API(高级 API) 调用模型;
* Model API 示例:此 Example 主要演示使用 Model API(低级 API) 调用模型;
* 函数调用示例:此 Example 主要演示如何使用 Function Calling 增强 LLM 能力;
* 结构化输出示例:此 Example 主要演示如何使用 Structured Output ,将 LLM 输出转为 Java Bean;
* Prompt 示例:此 Example 主要演示如何使用 Prompt Template 构建动态 Prompt 等,其他 Prompt 用法;
* RAG 示例:此 Example 演示 RAG(检索增强)应用的构建示例。
* Flight Booking Playground:一个高级示例,同时展示了 Prompt 模板、Function Calling、Chat Memory 和 RAG 的使用。
21 changes: 12 additions & 9 deletions spring-ai-alibaba-examples/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
This directory contains examples demonstrating basic and advanced usages of Spring AI Alibaba.
## Spring AI Alibaba Example

All the examples here are designed to be independent maven projects that can be copied and imported independently. So it's recommended to import the whole example directory or each specific example sub-directory as a separate maven project.
This directory contains examples that demonstrate basic and advanced usage of Spring AI Alibaba.

* Hello World
* Chat Model
* Function Calling
* Structured Output
* Prompt
* RAG
* Flight Booking Playground, an advanced example showcasing usage of prompt template, function calling, chat memory and rag at the same time.
All examples here are designed as independent Maven projects that can be copied and imported independently. Therefore, it is recommended to import the entire example directory or each specific example subdirectory as a separate Maven project,
to experience the capabilities of the Spring AI Alibaba development framework.

* Client API Example: This Example mainly demonstrates the use of Client API (advanced API) to call the model;
* Model API Example: This Example mainly demonstrates the use of Model API (low-level API) to call the model;
* Function Calling Example: This Example mainly demonstrates how to use Function Calling to enhance LLM capabilities;
* Structured Output Example: This Example mainly demonstrates how to use Structured Output to convert LLM output to Java Bean;
* Prompt Example: This Example mainly demonstrates how to use Prompt Template to build dynamic Prompt, etc., and other Prompt usage;
* RAG Example: This Example demonstrates the construction example of RAG (retrieval enhancement) application.
* Flight Booking Playground: An advanced example that also demonstrates the use of Prompt templates, Function Calling, Chat Memory, and RAG.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.alibaba.cloud.ai</groupId>
<artifactId>helloworld-example</artifactId>
<artifactId>client-api-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>helloworld-example</name>
<description>Demo project for Spring AI Alibaba</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.alibaba.cloud.ai</groupId>
<artifactId>chatmodel-example</artifactId>

<artifactId>module-api-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>chatmodel-example</name>
<description>Demo project for Spring AI Alibaba</description>
Expand Down
5 changes: 4 additions & 1 deletion spring-ai-alibaba-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
<maven-deploy-plugin.version>3.1.1</maven-deploy-plugin.version>
</properties>

<modules>
<modules>
<module>client-api-example</module>
<module>module-api-example</module>
<module>helloworld-example</module>
<module>chatmodel-example</module>
<module>multi-model-example</module>
Expand All @@ -40,6 +42,7 @@
<module>rag-example</module>
<module>output-parser-example</module>
<module>playground-flight-booking</module>
<module>usercase-example</module>
</modules>

<build>
Expand Down
139 changes: 139 additions & 0 deletions spring-ai-alibaba-examples/usercase-example/README-zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Spring AI user usage examples

## Generate SQL application

Generate query SQL statements based on parameters determined by the interface.

Usage examples are as follows:

**When the input parameter is email**

> url: http://localhost:8081/ai/sql?text="email"
```shell
$ curl http://localhost:8081/ai/sql?text=%22email%22 | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 355 0 355 0 0 514 0 --:--:-- --:--:-- --:--:-- 514
{
"sqlQuery": "SELECT email FROM TBL_USER;",
"results": [
{
"EMAIL": "user1@example.com"
},
{
"EMAIL": "user2@example.com"
},
{
"EMAIL": "user3@example.com"
},
{
"EMAIL": "user4@example.com"
},
{
"EMAIL": "user5@example.com"
},
{
"EMAIL": "user6@example.com"
},
{
"EMAIL": "user7@example.com"
},
{
"EMAIL": "user8@example.com"
},
{
"EMAIL": "user9@example.com"
},
{
"EMAIL": "user10@example.com"
}
]
}
```

**When no parameters are entered**

```shell
$ curl http://localhost:8081/ai/sql | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 844 0 844 0 0 1115 0 --:--:-- --:--:-- --:--:-- 1116
{
"sqlQuery": "SELECT * FROM TBL_USER;",
"results": [
{
"ID": 1,
"USERNAME": "user1",
"EMAIL": "user1@example.com",
"PASSWORD": "password1"
},
{
"ID": 2,
"USERNAME": "user2",
"EMAIL": "user2@example.com",
"PASSWORD": "password2"
},
{
"ID": 3,
"USERNAME": "user3",
"EMAIL": "user3@example.com",
"PASSWORD": "password3"
},
{
"ID": 4,
"USERNAME": "user4",
"EMAIL": "user4@example.com",
"PASSWORD": "password4"
},
{
"ID": 5,
"USERNAME": "user5",
"EMAIL": "user5@example.com",
"PASSWORD": "password5"
},
{
"ID": 6,
"USERNAME": "user6",
"EMAIL": "user6@example.com",
"PASSWORD": "password6"
},
{
"ID": 7,
"USERNAME": "user7",
"EMAIL": "user7@example.com",
"PASSWORD": "password7"
},
{
"ID": 8,
"USERNAME": "user8",
"EMAIL": "user8@example.com",
"PASSWORD": "password8"
},
{
"ID": 9,
"USERNAME": "user9",
"EMAIL": "user9@example.com",
"PASSWORD": "password9"
},
{
"ID": 10,
"USERNAME": "user10",
"EMAIL": "user10@example.com",
"PASSWORD": "password10"
}
]
}
```

### Part-of-Speech Typing Application

Perform part-of-speech analysis on the input text and output the analysis results.

> url: http://localhost:8082/ai/text/structured-output?text="好人"
```shell
$ curl http://localhost:8082/ai/text/structured-output?text=%22%E5%A5%BD%E4%BA%BA%22

"POSITIVE"
```
139 changes: 139 additions & 0 deletions spring-ai-alibaba-examples/usercase-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# Spring AI 用户使用示例

## 生成 SQL 应用

根据接口传入的参数生成查询 SQL 语句。

使用示例如下:

**当输入的参数为 email 时**

> url: http://localhost:8081/ai/sql?text="email"
```shell
$ curl http://localhost:8081/ai/sql?text=%22email%22 | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 355 0 355 0 0 514 0 --:--:-- --:--:-- --:--:-- 514
{
"sqlQuery": "SELECT email FROM TBL_USER;",
"results": [
{
"EMAIL": "user1@example.com"
},
{
"EMAIL": "user2@example.com"
},
{
"EMAIL": "user3@example.com"
},
{
"EMAIL": "user4@example.com"
},
{
"EMAIL": "user5@example.com"
},
{
"EMAIL": "user6@example.com"
},
{
"EMAIL": "user7@example.com"
},
{
"EMAIL": "user8@example.com"
},
{
"EMAIL": "user9@example.com"
},
{
"EMAIL": "user10@example.com"
}
]
}
```

**不输入任何参数时**

```shell
$ curl http://localhost:8081/ai/sql | python -m json.tool
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 844 0 844 0 0 1115 0 --:--:-- --:--:-- --:--:-- 1116
{
"sqlQuery": "SELECT * FROM TBL_USER;",
"results": [
{
"ID": 1,
"USERNAME": "user1",
"EMAIL": "user1@example.com",
"PASSWORD": "password1"
},
{
"ID": 2,
"USERNAME": "user2",
"EMAIL": "user2@example.com",
"PASSWORD": "password2"
},
{
"ID": 3,
"USERNAME": "user3",
"EMAIL": "user3@example.com",
"PASSWORD": "password3"
},
{
"ID": 4,
"USERNAME": "user4",
"EMAIL": "user4@example.com",
"PASSWORD": "password4"
},
{
"ID": 5,
"USERNAME": "user5",
"EMAIL": "user5@example.com",
"PASSWORD": "password5"
},
{
"ID": 6,
"USERNAME": "user6",
"EMAIL": "user6@example.com",
"PASSWORD": "password6"
},
{
"ID": 7,
"USERNAME": "user7",
"EMAIL": "user7@example.com",
"PASSWORD": "password7"
},
{
"ID": 8,
"USERNAME": "user8",
"EMAIL": "user8@example.com",
"PASSWORD": "password8"
},
{
"ID": 9,
"USERNAME": "user9",
"EMAIL": "user9@example.com",
"PASSWORD": "password9"
},
{
"ID": 10,
"USERNAME": "user10",
"EMAIL": "user10@example.com",
"PASSWORD": "password10"
}
]
}
```

### 词性分型应用

将输入的文本进行词性分析,并输出分析结果。

> url: http://localhost:8082/ai/text/structured-output?text="好人"
```shell
$ curl http://localhost:8082/ai/text/structured-output?text=%22%E5%A5%BD%E4%BA%BA%22

"POSITIVE"
```
Loading

0 comments on commit 2e69c39

Please sign in to comment.