有时候由于限制或者其他原因,不能直接访问外部的接口,我们就需要一个中转站,用于中转用户的请求,将用户的请求发送到目的地址,然后返回用户需要的结果。
例如如下代码是通过中转站调用了SUNO AI的接口
@Value("${yunmeng.api.key}")
private String API_KEY;
private static final String BASE_URL = "https://www.anmory.com";
public Map<String, Object> inspiration(Integer userId, String title, String prompt,
String mv, Boolean instrumental) throws Exception {
if (!deductCreditIfNotVip(userId)) {
return Map.of("code", 402, "msg", "积分不足");
}
Map<String, Object> body = new HashMap<>();
body.put("gpt_description_prompt", prompt);
body.put("mv", mv != null ? mv : "chirp-v4");
body.put("make_instrumental", instrumental != null && instrumental);
String taskId = submitToYunwuAndGetTaskId(body);
if (taskId == null) {
return Map.of("code", 500, "msg", "提交失败");
}
songsMapper.insertTask(
userId, taskId, title, prompt, null, null,
mv != null ? mv : "chirp-v4", instrumental, null, null
);
Songs task = songsMapper.getLastSong();
songDownloadTask.processTask(task);
return Map.of("code", 200, "msg", "提交成功", "taskId", taskId);
}
上述的中转api-key可前往这里获取
这样就可以轻松调用和切换各种模型

1056

被折叠的 条评论
为什么被折叠?



