✨Feat: 完成天气卡片
This commit is contained in:
@@ -19,8 +19,9 @@ public class BackGroundConstant {
|
||||
public static final String BACKGROUND_WINTER_DESCRIPTION = "“寒冷的季节,也是心灵的沉淀”\n" +
|
||||
"作息 影响健康值幅度增加,室内活动(节日)比例增加";
|
||||
|
||||
public static final String BACKGROUND_WEATHER = "按照如下示例根据天气生成" +
|
||||
"示例【晴天】阳光像金色的蜂蜜洒满星露谷!微风轻拂超舒服,快带上工具去田间劳作吧~ \uD83C\uDF31\n" +
|
||||
"记得给作物喝饱水,今天的阳光能量满分,庄稼会长得飞快哦!" +
|
||||
"【注意】你不需要输出天气本身";
|
||||
public static final String BACKGROUND_WEATHER = "【要求】请根据传入的今日数据,采用符合的语气,emjoy和符号,带一点想象,用简洁的语句,描述一下想象中的风景,体感,并附带一点小Tips。\n" +
|
||||
"【输出格式】今天的星露谷....(控制在30字)\\nTips。\n" +
|
||||
"【输出示例】\n" +
|
||||
"今天的星露谷天气阴沉,气温舒适,北风轻轻吹拂,风力微弱,湿度较高,仿佛连空气都带着一丝凉意。这种天气最适合在家中泡一杯热茶,或者在庭院里摆上几张藤椅,享受难得的宁静。\n" +
|
||||
"Tips:可以尝试在这样的天气里种植一些耐阴植物,比如蕨类或苔藓,为你的农场增添一抹绿意哦!\uD83D\uDE09\uD83C\uDF31";
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.lark.oapi.core.utils.Jsons;
|
||||
import com.lark.oapi.service.im.v1.model.CreateMessageReq;
|
||||
import com.lark.oapi.service.im.v1.model.CreateMessageReqBody;
|
||||
import com.lark.oapi.service.im.v1.model.CreateMessageResp;
|
||||
import com.wonderland.stardewvalley.common.constant.BackGroundConstant;
|
||||
import com.wonderland.stardewvalley.service.ai.ChatUtil;
|
||||
import com.wonderland.stardewvalley.common.constant.LarkConstant;
|
||||
import com.wonderland.stardewvalley.entity.game.Weather;
|
||||
@@ -29,6 +30,10 @@ public class LarkUtil {
|
||||
// 复制该 Demo 后, 需要将 "YOUR_APP_ID", "YOUR_APP_SECRET" 替换为自己应用的 APP_ID, APP_SECRET.
|
||||
// 以下示例代码默认根据文档示例值填充,如果存在代码问题,请在 API 调试台填上相关必要参数后再复制代码使用
|
||||
|
||||
@Resource
|
||||
private ChatUtil chatUtil;
|
||||
|
||||
|
||||
/**
|
||||
* 发送简单的文本消息
|
||||
* @param content 发送的内容
|
||||
@@ -69,7 +74,7 @@ public class LarkUtil {
|
||||
System.out.println(Jsons.DEFAULT.toJson(resp.getData()));
|
||||
}
|
||||
|
||||
public static void sendWeatherCard(Weather weather) throws Exception {
|
||||
public void sendWeatherCard(Weather weather) throws Exception {
|
||||
// 构建client
|
||||
Client client = Client.newBuilder(LarkConstant.APP_ID, LarkConstant.APP_SECRET).build();
|
||||
|
||||
@@ -82,6 +87,11 @@ public class LarkUtil {
|
||||
|
||||
|
||||
// 构建卡片:对于不同的卡片,只需要给出不同的 模板id 版本号 变量字段
|
||||
|
||||
String content = chatUtil.doChat(BackGroundConstant.BACKGROUND_WEATHER, weather.toString());
|
||||
weather.setContent(content);
|
||||
log.info("[LarkUtil] Set Content via LLM: {}", content);
|
||||
|
||||
Map<String, Object> templateData = new HashMap<>();
|
||||
templateData.put("template_id", CardTemplate.CARD_TEMPLATE_WEATHER.getCardId());
|
||||
templateData.put("template_version_name", CardTemplate.CARD_TEMPLATE_WEATHER.getVersion());
|
||||
|
||||
@@ -3,10 +3,15 @@ package com.wonderland.stardewvalley.lark;
|
||||
import com.wonderland.stardewvalley.entity.game.Weather;
|
||||
import com.wonderland.stardewvalley.util.weather.WeatherUtil;
|
||||
import com.wonderland.stardewvalley.util.lark.LarkUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class LarkUtilTest {
|
||||
|
||||
@Resource
|
||||
private LarkUtil larkUtil;
|
||||
|
||||
@Test
|
||||
void sendText() throws Exception {
|
||||
@@ -23,6 +28,6 @@ class LarkUtilTest {
|
||||
@Test
|
||||
void sendWeatherCard() throws Exception {
|
||||
Weather weather = WeatherUtil.getWeather();
|
||||
LarkUtil.sendWeatherCard(weather);
|
||||
larkUtil.sendWeatherCard(weather);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user