BasicModelService.java 974 B

1234567891011121314151617181920212223242526272829
  1. package com.webchat.aigc.llm;
  2. import com.alibaba.dashscope.embeddings.TextEmbedding;
  3. import com.alibaba.dashscope.embeddings.TextEmbeddingParam;
  4. import com.alibaba.dashscope.embeddings.TextEmbeddingResult;
  5. import com.alibaba.dashscope.exception.ApiException;
  6. import com.alibaba.dashscope.exception.NoApiKeyException;
  7. import org.springframework.stereotype.Service;
  8. import java.util.Arrays;
  9. @Service
  10. public class BasicModelService {
  11. public static void basicCall() throws ApiException, NoApiKeyException {
  12. TextEmbeddingParam param = TextEmbeddingParam
  13. .builder()
  14. .model(TextEmbedding.Models.TEXT_EMBEDDING_V3)
  15. .texts(Arrays.asList("风急天高猿啸哀", "渚清沙白鸟飞回", "无边落木萧萧下", "不尽长江滚滚来")).build();
  16. TextEmbedding textEmbedding = new TextEmbedding();
  17. TextEmbeddingResult result = textEmbedding.call(param);
  18. System.out.println(result);
  19. }
  20. }