openAI兼容通义千问

配置文件

spring:
  ai:
    openai:
      api-key: ${TONGYI_API_KEY}
      base-url: ${TONGYI_OPNEAI_BASE_URL}
      chat:
        options:
          model: ${TONGYI_MODEL}

# 通义千问API-KEY
TONGYI_API_KEY: "sk-xxx"
TONGYI_MODEL: "qwen-plus"
TONGYI_OPNEAI_BASE_URL: "https://dashscope.aliyuncs.com/compatible-mode"   #注意基础路径,不带V1
TONGYI_URL: "https://dashscope.aliyuncs.com/compatible-mode/v1"

 

@Resource
private OpenAiChatModel chatModel;

---------------------------------------------
UserMessage userMessage = null; try { userMessage = UserMessage.builder() // 提示语 .text(userText) // 添加图片资源 .media(new Media(MimeTypeUtils.IMAGE_PNG, new UrlResource("https://tongyi-main.oss-accelerate.aliyuncs.com/upload/06/93de276e61184400affdb130b1d1784e/ea8a8d41510f435b8c13de42c1ca8bd1/%E8%AF%95%E9%A2%981.png?Expires=1828062420&OSSAccessKeyId=LTAI5tL97mBYzVcjkG1cUyin&Signature=YSWft5EAhIimme9vewa8%2BlxcnOw%3D"))) .build(); } catch (MalformedURLException e) { throw new RuntimeException(e); } String response = chatModel.call(userMessage); System.out.println(response);

 

posted @ 2025-12-08 09:35  qx和世界  阅读(18)  评论(0)    收藏  举报