You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@seatunnel.apache.org by "SplitfireUptown (via GitHub)" <gi...@apache.org> on 2025/01/17 14:51:41 UTC

[PR] [Feature][seatunnel-transforms-v2] LLM transform Support Ollama return format #8550 [seatunnel]

SplitfireUptown opened a new pull request, #8551:
URL: https://github.com/apache/seatunnel/pull/8551

   <!--
   
   Thank you for contributing to SeaTunnel! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   ## Contribution Checklist
     - Make sure that the pull request corresponds to a [GITHUB issue](https://github.com/apache/seatunnel/issues).
     - Name the pull request in the form "[Feature] [component] Title of the pull request", where *Feature* can be replaced by `Hotfix`, `Bug`, etc.
     - Minor fixes should be named following this pattern: `[hotfix] [docs] Fix typo in README.md doc`.
   -->
   
   ### Purpose of this pull request
   
   <!-- Describe the purpose of this pull request. For example: This pull request adds checkstyle plugin.-->
   
   
   ### Does this PR introduce _any_ user-facing change?
   
   <!--
   Note that it means *any* user-facing change including all aspects such as the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to the released SeaTunnel versions or within the unreleased branches such as dev.
   If no, write 'No'.
   If you are adding/modifying connector documents, please follow our new specifications: https://github.com/apache/seatunnel/issues/4544.
   -->
   
   
   ### How was this patch tested?
   
   <!--
   If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
   If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why it was difficult to add.
   If you are adding E2E test cases, maybe refer to https://github.com/apache/seatunnel/blob/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/connector-cdc-mysql-e2e/src/test/resources/mysqlcdc_to_mysql.conf, here is a good example.
   -->
   
   
   ### Check list
   
   * [ ] If any new Jar binary package adding in your PR, please add License Notice according
     [New License Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/contribution/new-license.md)
   * [ ] If necessary, please update the documentation to describe the new feature. https://github.com/apache/seatunnel/tree/dev/docs
   * [ ] If you are contributing the connector code, please check that the following files are updated:
     1. Update [plugin-mapping.properties](https://github.com/apache/seatunnel/blob/dev/plugin-mapping.properties) and add new connector information in it
     2. Update the pom file of [seatunnel-dist](https://github.com/apache/seatunnel/blob/dev/seatunnel-dist/pom.xml)
     3. Add ci label in [label-scope-conf](https://github.com/apache/seatunnel/blob/dev/.github/workflows/labeler/label-scope-conf.yml)
     4. Add e2e testcase in [seatunnel-e2e](https://github.com/apache/seatunnel/tree/dev/seatunnel-e2e/seatunnel-connector-v2-e2e/)
     5. Update connector [plugin_config](https://github.com/apache/seatunnel/blob/dev/config/plugin_config)
   * [ ] Update the [`release-note`](https://github.com/apache/seatunnel/blob/dev/release-note.md).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][seatunnel-transforms-v2] LLM transform Support Ollama return format #8550 [seatunnel]

Posted by "corgy-w (via GitHub)" <gi...@apache.org>.
corgy-w commented on PR #8551:
URL: https://github.com/apache/seatunnel/pull/8551#issuecomment-2608982640

   > > Could you add a test case for this? Thanks
   > 
   > i commit a new test case, please check it
   
   @SplitfireUptown Remember to retry the failure ci
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][seatunnel-transforms-v2] LLM transform Support Ollama return format #8550 [seatunnel]

Posted by "SplitfireUptown (via GitHub)" <gi...@apache.org>.
SplitfireUptown commented on PR #8551:
URL: https://github.com/apache/seatunnel/pull/8551#issuecomment-2610020811

   > > > Could you add a test case for this? Thanks
   > > 
   > > 
   > > i commit a new test case, please check it
   > 
   > @SplitfireUptown Remember to retry the failure ci
   
   please help me, i dont konw why doris test case report this error
   ![image](https://github.com/user-attachments/assets/b3d96fd6-ae9b-474a-8e62-27bed2a2e459)
   
   
   and  kafka test case log can not find any error log, but status is fail


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][Transforms-V2] Handling LLM non-standard format responses [seatunnel]

Posted by "SplitfireUptown (via GitHub)" <gi...@apache.org>.
SplitfireUptown commented on code in PR #8551:
URL: https://github.com/apache/seatunnel/pull/8551#discussion_r1957275977


##########
seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/llm/LLMRequestJsonTest.java:
##########
@@ -209,4 +215,80 @@ void testCustomRequestJson() throws IOException {
                 "{\"messages\":[{\"role\":\"system\",\"content\":\"Determine whether someone is Chinese or American by their name\"},{\"role\":\"user\",\"content\":\"{\\\"id\\\":1, \\\"name\\\":\\\"John\\\"}\"}],\"model\":\"custom-model\"}",
                 OBJECT_MAPPER.writeValueAsString(node));
     }
+
+    @Mock
+    private HttpClient httpClient;
+
+    @Test
+    void testCustomOllamaRequestJson() throws IOException {
+
+        MockWebServer mockWebServer = new MockWebServer();
+        mockWebServer.start(11434);
+        // 设置模拟的 JSON 响应
+        String jsonResponse = "{\n" +
+                "    \"model\": \"qwen:7b\",\n" +
+                "    \"created_at\": \"2025-02-07T01:22:46.589856Z\",\n" +
+                "    \"message\": {\n" +
+                "        \"role\": \"assistant\",\n" +
+                "        \"content\": \"Based on the information provided in the JSON object, \\\"John\\\" does not inherently indicate if the person is Chinese or American. The name \\\"John\\\" is commonly used across many cultures. To determine a person's nationality based solely on their name, more context would be needed.\"\n" +
+                "    },\n" +
+                "    \"done_reason\": \"stop\",\n" +
+                "    \"done\": true,\n" +
+                "    \"total_duration\": 14435322300,\n" +
+                "    \"load_duration\": 28998200,\n" +
+                "    \"prompt_eval_count\": 34,\n" +
+                "    \"prompt_eval_duration\": 302000000,\n" +
+                "    \"eval_count\": 56,\n" +
+                "    \"eval_duration\": 14102000000\n" +
+                "}";
+
+        // 向 MockWebServer 添加响应

Review Comment:
   code is ok please check it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][seatunnel-transforms-v2] LLM transform Support Ollama return format #8550 [seatunnel]

Posted by "SplitfireUptown (via GitHub)" <gi...@apache.org>.
SplitfireUptown commented on PR #8551:
URL: https://github.com/apache/seatunnel/pull/8551#issuecomment-2601512110

   > Could you add a test case for this? Thanks
   
   ok, this is my first time to submit an open source project pr. please forgive me


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][seatunnel-transforms-v2] LLM transform Support Ollama return format #8550 [seatunnel]

Posted by "corgy-w (via GitHub)" <gi...@apache.org>.
corgy-w commented on code in PR #8551:
URL: https://github.com/apache/seatunnel/pull/8551#discussion_r1923086606


##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/nlpmodel/llm/remote/custom/CustomModel.java:
##########
@@ -94,8 +95,15 @@ protected List<String> chatWithModel(String promptWithLimit, String rowsJson)
         if (response.getStatusLine().getStatusCode() != 200) {
             throw new IOException("Failed to get vector from custom, response: " + responseStr);
         }
-        return OBJECT_MAPPER.convertValue(
-                parseResponse(responseStr), new TypeReference<List<String>>() {});
+        try {
+            return OBJECT_MAPPER.convertValue(
+                    parseResponse(responseStr), new TypeReference<List<String>>() {});
+        } catch (Exception e) {

Review Comment:
   get



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][seatunnel-transforms-v2] LLM transform Support Ollama return format #8550 [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on PR #8551:
URL: https://github.com/apache/seatunnel/pull/8551#issuecomment-2611360693

   Please retry failed ci.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][seatunnel-transforms-v2] LLM transform Support Ollama return format #8550 [seatunnel]

Posted by "SplitfireUptown (via GitHub)" <gi...@apache.org>.
SplitfireUptown commented on code in PR #8551:
URL: https://github.com/apache/seatunnel/pull/8551#discussion_r1923080697


##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/nlpmodel/llm/remote/custom/CustomModel.java:
##########
@@ -94,8 +95,15 @@ protected List<String> chatWithModel(String promptWithLimit, String rowsJson)
         if (response.getStatusLine().getStatusCode() != 200) {
             throw new IOException("Failed to get vector from custom, response: " + responseStr);
         }
-        return OBJECT_MAPPER.convertValue(
-                parseResponse(responseStr), new TypeReference<List<String>>() {});
+        try {
+            return OBJECT_MAPPER.convertValue(
+                    parseResponse(responseStr), new TypeReference<List<String>>() {});
+        } catch (Exception e) {

Review Comment:
   that better,but origin code were not handling exception here



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][Transforms-V2] Handling LLM non-standard format responses [seatunnel]

Posted by "hailin0 (via GitHub)" <gi...@apache.org>.
hailin0 merged PR #8551:
URL: https://github.com/apache/seatunnel/pull/8551


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][seatunnel-transforms-v2] LLM transform Support Ollama return format #8550 [seatunnel]

Posted by "SplitfireUptown (via GitHub)" <gi...@apache.org>.
SplitfireUptown commented on PR #8551:
URL: https://github.com/apache/seatunnel/pull/8551#issuecomment-2608979696

   > Could you add a test case for this? Thanks
   
   i commit a new test case, please check it


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][seatunnel-transforms-v2] LLM transform Support Ollama return format #8550 [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on PR #8551:
URL: https://github.com/apache/seatunnel/pull/8551#issuecomment-2601243791

   Could you add a test case for this? Thanks


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][Transforms-V2] Handling LLM non-standard format responses [seatunnel]

