Browse Source
Merge pull request #14209 from dashevchenko/aiNodeResourcesFix
[Rule node - AI request] Fixed error when using resources and templatization with Github Models AI provider
pull/14198/head
Viacheslav Klimov
11 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
2 additions and
10 deletions
-
application/src/main/java/org/thingsboard/server/service/ai/AiChatModelServiceImpl.java
-
common/data/src/main/java/org/thingsboard/server/common/data/StringUtils.java
|
|
|
@ -15,6 +15,7 @@ |
|
|
|
*/ |
|
|
|
package org.thingsboard.server.service.ai; |
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.io.JsonStringEncoder; |
|
|
|
import com.google.common.util.concurrent.FluentFuture; |
|
|
|
import dev.langchain4j.data.message.ChatMessage; |
|
|
|
import dev.langchain4j.data.message.Content; |
|
|
|
@ -32,8 +33,6 @@ import org.thingsboard.server.common.data.ai.model.chat.Langchain4jChatModelConf |
|
|
|
import java.util.List; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
import static org.thingsboard.server.common.data.StringUtils.escapeControlChars; |
|
|
|
|
|
|
|
@Service |
|
|
|
@RequiredArgsConstructor |
|
|
|
class AiChatModelServiceImpl implements AiChatModelService { |
|
|
|
@ -74,7 +73,7 @@ class AiChatModelServiceImpl implements AiChatModelService { |
|
|
|
|
|
|
|
private Content prepareContent(Content content) { |
|
|
|
if (content instanceof TextContent txt) { |
|
|
|
return new TextContent(escapeControlChars(txt.text())); |
|
|
|
return new TextContent(new String(JsonStringEncoder.getInstance().quoteAsString(txt.text()))); |
|
|
|
} |
|
|
|
return content; |
|
|
|
} |
|
|
|
|
|
|
|
@ -275,11 +275,4 @@ public class StringUtils { |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
public static String escapeControlChars(String text) { |
|
|
|
return text |
|
|
|
.replace("\n", "\\n") |
|
|
|
.replace("\r", "\\r") |
|
|
|
.replace("\t", "\\t"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|