-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a2f2c1
commit ae26772
Showing
48 changed files
with
816 additions
and
472 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
adi-chat/src/main/java/com/moyz/adi/chat/controller/ModelController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.moyz.adi.chat.controller; | ||
|
||
import com.moyz.adi.common.helper.ImageModelContext; | ||
import com.moyz.adi.common.helper.LLMContext; | ||
import com.moyz.adi.common.vo.ImageModelInfo; | ||
import com.moyz.adi.common.vo.LLMModelInfo; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@RestController | ||
@RequestMapping("/model") | ||
public class ModelController { | ||
@Operation(summary = "支持的大语言模型列表") | ||
@GetMapping(value = "/llms") | ||
public List<LLMModelInfo> llms() { | ||
return LLMContext.NAME_TO_MODEL.values().stream().collect(Collectors.toList()); | ||
} | ||
|
||
@Operation(summary = "支持的图片模型列表") | ||
@GetMapping(value = "/imageModels") | ||
public List<ImageModelInfo> imageModels() { | ||
return ImageModelContext.NAME_TO_MODEL.values().stream().collect(Collectors.toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,6 @@ public class EditImageReq { | |
@Min(1) | ||
@Max(10) | ||
private int number; | ||
|
||
private String modelName; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,6 @@ public class GenerateImageReq { | |
@Min(1) | ||
@Max(10) | ||
private int number; | ||
|
||
private String modelName; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,6 @@ public class QAReq { | |
|
||
@NotBlank | ||
private String question; | ||
|
||
private String modelName; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,6 @@ public class VariationImageReq { | |
@Min(1) | ||
@Max(10) | ||
private int number; | ||
|
||
private String modelName; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
adi-common/src/main/java/com/moyz/adi/common/helper/ImageModelContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.moyz.adi.common.helper; | ||
|
||
import com.moyz.adi.common.interfaces.AbstractImageModelService; | ||
import com.moyz.adi.common.vo.ImageModelInfo; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static dev.langchain4j.model.openai.OpenAiModelName.DALL_E_2; | ||
|
||
/** | ||
* image model service上下文类(策略模式) | ||
*/ | ||
@Slf4j | ||
public class ImageModelContext { | ||
|
||
/** | ||
* AI图片模型 | ||
*/ | ||
public static final Map<String, ImageModelInfo> NAME_TO_MODEL = new HashMap<>(); | ||
|
||
private AbstractImageModelService modelService; | ||
|
||
public ImageModelContext() { | ||
modelService = NAME_TO_MODEL.get(DALL_E_2).getModelService(); | ||
} | ||
|
||
public ImageModelContext(String modelName) { | ||
if (null == NAME_TO_MODEL.get(modelName)) { | ||
log.warn("︿︿︿ Can not find {}, use the default model DALL_E_2 ︿︿︿", modelName); | ||
modelService = NAME_TO_MODEL.get(DALL_E_2).getModelService(); | ||
} else { | ||
modelService = NAME_TO_MODEL.get(modelName).getModelService(); | ||
} | ||
} | ||
|
||
public static void addImageModelService(String modelName, AbstractImageModelService modelService) { | ||
ImageModelInfo imageModelInfo = new ImageModelInfo(); | ||
imageModelInfo.setModelService(modelService); | ||
imageModelInfo.setModelName(modelName); | ||
imageModelInfo.setEnable(modelService.isEnabled()); | ||
NAME_TO_MODEL.put(modelName, imageModelInfo); | ||
} | ||
|
||
public AbstractImageModelService getModelService() { | ||
return modelService; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
adi-common/src/main/java/com/moyz/adi/common/helper/LLMContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.moyz.adi.common.helper; | ||
|
||
import com.moyz.adi.common.interfaces.AbstractLLMService; | ||
import com.moyz.adi.common.vo.LLMModelInfo; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static dev.langchain4j.model.openai.OpenAiModelName.GPT_3_5_TURBO; | ||
|
||
/** | ||
* llmService上下文类(策略模式) | ||
*/ | ||
@Slf4j | ||
public class LLMContext { | ||
public static final Map<String, LLMModelInfo> NAME_TO_MODEL = new HashMap<>(); | ||
private AbstractLLMService llmService; | ||
|
||
public LLMContext() { | ||
llmService = NAME_TO_MODEL.get(GPT_3_5_TURBO).getLlmService(); | ||
} | ||
|
||
public LLMContext(String modelName) { | ||
if (null == NAME_TO_MODEL.get(modelName)) { | ||
log.warn("︿︿︿ Can not find {}, use the default model GPT_3_5_TURBO ︿︿︿", modelName); | ||
llmService = NAME_TO_MODEL.get(GPT_3_5_TURBO).getLlmService(); | ||
} else { | ||
llmService = NAME_TO_MODEL.get(modelName).getLlmService(); | ||
} | ||
} | ||
|
||
public static void addLLMService(String modelName, AbstractLLMService llmService) { | ||
LLMModelInfo llmModelInfo = new LLMModelInfo(); | ||
llmModelInfo.setModelName(modelName); | ||
llmModelInfo.setEnable(llmService.isEnabled()); | ||
llmModelInfo.setLlmService(llmService); | ||
NAME_TO_MODEL.put(modelName, llmModelInfo); | ||
} | ||
|
||
public AbstractLLMService getLLMService() { | ||
return llmService; | ||
} | ||
} |
Oops, something went wrong.