Posted by "SplitfireUptown (via GitHub)" <gi...@apache.org>.
SplitfireUptown commented on code in PR #8551:
URL: https://github.com/apache/seatunnel/pull/8551#discussion_r1955770872


##########
seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/llm/LLMRequestJsonTest.java:
##########
@@ -209,4 +208,50 @@ void testCustomRequestJson() throws IOException {
                 "{\"messages\":[{\"role\":\"system\",\"content\":\"Determine whether someone is Chinese or American by their name\"},{\"role\":\"user\",\"content\":\"{\\\"id\\\":1, \\\"name\\\":\\\"John\\\"}\"}],\"model\":\"custom-model\"}",
                 OBJECT_MAPPER.writeValueAsString(node));
     }
+
+    @Test
+    void testCustomOllamaRequestJson() throws IOException {

Review Comment:
   emmmm,new code add in  org.apache.seatunnel.transform.nlpmodel.llm.remote.custom.CustomModel#chatWithModel,i need call org.apache.seatunnel.transform.nlpmodel.llm.remote.AbstractModel#inference in test code, if i want test it,i need a server to mock ollama data, because request http interface code and new code in one function,i try many time and dont know how can i run it in  outside test code。can u help me please



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][seatunnel-transforms-v2] LLM transform Support Ollama return format #8550 [seatunnel]

