DashScopeConfig.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package com.smartreview.configure;
  2. import lombok.Data;
  3. import org.springframework.boot.context.properties.ConfigurationProperties;
  4. import org.springframework.stereotype.Component;
  5. import java.util.Map;
  6. /**
  7. * DashScope配置(直接调用AI模型)
  8. */
  9. @Data
  10. @Component
  11. @ConfigurationProperties("dashscope")
  12. public class DashScopeConfig {
  13. /**
  14. * API密钥
  15. */
  16. private String apiKey;
  17. /**
  18. * 默认模型名称
  19. */
  20. private String model = "qwen-plus";
  21. /**
  22. * 各功能使用的模型配置
  23. */
  24. private Map<String, String> models;
  25. /**
  26. * 获取指定功能的模型名称
  27. */
  28. public String getModel(String functionKey) {
  29. if (models != null && models.containsKey(functionKey)) {
  30. String modelName = models.get(functionKey);
  31. if (modelName != null && !modelName.isBlank()) {
  32. return modelName;
  33. }
  34. }
  35. return model;
  36. }
  37. /**
  38. * 获取知识点提取模型
  39. */
  40. public String getKnowledgeExtractorModel() {
  41. return getModel("knowledge-extractor");
  42. }
  43. /**
  44. * 获取题目生成模型
  45. */
  46. public String getQuestionGeneratorModel() {
  47. return getModel("question-generator");
  48. }
  49. /**
  50. * 获取答案批改模型
  51. */
  52. public String getAnswerGraderModel() {
  53. return getModel("answer-grader");
  54. }
  55. /**
  56. * 获取复习助教模型
  57. */
  58. public String getReviewAssistantModel() {
  59. return getModel("review-assistant");
  60. }
  61. /**
  62. * 获取对话标题生成模型
  63. */
  64. public String getTitleGeneratorModel() {
  65. return getModel("title-generator");
  66. }
  67. }