From 639478f03bcae4427fbc7a21fd793a8432df3798 Mon Sep 17 00:00:00 2001 From: Lin <220340138@cauc.edu.cn> Date: Tue, 24 Sep 2024 21:39:43 +0800 Subject: [PATCH] APIcontroller --- ai_agent/.gitignore | 38 ++++++++++++++++++++ ai_agent/.idea/.gitignore | 8 +++++ ai_agent/.idea/encodings.xml | 7 ++++ ai_agent/.idea/misc.xml | 15 ++++++++ ai_agent/pom.xml | 27 ++++++++++++++ ai_agent/src/main/java/org/example/Main.java | 32 +++++++++++++++++ 6 files changed, 127 insertions(+) create mode 100644 ai_agent/.gitignore create mode 100644 ai_agent/.idea/.gitignore create mode 100644 ai_agent/.idea/encodings.xml create mode 100644 ai_agent/.idea/misc.xml create mode 100644 ai_agent/pom.xml create mode 100644 ai_agent/src/main/java/org/example/Main.java diff --git a/ai_agent/.gitignore b/ai_agent/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/ai_agent/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/ai_agent/.idea/.gitignore b/ai_agent/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/ai_agent/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/ai_agent/.idea/encodings.xml b/ai_agent/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/ai_agent/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/ai_agent/.idea/misc.xml b/ai_agent/.idea/misc.xml new file mode 100644 index 0000000..7004689 --- /dev/null +++ b/ai_agent/.idea/misc.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/ai_agent/pom.xml b/ai_agent/pom.xml new file mode 100644 index 0000000..35ea0ee --- /dev/null +++ b/ai_agent/pom.xml @@ -0,0 +1,27 @@ + + + 4.0.0 + + org.example + ai_agent + 1.0-SNAPSHOT + AI Agent Project + A project for AI agent development + + + 21 + 21 + UTF-8 + + + + + com.alibaba + dashscope-sdk-java + 2.16.4 + + + + \ No newline at end of file diff --git a/ai_agent/src/main/java/org/example/Main.java b/ai_agent/src/main/java/org/example/Main.java new file mode 100644 index 0000000..fd90c86 --- /dev/null +++ b/ai_agent/src/main/java/org/example/Main.java @@ -0,0 +1,32 @@ +package org.example; +import com.alibaba.dashscope.app.*; +import com.alibaba.dashscope.exception.ApiException; +import com.alibaba.dashscope.exception.InputRequiredException; +import com.alibaba.dashscope.exception.NoApiKeyException; + +import java.util.List; +public class Main { + public static void callAgentApp() + throws ApiException, NoApiKeyException, InputRequiredException { + ApplicationParam param = ApplicationParam.builder() + .apiKey("sk-0ad1eaf5194249439f82698893607bef") + .appId("1d2b00751a914efd84ea4b354fffd962") + .prompt("推荐10月1日天津飞泉州的机票") + .build(); + + Application application = new Application(); + ApplicationResult result = application.call(param); + + System.out.printf("requestId: %s, text: %s, finishReason: %s\n", + result.getRequestId(), result.getOutput().getText(), result.getOutput().getFinishReason()); + } + + public static void main(String[] args) { + try { + callAgentApp(); + } catch (ApiException | NoApiKeyException | InputRequiredException e) { + System.out.printf("Exception: %s", e.getMessage()); + } + System.exit(0); + } +} \ No newline at end of file