Posted by "SplitfireUptown (via GitHub)" <gi...@apache.org>.
SplitfireUptown commented on PR #8551:
URL: https://github.com/apache/seatunnel/pull/8551#issuecomment-2638929455

   > Please retry failed ci.
   
   all ci successful


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][seatunnel-transforms-v2] LLM transform Support Ollama return format #8550 [seatunnel]

Posted by "Hisoka-X (via GitHub)" <gi...@apache.org>.
Hisoka-X commented on code in PR #8551:
URL: https://github.com/apache/seatunnel/pull/8551#discussion_r1944164440


##########
seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/llm/LLMRequestJsonTest.java:
##########
@@ -209,4 +208,50 @@ void testCustomRequestJson() throws IOException {
                 "{\"messages\":[{\"role\":\"system\",\"content\":\"Determine whether someone is Chinese or American by their name\"},{\"role\":\"user\",\"content\":\"{\\\"id\\\":1, \\\"name\\\":\\\"John\\\"}\"}],\"model\":\"custom-model\"}",
                 OBJECT_MAPPER.writeValueAsString(node));
     }
+
+    @Test
+    void testCustomOllamaRequestJson() throws IOException {

Review Comment:
   The test case can not reach the new code. I think you can use `Mockito` to [set http response](https://github.com/apache/seatunnel/pull/8551/files#diff-5cb1c07d7e029bd5547f51c1de022f53569c993806c5e08b426676cc930e0298R91) then parse it by the code you added. Please refer https://github.com/apache/seatunnel/blob/99fa19d2eab95b68dd79e27866233bd950efb166/seatunnel-engine/seatunnel-engine-core/src/test/java/org/apache/seatunnel/engine/core/classloader/ClassLoaderServiceTest.java#L117



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][seatunnel-transforms-v2] LLM transform Support Ollama return format #8550 [seatunnel]

Posted by "corgy-w (via GitHub)" <gi...@apache.org>.
corgy-w commented on code in PR #8551:
URL: https://github.com/apache/seatunnel/pull/8551#discussion_r1923039668


##########
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/nlpmodel/llm/remote/custom/CustomModel.java:
##########
@@ -94,8 +95,15 @@ protected List<String> chatWithModel(String promptWithLimit, String rowsJson)
         if (response.getStatusLine().getStatusCode() != 200) {
             throw new IOException("Failed to get vector from custom, response: " + responseStr);
         }
-        return OBJECT_MAPPER.convertValue(
-                parseResponse(responseStr), new TypeReference<List<String>>() {});
+        try {
+            return OBJECT_MAPPER.convertValue(
+                    parseResponse(responseStr), new TypeReference<List<String>>() {});
+        } catch (Exception e) {

Review Comment:
   Is it possible to specify the error here? 
   eg:
   `   try {
           return OBJECT_MAPPER.convertValue(
                   parseResponse(responseStr), new TypeReference<List<String>>() {});
       } catch (IllegalArgumentException or  xxxx e) {
           try {
               String result = OBJECT_MAPPER.convertValue(
                       parseResponse(responseStr), new TypeReference<String>() {});
               return Collections.singletonList(result);
           } catch (Exception ex) {
             xxxxx
           }
       }`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][Transforms-V2] Handling LLM non-standard format responses [seatunnel]

Posted by "corgy-w (via GitHub)" <gi...@apache.org>.
corgy-w commented on code in PR #8551:
URL: https://github.com/apache/seatunnel/pull/8551#discussion_r1955785239


##########
seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/llm/LLMRequestJsonTest.java:
##########
@@ -209,4 +215,80 @@ void testCustomRequestJson() throws IOException {
                 "{\"messages\":[{\"role\":\"system\",\"content\":\"Determine whether someone is Chinese or American by their name\"},{\"role\":\"user\",\"content\":\"{\\\"id\\\":1, \\\"name\\\":\\\"John\\\"}\"}],\"model\":\"custom-model\"}",
                 OBJECT_MAPPER.writeValueAsString(node));
     }
