mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-06-10 19:26:54 +08:00
Refactor: 交互框架移动至 liteflow-ai-engine
This commit is contained in:
40
liteflow-ai/liteflow-ai-bom/pom.xml
Normal file
40
liteflow-ai/liteflow-ai-bom/pom.xml
Normal file
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>liteflow-ai</artifactId>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<artifactId>liteflow-ai-bom</artifactId>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-ai-core</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-ai-engine</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- model start -->
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-ai-ollama</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
<!-- model end -->
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
</project>
|
||||
@@ -15,7 +15,8 @@
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-spring-boot-starter</artifactId>
|
||||
<artifactId>liteflow-ai-engine</artifactId>
|
||||
<version>${revision}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -27,21 +28,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp-sse</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -101,16 +101,6 @@ public @interface AIComponent {
|
||||
*/
|
||||
double frequencyPenalty() default -1.0;
|
||||
|
||||
// --- Format ----
|
||||
/**
|
||||
* 响应格式
|
||||
*/
|
||||
String responseFormat() default "";
|
||||
/**
|
||||
* 是否严格遵循 JSON Schema
|
||||
*/
|
||||
TriState strictJsonSchema() default TriState.UNSET;
|
||||
|
||||
// --- Tool Calling ----
|
||||
/**
|
||||
* 是否并行 ToolCall
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
package com.yomahub.liteflow.ai.component.chat;
|
||||
|
||||
import dev.langchain4j.agent.tool.ToolExecutionRequest;
|
||||
import dev.langchain4j.model.output.FinishReason;
|
||||
import dev.langchain4j.model.output.TokenUsage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 聊天结果
|
||||
*
|
||||
@@ -14,83 +8,83 @@ import java.util.List;
|
||||
*/
|
||||
|
||||
public class ChatResult {
|
||||
|
||||
private String text;
|
||||
|
||||
private List<ToolExecutionRequest> toolExecutionRequestList;
|
||||
|
||||
private String id;
|
||||
|
||||
private String modelName;
|
||||
|
||||
private TokenUsage tokenUsage;
|
||||
|
||||
private FinishReason finishReason;
|
||||
|
||||
public ChatResult() {
|
||||
}
|
||||
|
||||
public ChatResult(
|
||||
String text,
|
||||
List<ToolExecutionRequest> toolExecutionRequestList,
|
||||
String id,
|
||||
String modelName,
|
||||
TokenUsage tokenUsage,
|
||||
FinishReason finishReason
|
||||
) {
|
||||
this.text = text;
|
||||
this.toolExecutionRequestList = toolExecutionRequestList;
|
||||
this.id = id;
|
||||
this.modelName = modelName;
|
||||
this.tokenUsage = tokenUsage;
|
||||
this.finishReason = finishReason;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public List<ToolExecutionRequest> getToolExecutionRequestList() {
|
||||
return toolExecutionRequestList;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getModelName() {
|
||||
return modelName;
|
||||
}
|
||||
|
||||
public TokenUsage getTokenUsage() {
|
||||
return tokenUsage;
|
||||
}
|
||||
|
||||
public FinishReason getFinishReason() {
|
||||
return finishReason;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public void setToolExecutionRequestList(List<ToolExecutionRequest> toolExecutionRequestList) {
|
||||
this.toolExecutionRequestList = toolExecutionRequestList;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setModelName(String modelName) {
|
||||
this.modelName = modelName;
|
||||
}
|
||||
|
||||
public void setTokenUsage(TokenUsage tokenUsage) {
|
||||
this.tokenUsage = tokenUsage;
|
||||
}
|
||||
|
||||
public void setFinishReason(FinishReason finishReason) {
|
||||
this.finishReason = finishReason;
|
||||
}
|
||||
//
|
||||
// private String text;
|
||||
//
|
||||
// private List<ToolExecutionRequest> toolExecutionRequestList;
|
||||
//
|
||||
// private String id;
|
||||
//
|
||||
// private String modelName;
|
||||
//
|
||||
// private TokenUsage tokenUsage;
|
||||
//
|
||||
// private FinishReason finishReason;
|
||||
//
|
||||
// public ChatResult() {
|
||||
// }
|
||||
//
|
||||
// public ChatResult(
|
||||
// String text,
|
||||
// List<ToolExecutionRequest> toolExecutionRequestList,
|
||||
// String id,
|
||||
// String modelName,
|
||||
// TokenUsage tokenUsage,
|
||||
// FinishReason finishReason
|
||||
// ) {
|
||||
// this.text = text;
|
||||
// this.toolExecutionRequestList = toolExecutionRequestList;
|
||||
// this.id = id;
|
||||
// this.modelName = modelName;
|
||||
// this.tokenUsage = tokenUsage;
|
||||
// this.finishReason = finishReason;
|
||||
// }
|
||||
//
|
||||
// public String getText() {
|
||||
// return text;
|
||||
// }
|
||||
//
|
||||
// public List<ToolExecutionRequest> getToolExecutionRequestList() {
|
||||
// return toolExecutionRequestList;
|
||||
// }
|
||||
//
|
||||
// public String getId() {
|
||||
// return id;
|
||||
// }
|
||||
//
|
||||
// public String getModelName() {
|
||||
// return modelName;
|
||||
// }
|
||||
//
|
||||
// public TokenUsage getTokenUsage() {
|
||||
// return tokenUsage;
|
||||
// }
|
||||
//
|
||||
// public FinishReason getFinishReason() {
|
||||
// return finishReason;
|
||||
// }
|
||||
//
|
||||
// public void setText(String text) {
|
||||
// this.text = text;
|
||||
// }
|
||||
//
|
||||
// public void setToolExecutionRequestList(List<ToolExecutionRequest> toolExecutionRequestList) {
|
||||
// this.toolExecutionRequestList = toolExecutionRequestList;
|
||||
// }
|
||||
//
|
||||
// public void setId(String id) {
|
||||
// this.id = id;
|
||||
// }
|
||||
//
|
||||
// public void setModelName(String modelName) {
|
||||
// this.modelName = modelName;
|
||||
// }
|
||||
//
|
||||
// public void setTokenUsage(TokenUsage tokenUsage) {
|
||||
// this.tokenUsage = tokenUsage;
|
||||
// }
|
||||
//
|
||||
// public void setFinishReason(FinishReason finishReason) {
|
||||
// this.finishReason = finishReason;
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,11 +1,5 @@
|
||||
package com.yomahub.liteflow.ai.component.classifier;
|
||||
|
||||
import dev.langchain4j.agent.tool.ToolExecutionRequest;
|
||||
import dev.langchain4j.model.output.FinishReason;
|
||||
import dev.langchain4j.model.output.TokenUsage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分类结果
|
||||
*
|
||||
@@ -15,21 +9,21 @@ import java.util.List;
|
||||
|
||||
public class ClassifyResult {
|
||||
|
||||
private List<String> classifyResults;
|
||||
|
||||
private List<String> primaryCategories;
|
||||
|
||||
private String text;
|
||||
|
||||
private List<ToolExecutionRequest> toolExecutionRequestList;
|
||||
|
||||
private String id;
|
||||
|
||||
private String modelName;
|
||||
|
||||
private TokenUsage tokenUsage;
|
||||
|
||||
private FinishReason finishReason;
|
||||
|
||||
// private List<String> classifyResults;
|
||||
//
|
||||
// private List<String> primaryCategories;
|
||||
//
|
||||
// private String text;
|
||||
//
|
||||
// private List<ToolExecutionRequest> toolExecutionRequestList;
|
||||
//
|
||||
// private String id;
|
||||
//
|
||||
// private String modelName;
|
||||
//
|
||||
// private TokenUsage tokenUsage;
|
||||
//
|
||||
// private FinishReason finishReason;
|
||||
//
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
package com.yomahub.liteflow.ai.context;
|
||||
|
||||
import dev.langchain4j.model.chat.response.ChatResponse;
|
||||
import dev.langchain4j.rag.RetrievalAugmentor;
|
||||
import dev.langchain4j.rag.content.Content;
|
||||
import dev.langchain4j.service.TokenStream;
|
||||
import dev.langchain4j.service.tool.ToolExecution;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 流式输出处理器
|
||||
*
|
||||
@@ -16,59 +8,60 @@ import java.util.List;
|
||||
*/
|
||||
|
||||
public interface StreamHandler {
|
||||
|
||||
/**
|
||||
* 当语言模型生成新的部分响应(通常是单个 token)时,将调用此方法。
|
||||
*
|
||||
* @param partialResponse 新生成的部分响应文本。
|
||||
*/
|
||||
void onPartialResponse(String partialResponse);
|
||||
|
||||
/**
|
||||
* 当使用 {@link RetrievalAugmentor} 检索到任何 {@link Content} 时,将调用此方法。
|
||||
* <p>
|
||||
* 此调用发生在与语言模型进行任何交互之前。
|
||||
*
|
||||
* @param retrievedContents 所有被检索到的内容列表。
|
||||
*/
|
||||
void onRetrieved(List<Content> retrievedContents);
|
||||
|
||||
/**
|
||||
* 当任何工具被执行后,将调用此方法。
|
||||
* <p>
|
||||
* 此调用发生在工具方法执行完成之后,下一个工具执行之前。
|
||||
*
|
||||
* @param toolExecution 包含已执行工具的名称、参数和结果的对象。
|
||||
*/
|
||||
void onToolExecuted(ToolExecution toolExecution);
|
||||
|
||||
/**
|
||||
* 当语言模型完成流式响应时,将调用此方法。
|
||||
*
|
||||
* @param chatResponse 完整的聊天响应结果。
|
||||
*/
|
||||
void onCompleteResponse(ChatResponse chatResponse);
|
||||
|
||||
/**
|
||||
* 当流式处理过程中发生错误时,将调用此方法。
|
||||
*
|
||||
* @param error 捕获到的异常或错误。
|
||||
*/
|
||||
void onError(Throwable error);
|
||||
|
||||
/**
|
||||
* 接受一个 {@link TokenStream} 对象,并注册流式处理的回调。
|
||||
* <p>
|
||||
* 自动开启 TokenStream 的处理流程,并在流式响应的各个阶段调用相应的方法。
|
||||
*
|
||||
* @param tokenStream 要处理的 {@link TokenStream} 对象。
|
||||
*/
|
||||
default void acceptTokenStream(TokenStream tokenStream) {
|
||||
tokenStream.onPartialResponse(this::onPartialResponse)
|
||||
.onRetrieved(this::onRetrieved)
|
||||
.onToolExecuted(this::onToolExecuted)
|
||||
.onCompleteResponse(this::onCompleteResponse)
|
||||
.onError(this::onError)
|
||||
.start();
|
||||
}
|
||||
// TODO streamhandler 接口定义
|
||||
//
|
||||
// /**
|
||||
// * 当语言模型生成新的部分响应(通常是单个 token)时,将调用此方法。
|
||||
// *
|
||||
// * @param partialResponse 新生成的部分响应文本。
|
||||
// */
|
||||
// void onPartialResponse(String partialResponse);
|
||||
//
|
||||
// /**
|
||||
// * 当使用 {@link RetrievalAugmentor} 检索到任何 {@link Content} 时,将调用此方法。
|
||||
// * <p>
|
||||
// * 此调用发生在与语言模型进行任何交互之前。
|
||||
// *
|
||||
// * @param retrievedContents 所有被检索到的内容列表。
|
||||
// */
|
||||
// void onRetrieved(List<Content> retrievedContents);
|
||||
//
|
||||
// /**
|
||||
// * 当任何工具被执行后,将调用此方法。
|
||||
// * <p>
|
||||
// * 此调用发生在工具方法执行完成之后,下一个工具执行之前。
|
||||
// *
|
||||
// * @param toolExecution 包含已执行工具的名称、参数和结果的对象。
|
||||
// */
|
||||
// void onToolExecuted(ToolExecution toolExecution);
|
||||
//
|
||||
// /**
|
||||
// * 当语言模型完成流式响应时,将调用此方法。
|
||||
// *
|
||||
// * @param chatResponse 完整的聊天响应结果。
|
||||
// */
|
||||
// void onCompleteResponse(ChatResponse chatResponse);
|
||||
//
|
||||
// /**
|
||||
// * 当流式处理过程中发生错误时,将调用此方法。
|
||||
// *
|
||||
// * @param error 捕获到的异常或错误。
|
||||
// */
|
||||
// void onError(Throwable error);
|
||||
//
|
||||
// /**
|
||||
// * 接受一个 {@link TokenStream} 对象,并注册流式处理的回调。
|
||||
// * <p>
|
||||
// * 自动开启 TokenStream 的处理流程,并在流式响应的各个阶段调用相应的方法。
|
||||
// *
|
||||
// * @param tokenStream 要处理的 {@link TokenStream} 对象。
|
||||
// */
|
||||
// default void acceptTokenStream(TokenStream tokenStream) {
|
||||
// tokenStream.onPartialResponse(this::onPartialResponse)
|
||||
// .onRetrieved(this::onRetrieved)
|
||||
// .onToolExecuted(this::onToolExecuted)
|
||||
// .onCompleteResponse(this::onCompleteResponse)
|
||||
// .onError(this::onError)
|
||||
// .start();
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -33,8 +33,6 @@ public final class ModelConfig {
|
||||
private final double repeatPenalty;
|
||||
private final double presencePenalty;
|
||||
private final double frequencyPenalty;
|
||||
private final String responseFormat;
|
||||
private final TriState strictJsonSchema;
|
||||
private final TriState parallelToolCalls;
|
||||
private final TriState logRequests;
|
||||
private final TriState logResponses;
|
||||
@@ -43,8 +41,8 @@ public final class ModelConfig {
|
||||
public ModelConfig(String provider, String baseUrl, String model, String apiKey, String version,
|
||||
String timeout, int maxRetries, double temperature, double topP, int topK,
|
||||
int maxTokens, List<String> stop, int seed, double repeatPenalty,
|
||||
double presencePenalty, double frequencyPenalty, String responseFormat,
|
||||
TriState strictJsonSchema, TriState parallelToolCalls, TriState logRequests,
|
||||
double presencePenalty, double frequencyPenalty,
|
||||
TriState parallelToolCalls, TriState logRequests,
|
||||
TriState logResponses, List<KeyValue> customHeaders) {
|
||||
this.provider = provider;
|
||||
this.baseUrl = baseUrl;
|
||||
@@ -62,8 +60,6 @@ public final class ModelConfig {
|
||||
this.repeatPenalty = repeatPenalty;
|
||||
this.presencePenalty = presencePenalty;
|
||||
this.frequencyPenalty = frequencyPenalty;
|
||||
this.responseFormat = responseFormat;
|
||||
this.strictJsonSchema = strictJsonSchema;
|
||||
this.parallelToolCalls = parallelToolCalls;
|
||||
this.logRequests = logRequests;
|
||||
this.logResponses = logResponses;
|
||||
@@ -74,13 +70,12 @@ public final class ModelConfig {
|
||||
return new ModelConfig(
|
||||
anno.provider(), anno.baseUrl(), anno.model(), anno.apiKey(), anno.version(), anno.timeout(), anno.maxRetries(),
|
||||
anno.temperature(), anno.topP(), anno.topK(), anno.maxTokens(), Arrays.asList(anno.stop()),
|
||||
anno.seed(), anno.repeatPenalty(), anno.presencePenalty(), anno.frequencyPenalty(), anno.responseFormat(),
|
||||
anno.strictJsonSchema(), anno.parallelToolCalls(), anno.logRequests(), anno.logResponses(),
|
||||
anno.seed(), anno.repeatPenalty(), anno.presencePenalty(), anno.frequencyPenalty(),
|
||||
anno.parallelToolCalls(), anno.logRequests(), anno.logResponses(),
|
||||
Arrays.asList(anno.customHeaders())
|
||||
);
|
||||
}
|
||||
|
||||
// 3. 为所有字段生成 Getter 方法
|
||||
public String getProvider() {
|
||||
return provider;
|
||||
}
|
||||
@@ -145,14 +140,6 @@ public final class ModelConfig {
|
||||
return frequencyPenalty;
|
||||
}
|
||||
|
||||
public String getResponseFormat() {
|
||||
return responseFormat;
|
||||
}
|
||||
|
||||
public TriState getStrictJsonSchema() {
|
||||
return strictJsonSchema;
|
||||
}
|
||||
|
||||
public TriState getParallelToolCalls() {
|
||||
return parallelToolCalls;
|
||||
}
|
||||
@@ -190,8 +177,6 @@ public final class ModelConfig {
|
||||
Objects.equals(version, that.version) &&
|
||||
Objects.equals(timeout, that.timeout) &&
|
||||
Objects.equals(stop, that.stop) &&
|
||||
Objects.equals(responseFormat, that.responseFormat) &&
|
||||
strictJsonSchema == that.strictJsonSchema &&
|
||||
parallelToolCalls == that.parallelToolCalls &&
|
||||
logRequests == that.logRequests &&
|
||||
logResponses == that.logResponses &&
|
||||
@@ -200,7 +185,7 @@ public final class ModelConfig {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(provider, baseUrl, model, apiKey, version, timeout, maxRetries, temperature, topP, topK, maxTokens, stop, seed, repeatPenalty, presencePenalty, frequencyPenalty, responseFormat, strictJsonSchema, parallelToolCalls, logRequests, logResponses, customHeaders);
|
||||
return Objects.hash(provider, baseUrl, model, apiKey, version, timeout, maxRetries, temperature, topP, topK, maxTokens, stop, seed, repeatPenalty, presencePenalty, frequencyPenalty, parallelToolCalls, logRequests, logResponses, customHeaders);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -222,8 +207,6 @@ public final class ModelConfig {
|
||||
", repeatPenalty=" + repeatPenalty +
|
||||
", presencePenalty=" + presencePenalty +
|
||||
", frequencyPenalty=" + frequencyPenalty +
|
||||
", responseFormat='" + responseFormat + '\'' +
|
||||
", strictJsonSchema=" + strictJsonSchema +
|
||||
", parallelToolCalls=" + parallelToolCalls +
|
||||
", logRequests=" + logRequests +
|
||||
", logResponses=" + logResponses +
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package com.yomahub.liteflow.ai.domain.enums;
|
||||
|
||||
import dev.langchain4j.model.chat.request.ResponseFormatType;
|
||||
|
||||
/**
|
||||
* AI响应类型枚举
|
||||
*
|
||||
@@ -12,26 +10,11 @@ public enum ResponseType {
|
||||
/**
|
||||
* 纯文本响应
|
||||
*/
|
||||
TEXT(ResponseFormatType.TEXT),
|
||||
TEXT,
|
||||
|
||||
/**
|
||||
* JSON格式响应
|
||||
*/
|
||||
JSON(ResponseFormatType.JSON),
|
||||
JSON,
|
||||
;
|
||||
|
||||
private final ResponseFormatType type;
|
||||
|
||||
ResponseType(ResponseFormatType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取对应的LangChain4j响应类型
|
||||
*
|
||||
* @return LangChain4j响应类型
|
||||
*/
|
||||
public ResponseFormatType getType() {
|
||||
return this.type;
|
||||
}
|
||||
}
|
||||
|
||||
47
liteflow-ai/liteflow-ai-engine/pom.xml
Normal file
47
liteflow-ai/liteflow-ai-engine/pom.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<parent>
|
||||
<artifactId>liteflow-ai</artifactId>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>liteflow-ai-engine</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.yomahub</groupId>
|
||||
<artifactId>liteflow-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp-sse</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.yomahub.liteflow.ai.engine.exception;
|
||||
|
||||
/**
|
||||
* 大模型异常
|
||||
*
|
||||
* @author 苍镜月
|
||||
* @since TODO
|
||||
*/
|
||||
|
||||
public class LiteFlowAIEngineException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 异常信息
|
||||
*/
|
||||
private String message;
|
||||
|
||||
public LiteFlowAIEngineException(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public LiteFlowAIEngineException(String message, Throwable cause) {
|
||||
super(cause);
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.yomahub.liteflow.ai.interact;
|
||||
package com.yomahub.liteflow.ai.engine.interact;
|
||||
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatConfig;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatRequest;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatResponse;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatConfig;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatRequest;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatResponse;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
package com.yomahub.liteflow.ai.interact;
|
||||
package com.yomahub.liteflow.ai.engine.interact;
|
||||
|
||||
import com.yomahub.liteflow.ai.exception.LiteFlowAIException;
|
||||
import com.yomahub.liteflow.ai.interact.callbacks.ResultHandler;
|
||||
import com.yomahub.liteflow.ai.interact.pipeline.ChatContext;
|
||||
import com.yomahub.liteflow.ai.interact.pipeline.ChunkProcessPipeline;
|
||||
import com.yomahub.liteflow.ai.interact.protocol.ProtocolTransformer;
|
||||
import com.yomahub.liteflow.ai.interact.protocol.ProtocolTransformerFactory;
|
||||
import com.yomahub.liteflow.ai.interact.transport.Transport;
|
||||
import com.yomahub.liteflow.ai.interact.transport.TransportListener;
|
||||
import com.yomahub.liteflow.ai.interact.transport.TransportType;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatConfig;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatRequest;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatResponse;
|
||||
import com.yomahub.liteflow.ai.engine.exception.LiteFlowAIEngineException;
|
||||
import com.yomahub.liteflow.ai.engine.interact.callbacks.ResultHandler;
|
||||
import com.yomahub.liteflow.ai.engine.interact.pipeline.ChatContext;
|
||||
import com.yomahub.liteflow.ai.engine.interact.pipeline.ChunkProcessPipeline;
|
||||
import com.yomahub.liteflow.ai.engine.interact.protocol.ProtocolTransformer;
|
||||
import com.yomahub.liteflow.ai.engine.interact.protocol.ProtocolTransformerFactory;
|
||||
import com.yomahub.liteflow.ai.engine.interact.transport.Transport;
|
||||
import com.yomahub.liteflow.ai.engine.interact.transport.TransportListener;
|
||||
import com.yomahub.liteflow.ai.engine.interact.transport.TransportType;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatConfig;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatRequest;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatResponse;
|
||||
import com.yomahub.liteflow.log.LFLog;
|
||||
import com.yomahub.liteflow.log.LFLoggerManager;
|
||||
|
||||
@@ -40,7 +40,7 @@ public class LlmInteractClient implements InteractClient {
|
||||
try {
|
||||
return chatAsync(config, request).get();
|
||||
} catch (ExecutionException | InterruptedException e) {
|
||||
throw new LiteFlowAIException("同步调用大模型失败", e.getCause());
|
||||
throw new LiteFlowAIEngineException("同步调用大模型失败", e.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ public class LlmInteractClient implements InteractClient {
|
||||
ChatResponse response = manager.executeBlocking();
|
||||
future.complete(response);
|
||||
} catch (Exception e) {
|
||||
future.completeExceptionally(new LiteFlowAIException("异步调用大模型失败", e));
|
||||
future.completeExceptionally(new LiteFlowAIEngineException("异步调用大模型失败", e));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.yomahub.liteflow.ai.interact.callbacks;
|
||||
package com.yomahub.liteflow.ai.engine.interact.callbacks;
|
||||
|
||||
import com.yomahub.liteflow.ai.interact.pipeline.ChatContext;
|
||||
import com.yomahub.liteflow.ai.interact.pipeline.ChunkTransformer;
|
||||
import com.yomahub.liteflow.ai.interact.protocol.StreamingProtocolChunk;
|
||||
import com.yomahub.liteflow.ai.engine.interact.pipeline.ChatContext;
|
||||
import com.yomahub.liteflow.ai.engine.interact.pipeline.ChunkTransformer;
|
||||
import com.yomahub.liteflow.ai.engine.interact.protocol.StreamingProtocolChunk;
|
||||
|
||||
/**
|
||||
* 流式消息处理管道的回调接口。根据块数据的类型进行具体回调
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.yomahub.liteflow.ai.interact.callbacks;
|
||||
package com.yomahub.liteflow.ai.engine.interact.callbacks;
|
||||
|
||||
import com.yomahub.liteflow.ai.interact.pipeline.ChatContext;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatResponse;
|
||||
import com.yomahub.liteflow.ai.engine.interact.pipeline.ChatContext;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatResponse;
|
||||
|
||||
/**
|
||||
* 对消息全部发送完毕并转换后的结果进行处理的接口。
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.interact.pipeline;
|
||||
package com.yomahub.liteflow.ai.engine.interact.pipeline;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.yomahub.liteflow.ai.interact.pipeline;
|
||||
package com.yomahub.liteflow.ai.engine.interact.pipeline;
|
||||
|
||||
import com.yomahub.liteflow.ai.interact.callbacks.ChunkCallbackTransformer;
|
||||
import com.yomahub.liteflow.ai.interact.protocol.ProtocolTransformer;
|
||||
import com.yomahub.liteflow.ai.interact.protocol.StreamingProtocolChunk;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatResponse;
|
||||
import com.yomahub.liteflow.ai.engine.interact.callbacks.ChunkCallbackTransformer;
|
||||
import com.yomahub.liteflow.ai.engine.interact.protocol.ProtocolTransformer;
|
||||
import com.yomahub.liteflow.ai.engine.interact.protocol.StreamingProtocolChunk;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatResponse;
|
||||
|
||||
/**
|
||||
* 流式消息处理管道
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.interact.pipeline;
|
||||
package com.yomahub.liteflow.ai.engine.interact.pipeline;
|
||||
|
||||
/**
|
||||
* 消息转换器接口
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.yomahub.liteflow.ai.interact.protocol;
|
||||
package com.yomahub.liteflow.ai.engine.interact.protocol;
|
||||
|
||||
import com.yomahub.liteflow.ai.interact.pipeline.ChatContext;
|
||||
import com.yomahub.liteflow.ai.interact.pipeline.ChunkTransformer;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatResponse;
|
||||
import com.yomahub.liteflow.ai.engine.interact.pipeline.ChatContext;
|
||||
import com.yomahub.liteflow.ai.engine.interact.pipeline.ChunkTransformer;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatResponse;
|
||||
|
||||
/**
|
||||
* 协议转换器
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.yomahub.liteflow.ai.interact.protocol;
|
||||
package com.yomahub.liteflow.ai.engine.interact.protocol;
|
||||
|
||||
import com.yomahub.liteflow.ai.exception.LiteFlowAIException;
|
||||
import com.yomahub.liteflow.ai.engine.exception.LiteFlowAIEngineException;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -36,7 +36,7 @@ public class ProtocolTransformerFactory {
|
||||
public static ProtocolTransformer getTransformer(String provider) {
|
||||
ProtocolTransformer protocolTransformer = TRANSFORMER_REGISTRY.get(provider);
|
||||
if (Objects.isNull(protocolTransformer)) {
|
||||
throw new LiteFlowAIException("不支持的协议转换器: " + provider);
|
||||
throw new LiteFlowAIEngineException("不支持的协议转换器: " + provider);
|
||||
}
|
||||
return protocolTransformer;
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.interact.protocol;
|
||||
package com.yomahub.liteflow.ai.engine.interact.protocol;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.interact.protocol;
|
||||
package com.yomahub.liteflow.ai.engine.interact.protocol;
|
||||
|
||||
/**
|
||||
* 流式消息块
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.interact.protocol;
|
||||
package com.yomahub.liteflow.ai.engine.interact.protocol;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.yomahub.liteflow.ai.interact.transport;
|
||||
package com.yomahub.liteflow.ai.engine.interact.transport;
|
||||
|
||||
import com.yomahub.liteflow.ai.interact.pipeline.ChunkProcessPipeline;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatConfig;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatRequest;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatResponse;
|
||||
import com.yomahub.liteflow.ai.engine.interact.pipeline.ChunkProcessPipeline;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatConfig;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatRequest;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatResponse;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.yomahub.liteflow.ai.interact.transport;
|
||||
package com.yomahub.liteflow.ai.engine.interact.transport;
|
||||
|
||||
import com.yomahub.liteflow.ai.interact.pipeline.ChatContext;
|
||||
import com.yomahub.liteflow.ai.engine.interact.pipeline.ChatContext;
|
||||
|
||||
/**
|
||||
* 传输监听器接口
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.yomahub.liteflow.ai.interact.transport;
|
||||
package com.yomahub.liteflow.ai.engine.interact.transport;
|
||||
|
||||
import com.yomahub.liteflow.ai.interact.transport.impl.HttpTransport;
|
||||
import com.yomahub.liteflow.ai.interact.transport.impl.SseTransport;
|
||||
import com.yomahub.liteflow.ai.engine.interact.transport.impl.HttpTransport;
|
||||
import com.yomahub.liteflow.ai.engine.interact.transport.impl.SseTransport;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.yomahub.liteflow.ai.interact.transport.impl;
|
||||
package com.yomahub.liteflow.ai.engine.interact.transport.impl;
|
||||
|
||||
import com.yomahub.liteflow.ai.exception.LiteFlowAIException;
|
||||
import com.yomahub.liteflow.ai.interact.pipeline.ChunkProcessPipeline;
|
||||
import com.yomahub.liteflow.ai.interact.transport.Transport;
|
||||
import com.yomahub.liteflow.ai.interact.transport.TransportListener;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatConfig;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatRequest;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatResponse;
|
||||
import com.yomahub.liteflow.ai.util.HttpUtil;
|
||||
import com.yomahub.liteflow.ai.engine.exception.LiteFlowAIEngineException;
|
||||
import com.yomahub.liteflow.ai.engine.interact.pipeline.ChunkProcessPipeline;
|
||||
import com.yomahub.liteflow.ai.engine.interact.transport.Transport;
|
||||
import com.yomahub.liteflow.ai.engine.interact.transport.TransportListener;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatConfig;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatRequest;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatResponse;
|
||||
import com.yomahub.liteflow.ai.engine.util.HttpUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
@@ -45,7 +45,7 @@ public class HttpTransport implements Transport {
|
||||
// 处理响应
|
||||
return pipeline.processBlocking(responseBody);
|
||||
} catch (IOException e) {
|
||||
throw new LiteFlowAIException("阻塞调用大模型失败", e);
|
||||
throw new LiteFlowAIEngineException("阻塞调用大模型失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package com.yomahub.liteflow.ai.interact.transport.impl;
|
||||
package com.yomahub.liteflow.ai.engine.interact.transport.impl;
|
||||
|
||||
import okhttp3.Headers;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import com.yomahub.liteflow.ai.interact.pipeline.ChunkProcessPipeline;
|
||||
import com.yomahub.liteflow.ai.interact.transport.Transport;
|
||||
import com.yomahub.liteflow.ai.interact.transport.TransportListener;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatConfig;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatRequest;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatResponse;
|
||||
import com.yomahub.liteflow.ai.engine.interact.pipeline.ChunkProcessPipeline;
|
||||
import com.yomahub.liteflow.ai.engine.interact.transport.Transport;
|
||||
import com.yomahub.liteflow.ai.engine.interact.transport.TransportListener;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatConfig;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatRequest;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatResponse;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.model;
|
||||
package com.yomahub.liteflow.ai.engine.model;
|
||||
|
||||
/**
|
||||
* 大模型标识接口
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.yomahub.liteflow.ai.model;
|
||||
package com.yomahub.liteflow.ai.engine.model;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.yomahub.liteflow.ai.util.request.RequestBody;
|
||||
import com.yomahub.liteflow.ai.util.request.RequestBodyConvertible;
|
||||
import com.yomahub.liteflow.ai.util.request.RequestHeader;
|
||||
import com.yomahub.liteflow.ai.util.request.RequestHeaderConvertible;
|
||||
import com.yomahub.liteflow.ai.engine.util.request.RequestBody;
|
||||
import com.yomahub.liteflow.ai.engine.util.request.RequestBodyConvertible;
|
||||
import com.yomahub.liteflow.ai.engine.util.request.RequestHeader;
|
||||
import com.yomahub.liteflow.ai.engine.util.request.RequestHeaderConvertible;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.yomahub.liteflow.ai.model;
|
||||
package com.yomahub.liteflow.ai.engine.model;
|
||||
|
||||
import com.yomahub.liteflow.ai.util.request.RequestBodyConvertible;
|
||||
import com.yomahub.liteflow.ai.engine.util.request.RequestBodyConvertible;
|
||||
|
||||
/**
|
||||
* 大模型选项配置
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.yomahub.liteflow.ai.model;
|
||||
package com.yomahub.liteflow.ai.engine.model;
|
||||
|
||||
import com.yomahub.liteflow.ai.util.request.RequestBodyConvertible;
|
||||
import com.yomahub.liteflow.ai.engine.util.request.RequestBodyConvertible;
|
||||
|
||||
/**
|
||||
* 大模型请求
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.model;
|
||||
package com.yomahub.liteflow.ai.engine.model;
|
||||
|
||||
/**
|
||||
* 大模型响应
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.yomahub.liteflow.ai.model.chat;
|
||||
package com.yomahub.liteflow.ai.engine.model.chat;
|
||||
|
||||
import com.yomahub.liteflow.ai.model.BaseModel;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatConfig;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatRequest;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatResponse;
|
||||
import com.yomahub.liteflow.ai.engine.model.BaseModel;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatConfig;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatRequest;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatResponse;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.yomahub.liteflow.ai.model.chat.entity;
|
||||
package com.yomahub.liteflow.ai.engine.model.chat.entity;
|
||||
|
||||
import com.yomahub.liteflow.ai.interact.transport.TransportType;
|
||||
import com.yomahub.liteflow.ai.model.ModelConfig;
|
||||
import com.yomahub.liteflow.ai.util.request.RequestBody;
|
||||
import com.yomahub.liteflow.ai.engine.interact.transport.TransportType;
|
||||
import com.yomahub.liteflow.ai.engine.model.ModelConfig;
|
||||
import com.yomahub.liteflow.ai.engine.util.request.RequestBody;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.yomahub.liteflow.ai.model.chat.entity;
|
||||
package com.yomahub.liteflow.ai.engine.model.chat.entity;
|
||||
|
||||
import com.yomahub.liteflow.ai.model.ModelOptions;
|
||||
import com.yomahub.liteflow.ai.util.request.RequestBody;
|
||||
import com.yomahub.liteflow.ai.engine.model.ModelOptions;
|
||||
import com.yomahub.liteflow.ai.engine.util.request.RequestBody;
|
||||
|
||||
/**
|
||||
* 对话选项配置
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.yomahub.liteflow.ai.model.chat.entity;
|
||||
package com.yomahub.liteflow.ai.engine.model.chat.entity;
|
||||
|
||||
import com.yomahub.liteflow.ai.interact.callbacks.ChunkCallbackTransformer;
|
||||
import com.yomahub.liteflow.ai.interact.callbacks.ResultHandler;
|
||||
import com.yomahub.liteflow.ai.interact.pipeline.ChatContext;
|
||||
import com.yomahub.liteflow.ai.interact.transport.TransportListener;
|
||||
import com.yomahub.liteflow.ai.model.ModelRequest;
|
||||
import com.yomahub.liteflow.ai.util.request.RequestBody;
|
||||
import com.yomahub.liteflow.ai.model.chat.message.Message;
|
||||
import com.yomahub.liteflow.ai.engine.interact.callbacks.ChunkCallbackTransformer;
|
||||
import com.yomahub.liteflow.ai.engine.interact.callbacks.ResultHandler;
|
||||
import com.yomahub.liteflow.ai.engine.interact.pipeline.ChatContext;
|
||||
import com.yomahub.liteflow.ai.engine.interact.transport.TransportListener;
|
||||
import com.yomahub.liteflow.ai.engine.model.ModelRequest;
|
||||
import com.yomahub.liteflow.ai.engine.util.request.RequestBody;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.message.Message;
|
||||
import org.apache.commons.lang3.function.TriFunction;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.yomahub.liteflow.ai.model.chat.entity;
|
||||
package com.yomahub.liteflow.ai.engine.model.chat.entity;
|
||||
|
||||
import com.yomahub.liteflow.ai.model.ModelResponse;
|
||||
import com.yomahub.liteflow.ai.model.chat.message.AssistantMessage;
|
||||
import com.yomahub.liteflow.ai.engine.model.ModelResponse;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.message.AssistantMessage;
|
||||
|
||||
/**
|
||||
* chat 响应体
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.model.chat.entity;
|
||||
package com.yomahub.liteflow.ai.engine.model.chat.entity;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.yomahub.liteflow.ai.model.chat.message;
|
||||
package com.yomahub.liteflow.ai.engine.model.chat.message;
|
||||
|
||||
import com.yomahub.liteflow.ai.exception.LiteFlowAIException;
|
||||
|
||||
import com.yomahub.liteflow.ai.engine.exception.LiteFlowAIEngineException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -43,10 +44,10 @@ public abstract class AbstractMessage implements Message {
|
||||
*/
|
||||
protected AbstractMessage(MessageType messageType, String textContent, Map<String, Object> metadata) {
|
||||
if (Objects.isNull(messageType)) {
|
||||
throw new LiteFlowAIException("消息类型不能为 null");
|
||||
throw new LiteFlowAIEngineException("消息类型不能为 null");
|
||||
}
|
||||
if (Objects.isNull(metadata)) {
|
||||
throw new LiteFlowAIException("Metadata 不能为null");
|
||||
throw new LiteFlowAIEngineException("Metadata 不能为null");
|
||||
}
|
||||
this.messageType = messageType;
|
||||
this.textContent = textContent;
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.yomahub.liteflow.ai.model.chat.message;
|
||||
package com.yomahub.liteflow.ai.engine.model.chat.message;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ToolCall;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ToolCall;
|
||||
|
||||
/**
|
||||
* 大模型消息
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.model.chat.message;
|
||||
package com.yomahub.liteflow.ai.engine.model.chat.message;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.model.chat.message;
|
||||
package com.yomahub.liteflow.ai.engine.model.chat.message;
|
||||
|
||||
/**
|
||||
* 消息接口
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.model.chat.message;
|
||||
package com.yomahub.liteflow.ai.engine.model.chat.message;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.model.chat.message;
|
||||
package com.yomahub.liteflow.ai.engine.model.chat.message;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.model.chat.message;
|
||||
package com.yomahub.liteflow.ai.engine.model.chat.message;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.model.chat.message;
|
||||
package com.yomahub.liteflow.ai.engine.model.chat.message;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.model.embedding;
|
||||
package com.yomahub.liteflow.ai.engine.model.embedding;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.model.embedding.entity;
|
||||
package com.yomahub.liteflow.ai.engine.model.embedding.entity;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.model.embedding.entity;
|
||||
package com.yomahub.liteflow.ai.engine.model.embedding.entity;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.model.rerank;
|
||||
package com.yomahub.liteflow.ai.engine.model.rerank;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.model.rerank.entity;
|
||||
package com.yomahub.liteflow.ai.engine.model.rerank.entity;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.model.rerank.entity;
|
||||
package com.yomahub.liteflow.ai.engine.model.rerank.entity;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.model.runtime;
|
||||
package com.yomahub.liteflow.ai.engine.model.runtime;
|
||||
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.yomahub.liteflow.ai.model.runtime;
|
||||
package com.yomahub.liteflow.ai.engine.model.runtime;
|
||||
|
||||
import com.yomahub.liteflow.ai.exception.LiteFlowAIException;
|
||||
import com.yomahub.liteflow.ai.model.BaseModel;
|
||||
import com.yomahub.liteflow.ai.model.ModelConfig;
|
||||
import com.yomahub.liteflow.ai.model.chat.ChatModel;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatConfig;
|
||||
import com.yomahub.liteflow.ai.model.embedding.EmbeddingModel;
|
||||
import com.yomahub.liteflow.ai.util.SpringUtil;
|
||||
import com.yomahub.liteflow.ai.engine.exception.LiteFlowAIEngineException;
|
||||
import com.yomahub.liteflow.ai.engine.model.BaseModel;
|
||||
import com.yomahub.liteflow.ai.engine.model.ModelConfig;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.ChatModel;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatConfig;
|
||||
import com.yomahub.liteflow.ai.engine.model.embedding.EmbeddingModel;
|
||||
import com.yomahub.liteflow.ai.engine.util.SpringUtil;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -48,7 +48,7 @@ public class ModelRuntimeFactory {
|
||||
return RUNTIME_CACHE.computeIfAbsent(cacheKey, key -> {
|
||||
Class<? extends BaseModel<? extends ModelConfig>> runtimeClass = PROVIDER_REGISTRY.get(provider);
|
||||
if (Objects.isNull(runtimeClass)) {
|
||||
throw new LiteFlowAIException("不支持的模型提供者: " + provider);
|
||||
throw new LiteFlowAIEngineException("不支持的模型提供者: " + provider);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -69,7 +69,7 @@ public class ModelRuntimeFactory {
|
||||
public static ChatModel createChatRuntime(String provider, ChatConfig config) {
|
||||
BaseModel<? extends ModelConfig> model = createRuntime(provider + ModelType.CHAT_MODEL, config);
|
||||
if (!(model instanceof ChatModel)) {
|
||||
throw new LiteFlowAIException("提供者 " + provider + " 不支持聊天模型");
|
||||
throw new LiteFlowAIEngineException("提供者 " + provider + " 不支持聊天模型");
|
||||
}
|
||||
return (ChatModel) model;
|
||||
}
|
||||
@@ -84,7 +84,7 @@ public class ModelRuntimeFactory {
|
||||
public static EmbeddingModel createEmbeddingRuntime(String provider, ModelConfig config) {
|
||||
BaseModel<? extends ModelConfig> model = createRuntime(provider + ModelType.EMBEDDING_MODEL, config);
|
||||
if (!(model instanceof EmbeddingModel)) {
|
||||
throw new LiteFlowAIException("提供者 " + provider + " 不支持嵌入模型");
|
||||
throw new LiteFlowAIEngineException("提供者 " + provider + " 不支持嵌入模型");
|
||||
}
|
||||
return (EmbeddingModel) model;
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.yomahub.liteflow.ai.model.runtime;
|
||||
package com.yomahub.liteflow.ai.engine.model.runtime;
|
||||
|
||||
import com.yomahub.liteflow.ai.model.BaseModel;
|
||||
import com.yomahub.liteflow.ai.model.ModelConfig;
|
||||
import com.yomahub.liteflow.ai.util.SpringUtil;
|
||||
import com.yomahub.liteflow.ai.engine.model.BaseModel;
|
||||
import com.yomahub.liteflow.ai.engine.model.ModelConfig;
|
||||
import com.yomahub.liteflow.ai.engine.util.SpringUtil;
|
||||
import com.yomahub.liteflow.log.LFLog;
|
||||
import com.yomahub.liteflow.log.LFLoggerManager;
|
||||
import org.springframework.beans.factory.SmartInitializingSingleton;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.model.runtime;
|
||||
package com.yomahub.liteflow.ai.engine.model.runtime;
|
||||
|
||||
/**
|
||||
* 模型类型
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.tool;
|
||||
package com.yomahub.liteflow.ai.engine.tool;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.tool;
|
||||
package com.yomahub.liteflow.ai.engine.tool;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.tool;
|
||||
package com.yomahub.liteflow.ai.engine.tool;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.util;
|
||||
package com.yomahub.liteflow.ai.engine.util;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.yomahub.liteflow.log.LFLog;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.util;
|
||||
package com.yomahub.liteflow.ai.engine.util;
|
||||
|
||||
import cn.hutool.core.lang.TypeReference;
|
||||
import org.springframework.beans.BeansException;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.util.request;
|
||||
package com.yomahub.liteflow.ai.engine.util.request;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONWriter;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.util.request;
|
||||
package com.yomahub.liteflow.ai.engine.util.request;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.util.request;
|
||||
package com.yomahub.liteflow.ai.engine.util.request;
|
||||
|
||||
/**
|
||||
* 实现该接口的类可以转换为请求体。
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.util.request;
|
||||
package com.yomahub.liteflow.ai.engine.util.request;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.ai.util.request;
|
||||
package com.yomahub.liteflow.ai.engine.util.request;
|
||||
|
||||
/**
|
||||
* 实现该接口的类可以转换为请求头
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.yomahub.liteflow.ai.model.ollama.interact;
|
||||
|
||||
import com.yomahub.liteflow.ai.interact.pipeline.ChatContext;
|
||||
import com.yomahub.liteflow.ai.interact.protocol.ProtocolTransformer;
|
||||
import com.yomahub.liteflow.ai.interact.protocol.ProtocolTransformerRegistrar;
|
||||
import com.yomahub.liteflow.ai.interact.protocol.StreamingProtocolChunk;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatResponse;
|
||||
import com.yomahub.liteflow.ai.model.chat.message.AssistantMessage;
|
||||
import com.yomahub.liteflow.ai.engine.interact.pipeline.ChatContext;
|
||||
import com.yomahub.liteflow.ai.engine.interact.protocol.ProtocolTransformer;
|
||||
import com.yomahub.liteflow.ai.engine.interact.protocol.ProtocolTransformerRegistrar;
|
||||
import com.yomahub.liteflow.ai.engine.interact.protocol.StreamingProtocolChunk;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatResponse;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.message.AssistantMessage;
|
||||
|
||||
import static com.yomahub.liteflow.ai.model.ollama.constants.OllamaConstant.PROVIDER_NAME;
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.yomahub.liteflow.ai.model.ollama.model.chat;
|
||||
|
||||
import com.yomahub.liteflow.ai.interact.transport.TransportType;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatConfig;
|
||||
import com.yomahub.liteflow.ai.engine.interact.transport.TransportType;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatConfig;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package com.yomahub.liteflow.ai.model.ollama.model.chat;
|
||||
|
||||
import com.yomahub.liteflow.ai.interact.InteractClient;
|
||||
import com.yomahub.liteflow.ai.interact.LlmInteractClient;
|
||||
import com.yomahub.liteflow.ai.model.chat.ChatModel;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatRequest;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatResponse;
|
||||
import com.yomahub.liteflow.ai.model.runtime.LiteFlowAIModel;
|
||||
import com.yomahub.liteflow.ai.engine.interact.InteractClient;
|
||||
import com.yomahub.liteflow.ai.engine.interact.LlmInteractClient;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.ChatModel;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatRequest;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatResponse;
|
||||
import com.yomahub.liteflow.ai.engine.model.runtime.LiteFlowAIModel;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static com.yomahub.liteflow.ai.model.ollama.constants.OllamaConstant.PROVIDER_NAME;
|
||||
import static com.yomahub.liteflow.ai.model.runtime.ModelType.CHAT_MODEL;
|
||||
import static com.yomahub.liteflow.ai.engine.model.runtime.ModelType.CHAT_MODEL;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package com.yomahub.liteflow.ai.model.ollama.model.chat;
|
||||
|
||||
import com.yomahub.liteflow.ai.interact.callbacks.ChunkCallbackTransformer;
|
||||
import com.yomahub.liteflow.ai.interact.callbacks.ResultHandler;
|
||||
import com.yomahub.liteflow.ai.interact.transport.TransportListener;
|
||||
import com.yomahub.liteflow.ai.util.request.RequestBody;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatOptions;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatRequest;
|
||||
import com.yomahub.liteflow.ai.model.chat.message.Message;
|
||||
import com.yomahub.liteflow.ai.engine.interact.callbacks.ChunkCallbackTransformer;
|
||||
import com.yomahub.liteflow.ai.engine.interact.callbacks.ResultHandler;
|
||||
import com.yomahub.liteflow.ai.engine.interact.transport.TransportListener;
|
||||
import com.yomahub.liteflow.ai.engine.util.request.RequestBody;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatOptions;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatRequest;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.message.Message;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
<modules>
|
||||
<module>liteflow-ai-core</module>
|
||||
<module>liteflow-ai-ollama</module>
|
||||
<module>liteflow-ai-engine</module>
|
||||
<module>liteflow-ai-bom</module>
|
||||
</modules>
|
||||
|
||||
<artifactId>liteflow-ai</artifactId>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.test.ai.proxy;
|
||||
package com.yomahub.liteflow.test.ai.core.proxy;
|
||||
|
||||
import com.yomahub.liteflow.ai.context.ChatContext;
|
||||
import com.yomahub.liteflow.core.FlowExecutor;
|
||||
@@ -20,10 +20,10 @@ import javax.annotation.Resource;
|
||||
* @since TODO
|
||||
*/
|
||||
|
||||
@TestPropertySource(properties = {"spring.config.location=classpath:/proxy/application.yaml"})
|
||||
@TestPropertySource(properties = {"spring.config.location=classpath:core/proxy/application.yaml"})
|
||||
@SpringBootTest(classes = {ProxyTest.class})
|
||||
@EnableAutoConfiguration
|
||||
@ComponentScan({"com.yomahub.liteflow.test.ai.proxy.cmp"})
|
||||
@ComponentScan({"com.yomahub.liteflow.test.ai.core.proxy.cmp"})
|
||||
public class ProxyTest {
|
||||
|
||||
@Resource
|
||||
@@ -0,0 +1,240 @@
|
||||
package com.yomahub.liteflow.test.ai.core.proxy;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @author 苍镜月
|
||||
* @since TODO
|
||||
*/
|
||||
|
||||
public class TTMPTest {
|
||||
|
||||
// static class Output {
|
||||
// private String content;
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void test3() throws Exception {
|
||||
// Class<?> clazz = createLiteFlowAIAssistant(String.class);
|
||||
// Object assitant = AiServices.builder(clazz)
|
||||
// .chatModel(null)
|
||||
// .build();
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void test2() throws Exception {
|
||||
// // --- 准备阶段 ---
|
||||
// // 我们期望的动态类型是 String.class
|
||||
// Class<?> expectedDynamicType = Output.class;
|
||||
// System.out.println("期望的泛型参数: " + expectedDynamicType.getName());
|
||||
// System.out.println("------------------------------------------");
|
||||
//
|
||||
// // --- 执行阶段 ---
|
||||
// // 动态创建接口,并传入 String.class
|
||||
// Class<?> dynamicInterface = createLiteFlowAIAssistant(expectedDynamicType);
|
||||
//
|
||||
// // --- 验证阶段 ---
|
||||
// System.out.println("开始验证动态生成的接口: " + dynamicInterface.getName());
|
||||
//
|
||||
// // 1. 获取 chat(String, String) 方法的 Method 对象
|
||||
// Method chatMethod = dynamicInterface.getMethod("chat", String.class, String.class);
|
||||
// System.out.println("\n成功获取到方法: " + chatMethod.getName());
|
||||
//
|
||||
// // 2. 获取方法的泛型返回类型
|
||||
// Type genericReturnType = chatMethod.getGenericReturnType();
|
||||
// System.out.println("方法的 getGenericReturnType() 返回: " + genericReturnType.getTypeName());
|
||||
//
|
||||
// // 3. 检查返回类型是否是参数化类型 (例如 Result<String> 而不是 Result)
|
||||
// if (genericReturnType instanceof ParameterizedType) {
|
||||
// System.out.println("✅ 类型检查通过: 返回类型是 ParameterizedType");
|
||||
//
|
||||
// // 4. 将其转换为 ParameterizedType
|
||||
// ParameterizedType parameterizedType = (ParameterizedType) genericReturnType;
|
||||
//
|
||||
// // 5. 验证原始类型是否为 Result.class
|
||||
// Type rawType = parameterizedType.getRawType();
|
||||
// System.out.println(" - 原始类型 (Raw Type): " + rawType.getTypeName());
|
||||
// if (rawType.equals(Result.class)) {
|
||||
// System.out.println(" - ✅ 原始类型验证成功: 是 Result.class");
|
||||
// } else {
|
||||
// System.out.println(" - ❌ 原始类型验证失败: 不是 Result.class");
|
||||
// }
|
||||
//
|
||||
// // 6. 获取所有泛型参数 (例如 <String, Integer> 中的 String 和 Integer)
|
||||
// Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
|
||||
// System.out.println(" - 泛型参数列表 (Actual Type Arguments): " + Arrays.toString(actualTypeArguments));
|
||||
//
|
||||
// // 7. 验证泛型参数的数量和类型
|
||||
// if (actualTypeArguments.length == 1) {
|
||||
// System.out.println(" - ✅ 泛型参数数量验证成功: 数量为 1");
|
||||
// Type actualTypeArgument = actualTypeArguments[0];
|
||||
//
|
||||
// if (actualTypeArgument.equals(expectedDynamicType)) {
|
||||
// System.out.println(" - ✅✅✅ 最终验证成功: 泛型参数与期望的 " + expectedDynamicType.getName() + " 完全匹配!");
|
||||
// } else {
|
||||
// System.out.println(" - ❌❌❌ 最终验证失败: 泛型参数是 " + actualTypeArgument.getTypeName() + " 而不是期望的 " + expectedDynamicType.getName());
|
||||
// }
|
||||
// } else {
|
||||
// System.out.println(" - ❌ 泛型参数数量验证失败: 数量不为 1");
|
||||
// }
|
||||
//
|
||||
// } else {
|
||||
// System.out.println("❌ 类型检查失败: 返回类型不是 ParameterizedType,无法进行泛型验证。");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void test1() throws Exception {
|
||||
// // --- 准备阶段 ---
|
||||
// // 我们期望的动态类型是 String.class
|
||||
// Class<?> expectedDynamicType = String.class;
|
||||
// System.out.println("期望的泛型参数: " + expectedDynamicType.getName());
|
||||
// System.out.println("------------------------------------------");
|
||||
//
|
||||
// // --- 执行阶段 ---
|
||||
// // 动态创建接口,并传入 String.class
|
||||
// Class<?> dynamicInterface = createLiteFlowAIAssistant(expectedDynamicType);
|
||||
//
|
||||
// // --- 验证阶段 ---
|
||||
// System.out.println("开始验证动态生成的接口: " + dynamicInterface.getName());
|
||||
//
|
||||
// // 1. 获取 chat(String, String) 方法的 Method 对象
|
||||
// Method chatMethod = dynamicInterface.getMethod("chat", String.class, String.class);
|
||||
// System.out.println("\n成功获取到方法: " + chatMethod.getName());
|
||||
//
|
||||
// // 2. 获取方法的泛型返回类型
|
||||
// Type genericReturnType = chatMethod.getGenericReturnType();
|
||||
// System.out.println("方法的 getGenericReturnType() 返回: " + genericReturnType.getTypeName());
|
||||
//
|
||||
// // 3. 检查返回类型是否是参数化类型 (例如 Result<String> 而不是 Result)
|
||||
// if (genericReturnType instanceof ParameterizedType) {
|
||||
// System.out.println("✅ 类型检查通过: 返回类型是 ParameterizedType");
|
||||
//
|
||||
// // 4. 将其转换为 ParameterizedType
|
||||
// ParameterizedType parameterizedType = (ParameterizedType) genericReturnType;
|
||||
//
|
||||
// // 5. 验证原始类型是否为 Result.class
|
||||
// Type rawType = parameterizedType.getRawType();
|
||||
// System.out.println(" - 原始类型 (Raw Type): " + rawType.getTypeName());
|
||||
// if (rawType.equals(Result.class)) {
|
||||
// System.out.println(" - ✅ 原始类型验证成功: 是 Result.class");
|
||||
// } else {
|
||||
// System.out.println(" - ❌ 原始类型验证失败: 不是 Result.class");
|
||||
// }
|
||||
//
|
||||
// // 6. 获取所有泛型参数 (例如 <String, Integer> 中的 String 和 Integer)
|
||||
// Type[] actualTypeArguments = parameterizedType.getActualTypeArguments();
|
||||
// System.out.println(" - 泛型参数列表 (Actual Type Arguments): " + Arrays.toString(actualTypeArguments));
|
||||
//
|
||||
// // 7. 验证泛型参数的数量和类型
|
||||
// if (actualTypeArguments.length == 1) {
|
||||
// System.out.println(" - ✅ 泛型参数数量验证成功: 数量为 1");
|
||||
// Type actualTypeArgument = actualTypeArguments[0];
|
||||
//
|
||||
// if (actualTypeArgument.equals(expectedDynamicType)) {
|
||||
// System.out.println(" - ✅✅✅ 最终验证成功: 泛型参数与期望的 " + expectedDynamicType.getName() + " 完全匹配!");
|
||||
// } else {
|
||||
// System.out.println(" - ❌❌❌ 最终验证失败: 泛型参数是 " + actualTypeArgument.getTypeName() + " 而不是期望的 " + expectedDynamicType.getName());
|
||||
// }
|
||||
// } else {
|
||||
// System.out.println(" - ❌ 泛型参数数量验证失败: 数量不为 1");
|
||||
// }
|
||||
//
|
||||
// } else {
|
||||
// System.out.println("❌ 类型检查失败: 返回类型不是 ParameterizedType,无法进行泛型验证。");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// public void test() throws Exception {
|
||||
// Class<?> liteFlowAIAssistant = createLiteFlowAIAssistant(Output.class);
|
||||
// System.out.println(liteFlowAIAssistant);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 动态创建一个 LiteFlowAIAssistant 接口的实现。
|
||||
// *
|
||||
// * @param dynamicResultType 动态指定的 chat 方法返回结果类型,例如 String.class
|
||||
// * @return 动态生成的接口 Class 对象
|
||||
// * @throws Exception 如果创建失败
|
||||
// */
|
||||
// public static Class<?> createLiteFlowAIAssistant(Class<?> dynamicResultType) throws Exception {
|
||||
//
|
||||
// // 1. 使用 TypeDescription.Generic.Builder 来创建参数化的返回类型
|
||||
// // 这是处理泛型的关键步骤,我们构建一个表示 Result<dynamicResultType> 的类型
|
||||
// TypeDescription.Generic genericResultType = TypeDescription.Generic.Builder
|
||||
// .parameterizedType(Result.class, dynamicResultType)
|
||||
// .build();
|
||||
//
|
||||
// // 2. 使用 ByteBuddy 开始创建接口
|
||||
// DynamicType.Unloaded<?> dynamicType = new ByteBuddy()
|
||||
// // 明确指定我们要创建一个接口
|
||||
// .makeInterface()
|
||||
// // 为接口命名
|
||||
// .name("com.example.generated.DynamicLiteFlowAIAssistant")
|
||||
//
|
||||
// // --- 定义第一个方法: chat ---
|
||||
// .defineMethod("chat", genericResultType, Visibility.PUBLIC)
|
||||
// // 为此方法定义一个泛型参数 <T>
|
||||
// // 注意:即使我们已经将返回类型具体化为 Result<String>,
|
||||
// // 原始接口的方法签名中仍有 <T>,我们在这里进行保留。
|
||||
// // 如果你的目标是完全擦除方法签名中的 <T>,可以省略此行。
|
||||
//// .withTypeVariable("T")
|
||||
// // 添加第一个参数: String userMessage
|
||||
// .withParameter(String.class, "userMessage")
|
||||
// // 为第一个参数添加注解: @V("userMessage")
|
||||
// .annotateParameter(AnnotationDescription.Builder.ofType(V.class)
|
||||
// .define("value", "userMessage")
|
||||
// .build())
|
||||
// // 添加第二个参数: String systemMessage
|
||||
// .withParameter(String.class, "systemMessage")
|
||||
// // 为第二个参数添加注解: @V("systemMessage")
|
||||
// .annotateParameter(AnnotationDescription.Builder.ofType(V.class)
|
||||
// .define("value", "systemMessage")
|
||||
// .build())
|
||||
// .withoutCode()
|
||||
// // 为 chat 方法本身添加注解
|
||||
// .annotateMethod(
|
||||
// // @SystemMessage("{{systemMessage}}")
|
||||
// AnnotationDescription.Builder.ofType(SystemMessage.class)
|
||||
// .defineArray("value", "{{systemMessage}}")
|
||||
// .build(),
|
||||
// // @UserMessage("{{userMessage}}")
|
||||
// AnnotationDescription.Builder.ofType(UserMessage.class)
|
||||
// .defineArray("value", "{{userMessage}}")
|
||||
// .build()
|
||||
// )
|
||||
//
|
||||
// // --- 定义第二个方法: chatStream ---
|
||||
// .defineMethod("chatStream", TokenStream.class, Visibility.PUBLIC)
|
||||
// // 添加参数和注解,逻辑同上
|
||||
// .withParameter(String.class, "userMessage")
|
||||
// .annotateParameter(AnnotationDescription.Builder.ofType(V.class)
|
||||
// .define("value", "userMessage")
|
||||
// .build())
|
||||
// .withParameter(String.class, "systemMessage")
|
||||
// .annotateParameter(AnnotationDescription.Builder.ofType(V.class)
|
||||
// .define("value", "systemMessage")
|
||||
// .build())
|
||||
// .withoutCode()
|
||||
// // 为 chatStream 方法添加注解
|
||||
// .annotateMethod(
|
||||
// AnnotationDescription.Builder.ofType(SystemMessage.class)
|
||||
// .defineArray("value", "{{systemMessage}}")
|
||||
// .build(),
|
||||
// AnnotationDescription.Builder.ofType(UserMessage.class)
|
||||
// .defineArray("value", "{{userMessage}}")
|
||||
// .build()
|
||||
// )
|
||||
//
|
||||
// // 3. 完成创建
|
||||
// .make();
|
||||
//
|
||||
// // 4. 加载生成的类并返回 Class 对象
|
||||
// return dynamicType
|
||||
// .load(AiServiceFactory.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
|
||||
// .getLoaded();
|
||||
// }
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.yomahub.liteflow.test.ai.core.proxy;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*
|
||||
* @author 苍镜月
|
||||
* @since TODO
|
||||
*/
|
||||
|
||||
public class TmpTest {
|
||||
//
|
||||
// @Test
|
||||
// public void test1() {
|
||||
// Provider provider = new Provider() {
|
||||
// @Override
|
||||
// public Optional<String> getString() {
|
||||
// return Optional.empty();
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public Optional<Double> getDouble() {
|
||||
// return Optional.empty();
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// System.out.println(provider.getDouble().orElseThrow(() -> new RuntimeException("No value present")));
|
||||
//
|
||||
// }
|
||||
//
|
||||
//
|
||||
// static interface Provider {
|
||||
// Optional<String> getString();
|
||||
//
|
||||
// Optional<Double> getDouble();
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// public void testProxyFactoryBean() throws Exception {
|
||||
//// AIComponentProxyFactoryBean<cmp> factoryBean = new AIComponentProxyFactoryBean<>(cmp.class);
|
||||
////
|
||||
//// System.out.println(cmp.class.getAnnotations());
|
||||
//// Class<cmp> interfaceClass = factoryBean.getInterfaceClass();
|
||||
//// Class<?> objectType = factoryBean.getObjectType();
|
||||
////
|
||||
//// System.out.println(interfaceClass);
|
||||
//// System.out.println(Arrays.toString(interfaceClass.getAnnotations()));
|
||||
////
|
||||
//// System.out.println(objectType);
|
||||
//// System.out.println(Arrays.toString(objectType.getAnnotations()));
|
||||
// }
|
||||
//
|
||||
// @AIComponent
|
||||
// @AIChat
|
||||
// @AIInput
|
||||
// public interface cmp {}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.test.ai.proxy.cmp;
|
||||
package com.yomahub.liteflow.test.ai.core.proxy.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.test.ai.proxy.cmp;
|
||||
package com.yomahub.liteflow.test.ai.core.proxy.cmp;
|
||||
|
||||
import com.yomahub.liteflow.ai.annotation.*;
|
||||
import com.yomahub.liteflow.ai.domain.enums.ResponseType;
|
||||
@@ -18,7 +18,7 @@ import com.yomahub.liteflow.ai.domain.enums.ResponseType;
|
||||
model = "qwen3:32b"
|
||||
)
|
||||
@AIChat(
|
||||
systemPrompt = "classpath:proxy/system_prompt.txt",
|
||||
systemPrompt = "classpath:core/proxy/system_prompt.txt",
|
||||
userPrompt = "{{question}}, {{answer}}"
|
||||
)
|
||||
@AIInput(
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.test.ai.proxy.cmp;
|
||||
package com.yomahub.liteflow.test.ai.core.proxy.cmp;
|
||||
|
||||
import com.yomahub.liteflow.core.NodeComponent;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.test.ai.proxy.cmp;
|
||||
package com.yomahub.liteflow.test.ai.core.proxy.cmp;
|
||||
|
||||
/**
|
||||
* 测试结构化输出使用
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.yomahub.liteflow.test.ai.util;
|
||||
package com.yomahub.liteflow.test.ai.core.util;
|
||||
|
||||
import com.yomahub.liteflow.ai.util.SetUtil;
|
||||
import com.yomahub.liteflow.ai.util.TriState;
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.yomahub.liteflow.test.ai.model.ollama;
|
||||
|
||||
import com.yomahub.liteflow.ai.interact.transport.TransportType;
|
||||
import com.yomahub.liteflow.ai.engine.interact.transport.TransportType;
|
||||
import com.yomahub.liteflow.ai.model.ollama.constants.OllamaConstant;
|
||||
import com.yomahub.liteflow.ai.model.ollama.interact.OllamaProtocolTransformer;
|
||||
import com.yomahub.liteflow.ai.model.ollama.model.chat.OllamaChatConfig;
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
package com.yomahub.liteflow.test.ai.model.ollama;
|
||||
|
||||
import com.yomahub.liteflow.ai.interact.protocol.ProtocolTransformer;
|
||||
import com.yomahub.liteflow.ai.interact.protocol.ProtocolTransformerFactory;
|
||||
import com.yomahub.liteflow.ai.model.chat.ChatModel;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatOptions;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatRequest;
|
||||
import com.yomahub.liteflow.ai.model.chat.entity.ChatResponse;
|
||||
import com.yomahub.liteflow.ai.model.chat.message.AssistantMessage;
|
||||
import com.yomahub.liteflow.ai.engine.interact.protocol.ProtocolTransformer;
|
||||
import com.yomahub.liteflow.ai.engine.interact.protocol.ProtocolTransformerFactory;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.ChatModel;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatOptions;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatRequest;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.entity.ChatResponse;
|
||||
import com.yomahub.liteflow.ai.engine.model.chat.message.AssistantMessage;
|
||||
import com.yomahub.liteflow.ai.model.ollama.constants.OllamaConstant;
|
||||
import com.yomahub.liteflow.ai.model.ollama.model.chat.OllamaChatConfig;
|
||||
import com.yomahub.liteflow.ai.model.ollama.model.chat.OllamaChatModel;
|
||||
import com.yomahub.liteflow.ai.model.ollama.model.chat.OllamaChatRequest;
|
||||
import com.yomahub.liteflow.ai.model.runtime.ModelRuntimeFactory;
|
||||
import com.yomahub.liteflow.ai.model.runtime.ModelRuntimeRegistrar;
|
||||
import com.yomahub.liteflow.ai.util.SpringUtil;
|
||||
import com.yomahub.liteflow.ai.engine.model.runtime.ModelRuntimeFactory;
|
||||
import com.yomahub.liteflow.ai.engine.model.runtime.ModelRuntimeRegistrar;
|
||||
import com.yomahub.liteflow.ai.engine.util.SpringUtil;
|
||||
import com.yomahub.liteflow.log.LFLog;
|
||||
import com.yomahub.liteflow.log.LFLoggerManager;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -96,8 +96,8 @@ public class ModelFactoryTest {
|
||||
}
|
||||
=========================================
|
||||
2025-07-19 18:43:01.505 INFO 71216 --- [onPool-worker-1] c.y.l.ai.model.ollama.ModelFactoryTest : chat start
|
||||
2025-07-19 18:43:37.115 INFO 71216 --- [onPool-worker-1] com.yomahub.liteflow.ai.util.HttpUtil : 正在关闭 OkHttp 客户端。
|
||||
2025-07-19 18:43:37.117 INFO 71216 --- [onPool-worker-1] com.yomahub.liteflow.ai.util.HttpUtil : OkHttp 客户端已成功关闭。
|
||||
2025-07-19 18:43:37.115 INFO 71216 --- [onPool-worker-1] com.yomahub.liteflow.ai.engine.util.HttpUtil : 正在关闭 OkHttp 客户端。
|
||||
2025-07-19 18:43:37.117 INFO 71216 --- [onPool-worker-1] com.yomahub.liteflow.ai.engine.util.HttpUtil : OkHttp 客户端已成功关闭。
|
||||
2025-07-19 18:43:37.117 INFO 71216 --- [onPool-worker-1] c.y.l.ai.model.ollama.ModelFactoryTest : chat completion:
|
||||
{"model":"qwen3:32b","created_at":"2025-07-19T10:43:37.097945Z","response":"The sky appears blue due to a phenomenon called **Rayleigh scattering**, which involves the way light interacts with the Earth's atmosphere.\n\n### Here's a simple explanation:\n\n1. **Sunlight is made of many colors** — each color has a different wavelength.\n2. When sunlight enters Earth's atmosphere, it collides with molecules and small particles in the air.\n3. **Blue light (shorter wavelengths)** is scattered in all directions by the gases and particles in the atmosphere **much more effectively** than other colors like red or yellow (which have longer wavelengths).\n4. This scattered blue light is what we see when we look up — hence, the **sky appears blue** during the day.\n\n### Why not violet?\nViolet light has an even shorter wavelength than blue and is scattered even more. However, our eyes are less sensitive to violet, and the sun emits less violet light compared to blue. Also, our eyes' cone cells are more responsive to blue light, so we perceive the sky as blue rather than violet.\n\n### Fun facts:\n- During sunrise or sunset, the sky appears red or orange because the sunlight has to pass through more of the Earth's atmosphere, scattering out the blue light and leaving the longer wavelengths (reds and oranges) to dominate.\n\nLet me know if you'd like a more detailed scientific explanation!","done":true,"done_reason":"stop","context":[151644,872,198,10234,12884,374,6303,30,608,2152,5854,766,151645,198,151644,77091,198,151667,271,151668,271,785,12884,7952,6303,4152,311,264,24844,2598,3070,29187,62969,71816,97219,892,17601,279,1616,3100,83161,448,279,9237,594,16566,382,14374,5692,594,264,4285,16148,1447,16,13,3070,30092,4145,374,1865,315,1657,7987,334,1959,1817,1894,702,264,2155,45306,624,17,13,3197,39020,28833,9237,594,16566,11,432,4530,3341,448,34615,323,2613,18730,304,279,3720,624,18,13,3070,10331,3100,320,8676,261,92859,32295,374,36967,304,678,17961,553,279,44512,323,18730,304,279,16566,3070,58078,803,13444,334,1091,1008,7987,1075,2518,476,13753,320,8206,614,5021,92859,4292,19,13,1096,36967,6303,3100,374,1128,582,1490,979,582,1401,705,1959,16085,11,279,3070,26684,7952,6303,334,2337,279,1899,382,14374,8429,537,79736,5267,53,30912,3100,702,458,1496,23327,45306,1091,6303,323,374,36967,1496,803,13,4354,11,1039,6414,525,2686,16216,311,79736,11,323,279,7015,72780,2686,79736,3100,7707,311,6303,13,7281,11,1039,6414,6,22161,7761,525,803,25988,311,6303,3100,11,773,582,44393,279,12884,438,6303,4751,1091,79736,382,14374,16071,13064,510,12,11954,63819,476,42984,11,279,12884,7952,2518,476,18575,1576,279,39020,702,311,1494,1526,803,315,279,9237,594,16566,11,71816,700,279,6303,3100,323,9380,279,5021,92859,320,53369,323,84038,8,311,40736,382,10061,752,1414,421,498,4172,1075,264,803,11682,12344,16148,0],"total_duration":34312626292,"load_duration":3694902292,"prompt_eval_count":21,"prompt_eval_duration":4762227958,"eval_count":270,"eval_duration":25851820750}
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
liteflow:
|
||||
rule-source: core/proxy/flow.el.xml
|
||||
ai:
|
||||
base-packages:
|
||||
- com.liteflow.test.ai.core.proxy.cmp
|
||||
enable: true
|
||||
@@ -1,6 +0,0 @@
|
||||
liteflow:
|
||||
rule-source: proxy/flow.el.xml
|
||||
ai:
|
||||
base-packages:
|
||||
- com.liteflow.test.ai.proxy.cmp
|
||||
enable: true
|
||||
Reference in New Issue
Block a user