Skip to content

Commit

Permalink
Merge pull request #6 from yuluo-yx/0920-yuluo/feat
Browse files Browse the repository at this point in the history
feat: update ai example
  • Loading branch information
chickenlj authored Sep 21, 2024
2 parents f50c463 + 1a932a3 commit 9253c6e
Show file tree
Hide file tree
Showing 19 changed files with 651 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,33 @@
*/
package com.alibaba.cloud.ai.example.model;

import com.alibaba.cloud.ai.dashscope.audio.speech.AudioSpeechModels;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ai/audio")
public class AudioModelController {

private static final Logger logger = LoggerFactory.getLogger(AudioModelController.class);

@GetMapping("/speech")
public String speech(String text) {

logger.warn("unimplement");

return "unimplement";
}

@GetMapping("/transcription")
public String transcription(String text) {

logger.warn("unimplement");

return "unimplement";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,40 @@
*/
package com.alibaba.cloud.ai.example.model;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ai")
public class ChatModelController {

private static final Logger logger = LoggerFactory.getLogger(ChatModelController.class);

private final ChatModel chatModel;

public ChatModelController(ChatModel chatModel) {
this.chatModel = chatModel;
}

@RequestMapping("/chat")
@GetMapping("/chat")
public String chat(String input) {

ChatResponse response = chatModel.call(new Prompt(input));
return response.getResult().getOutput().getContent();
}

@GetMapping("/stream")
public String stream(String input) {

logger.warn("unimplement");

return "unimplement";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ai")
public class ImageModelController {

private final ImageModel imageModel;
Expand All @@ -35,12 +36,13 @@ public class ImageModelController {

@RequestMapping("/image")
public String image(String input) {
ImageOptions options = ImageOptionsBuilder.builder().withModel("wanx-v1").build();

ImagePrompt imagePrompt = new ImagePrompt(input, options);
ImageOptions options = ImageOptionsBuilder.builder()
.withModel("wanx-v1")
.build();

ImagePrompt imagePrompt = new ImagePrompt(input, options);
ImageResponse response = imageModel.call(imagePrompt);

String imageUrl = response.getResult().getOutput().getUrl();

return "redirect:" + imageUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
*/
package com.alibaba.cloud.ai.example.functioncalling;

import com.alibaba.cloud.ai.example.functioncalling.function.MockWeatherService;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ai/func")
public class FunctionCallingController {

private final ChatClient chatClient;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
/*
* All rights Reserved, Designed By Alibaba Group Inc.
* Copyright: Copyright(C) 1999-2024
* Company : Alibaba Group Inc.
*/
package com.alibaba.cloud.ai.example.functioncalling;

import java.util.function.Function;

import org.springframework.ai.chat.client.ChatClient;
import com.alibaba.cloud.ai.example.functioncalling.entity.Response;
import com.alibaba.cloud.ai.example.functioncalling.function.MockOrderService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Description;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerResponse;

@SpringBootApplication
public class FunctionCallingExampleApplication {
Expand All @@ -20,8 +23,9 @@ public static void main(String[] args) {

@Bean
@Description("根据用户编号和订单编号查询订单信息")
public Function<MockOrderService.Request, MockOrderService.Response> getOrderFunction(
public Function<MockOrderService.Request, Response> getOrderFunction(
MockOrderService mockOrderService) {

return mockOrderService::getOrder;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* All rights Reserved, Designed By Alibaba Group Inc.
* Copyright: Copyright(C) 1999-2024
* Company : Alibaba Group Inc.
*/
package com.alibaba.cloud.ai.example.functioncalling.entity;

public record Response(String description) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* Copyright: Copyright(C) 1999-2024
* Company : Alibaba Group Inc.
*/
package com.alibaba.cloud.ai.example.functioncalling;
package com.alibaba.cloud.ai.example.functioncalling.function;

import com.alibaba.cloud.ai.example.functioncalling.entity.Response;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
Expand Down Expand Up @@ -37,7 +38,4 @@ public record Request(
value = "userId") @JsonPropertyDescription("用户编号, 比如2001***") String userId) {
}

public record Response(String description) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
* Copyright: Copyright(C) 1999-2024
* Company : Alibaba Group Inc.
*/
package com.alibaba.cloud.ai.example.functioncalling;
package com.alibaba.cloud.ai.example.functioncalling.function;

import java.util.function.Function;

import com.alibaba.cloud.ai.example.functioncalling.entity.Response;
import com.fasterxml.jackson.annotation.JsonClassDescription;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -22,7 +23,7 @@
* @since jdk8
*/

public class MockWeatherService implements Function<MockWeatherService.Request, MockWeatherService.Response> {
public class MockWeatherService implements Function<MockWeatherService.Request, Response> {

@Override
public Response apply(Request request) {
Expand All @@ -44,7 +45,4 @@ public record Request(
@JsonProperty(required = true, value = "date") @JsonPropertyDescription("日期, 比如2024-08-22") String date) {
}

public record Response(String description) {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ai")
public class ChatController {

private final ChatClient chatClient;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Map;

import com.alibaba.cloud.ai.example.outparser.entity.ActorsFilms;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -12,10 +13,12 @@
import org.springframework.ai.parser.BeanOutputParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/ai")
public class OutputParserController {

private static final Logger logger = LoggerFactory.getLogger(OutputParserController.class);
Expand All @@ -27,7 +30,7 @@ public OutputParserController(ChatClient.Builder builder) {
this.chatClient = builder.build();
}

@GetMapping("/ai/output")
@GetMapping("/output")
public ActorsFilms generate(@RequestParam(value = "actor", defaultValue = "Jeff Bridges") String actor) {
var outputParser = new BeanOutputParser<>(ActorsFilms.class);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.alibaba.cloud.ai.example.outparser.entity;

import java.util.List;

public class ActorsFilms {

private String actor;

private List<String> movies;

public ActorsFilms() {
}

public String getActor() {
return actor;
}

public void setActor(String actor) {
this.actor = actor;
}

public List<String> getMovies() {
return movies;
}

public void setMovies(List<String> movies) {
this.movies = movies;
}

@Override
public String toString() {
return "ActorsFilms{" + "actor='" + actor + '\'' + ", movies=" + movies + '}';
}

}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,3 @@ import 'Frontend/generated/jar-resources/vaadin-dev-tools/vaadin-dev-tools.js';
import './theme-customer-support-agent.global.generated.js';
import { applyTheme } from './theme.js';
applyTheme(document);

import { Outlet } from 'react-router-dom';
(window as any).Vaadin ??= {};
(window as any).Vaadin.copilot ??= {};
(window as any).Vaadin.copilot._ref ??= {};
(window as any).Vaadin.copilot._ref.Outlet = Outlet;
Loading

0 comments on commit 9253c6e

Please sign in to comment.