+
+    @Mock
+    private HttpClient httpClient;
+
+    @Test
+    void testCustomOllamaRequestJson() throws IOException {
+
+        MockWebServer mockWebServer = new MockWebServer();
+        mockWebServer.start(11434);
+        // 设置模拟的 JSON 响应
+        String jsonResponse = "{\n" +
+                "    \"model\": \"qwen:7b\",\n" +
+                "    \"created_at\": \"2025-02-07T01:22:46.589856Z\",\n" +
+                "    \"message\": {\n" +
+                "        \"role\": \"assistant\",\n" +
+                "        \"content\": \"Based on the information provided in the JSON object, \\\"John\\\" does not inherently indicate if the person is Chinese or American. The name \\\"John\\\" is commonly used across many cultures. To determine a person's nationality based solely on their name, more context would be needed.\"\n" +
+                "    },\n" +
+                "    \"done_reason\": \"stop\",\n" +
+                "    \"done\": true,\n" +
+                "    \"total_duration\": 14435322300,\n" +
+                "    \"load_duration\": 28998200,\n" +
+                "    \"prompt_eval_count\": 34,\n" +
+                "    \"prompt_eval_duration\": 302000000,\n" +
+                "    \"eval_count\": 56,\n" +
+                "    \"eval_duration\": 14102000000\n" +
+                "}";
+
+        // 向 MockWebServer 添加响应

Review Comment:
   Remind you to develop the habit of commenting in En



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Feature][Transforms-V2] Handling LLM non-standard format responses [seatunnel]

Posted by "SplitfireUptown (via GitHub)" <gi...@apache.org>.
SplitfireUptown commented on code in PR #8551:
URL: https://github.com/apache/seatunnel/pull/8551#discussion_r1955783232


##########
seatunnel-transforms-v2/src/test/java/org/apache/seatunnel/transform/llm/LLMRequestJsonTest.java:
##########
@@ -209,4 +208,50 @@ void testCustomRequestJson() throws IOException {
                 "{\"messages\":[{\"role\":\"system\",\"content\":\"Determine whether someone is Chinese or American by their name\"},{\"role\":\"user\",\"content\":\"{\\\"id\\\":1, \\\"name\\\":\\\"John\\\"}\"}],\"model\":\"custom-model\"}",
                 OBJECT_MAPPER.writeValueAsString(node));
     }
+
+    @Test
+    void testCustomOllamaRequestJson() throws IOException {

Review Comment:
   nerver mind i got it!  



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@seatunnel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org