Skip to content

Commit 15368cd

Browse files
author
kevin
committed
fix StreamingMerger.java、MultiModalConversation.java、ImageGeneration.java
1 parent 563f18e commit 15368cd

6 files changed

Lines changed: 31 additions & 13 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Conversation conversation = new Conversation(Protocol.HTTP.getValue());
3333
Conversation conversation = new Conversation(Protocol.WEBSOCKET.getValue());
3434
```
3535

36-
The conversation interface supports both stream and non-stream queries. These queries all accept `ConversationParam` as input, and returns `ConversationResult` as output . Each model has a unique input structure and output structure which derives from the two data classes mentioned above. Please use these sub classes when you are using the coordinating model.
36+
The conversation interface supports both stream and non-stream queries. These queries all accept `ConversationParam` as input, and returns `ConversationResult` as output . Each model has a unique input structure and output structure which derives from the two data classes mentioned above. Please use these sub classes when you are using the coordinating model.
3737

3838
Here shows the usages of each method, with the examples of `qwen-turbo` model.
3939

src/main/java/com/alibaba/dashscope/aigc/imagegeneration/ImageGeneration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ private ImageGenerationResult mergeSingleResponse(
408408
}
409409
// Always set the accumulated content if we have any
410410
if (!accumulated.content.isEmpty()) {
411-
choice.getMessage().setContent(accumulated.content);
411+
choice.getMessage().setContent(StreamingMerger.copyContent(accumulated.content));
412412
}
413413
}
414414
}

src/main/java/com/alibaba/dashscope/aigc/multimodalconversation/MultiModalConversation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ private MultiModalConversationResult mergeSingleResponse(
341341
}
342342
// Always set the accumulated content if we have any
343343
if (!accumulated.content.isEmpty()) {
344-
choice.getMessage().setContent(accumulated.content);
344+
choice.getMessage().setContent(StreamingMerger.copyContent(accumulated.content));
345345
}
346346

347347
// Handle reasoning_content accumulation

src/main/java/com/alibaba/dashscope/utils/StreamingMerger.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import com.alibaba.dashscope.tools.ToolCallBase;
55
import com.alibaba.dashscope.tools.ToolCallFunction;
6+
import java.util.ArrayList;
67
import java.util.HashMap;
78
import java.util.List;
89
import java.util.Map;
@@ -53,6 +54,23 @@ public static void mergeTextContent(
5354
}
5455
}
5556

57+
public static List<Map<String, Object>> copyContent(
58+
List<Map<String, Object>> accumulatedContent) {
59+
List<Map<String, Object>> copiedContent = new ArrayList<>();
60+
if (accumulatedContent == null) {
61+
return copiedContent;
62+
}
63+
64+
for (Map<String, Object> contentItem : accumulatedContent) {
65+
if (contentItem == null) {
66+
copiedContent.add(null);
67+
} else {
68+
copiedContent.add(new HashMap<>(contentItem));
69+
}
70+
}
71+
return copiedContent;
72+
}
73+
5674
public static void mergeToolCalls(
5775
List<ToolCallBase> currentToolCalls, List<ToolCallBase> accumulatedToolCalls) {
5876
if (currentToolCalls == null || accumulatedToolCalls == null) {

src/test/resources/mismatch.jsonl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
{"HumanAnswer": "2个读音  一个是xi 一个是qian",
2-
"Python": [24918, 18947, 57553, 78685, 22441, 22441, 108075, 144767, 144155, 22441, 108075, 145529, 144155, 144127, 144270],
1+
{"HumanAnswer": "2个读音  一个是xi 一个是qian",
2+
"Python": [24918, 18947, 57553, 78685, 22441, 22441, 108075, 144767, 144155, 22441, 108075, 145529, 144155, 144127, 144270],
33
"Java": [24918, 18947, 57553, 78685, 43429, 108075, 144767, 144155, 22441, 108075, 145529, 144155, 144127, 144270]}
4-
{"HumanAnswer": "炸腐竹·油温要适中·炸后浸温水
4+
{"HumanAnswer": "炸腐竹·油温要适中·炸后浸温水
55
  要腐竹炸得刚好而不焦黑,秘诀是当生油烧至六成熟时转慢火,然后放下腐竹,迅速地翻动,让腐竹全身炸透,呈现白泡,并即投入温水中浸透,再切段。炸时如油温过热,会将腐竹炸焦,变深黄色或黑色,如油温不够热,则不会起白泡。 ", "Python": [100893, 100298, 102045, 13935, 99318, 99416, 30534, 99340, 15946, 13935, 100893, 33447, 101595, 99416, 52510, 2529, 22441, 22441, 30534, 100298, 102045, 100893, 49828, 109586, 105145, 100479, 56652, 3837, 114928, 20412, 39165, 21287, 99318, 100228, 56137, 99566, 102226, 13343, 46670, 99843, 79599, 3837, 101889, 106162, 100298, 102045, 3837, 104015, 29490, 100712, 27733, 3837, 99258, 100298, 102045, 105418, 100893, 99844, 3837, 104401, 99243, 100454, 90395, 91676, 100709, 99416, 107629, 101595, 99844, 3837, 87256, 99322, 37474, 1773, 100893, 13343, 29524, 99318, 99416, 38182, 99259, 3837, 36993, 44063, 100298, 102045, 100893, 100479, 3837, 74040, 99194, 106140, 57191, 104723, 3837, 29524, 99318, 99416, 104222, 99259, 95053, 99670, 71618, 99243, 100454, 1773, 220], "Java": [100893, 100298, 102045, 13935, 99318, 99416, 30534, 99340, 15946, 13935, 100893, 33447, 101595, 99416, 52510, 2529, 43429, 30534, 100298, 102045, 100893, 49828, 109586, 105145, 100479, 56652, 3837, 114928, 20412, 39165, 21287, 99318, 100228, 56137, 99566, 102226, 13343, 46670, 99843, 79599, 3837, 101889, 106162, 100298, 102045, 3837, 104015, 29490, 100712, 27733, 3837, 99258, 100298, 102045, 105418, 100893, 99844, 3837, 104401, 99243, 100454, 90395, 91676, 100709, 99416, 107629, 101595, 99844, 3837, 87256, 99322, 37474, 1773, 100893, 13343, 29524, 99318, 99416, 38182, 99259, 3837, 36993, 44063, 100298, 102045, 100893, 100479, 3837, 74040, 99194, 106140, 57191, 104723, 3837, 29524, 99318, 99416, 104222, 99259, 95053, 99670, 71618, 99243, 100454, 1773, 220]}
66
{"HumanAnswer": "  你好,癫痫病频频发作容易造成癫痫患者的脑发育障碍、组织结构毁坏、代谢异常,必然也影响其所有心理发育的领域,对于脑器质性损害伴发的癫痫,往往伴有智力损害及行为问题。一般癫痫发生愈早,程度愈重,对心理、精神行为的影响也愈大。
77
", "Python": [22441, 22441, 108386, 3837, 113282, 111972, 107253, 100047, 101090, 103440, 108723, 99931, 106115, 102544, 5373, 99877, 100166, 100882, 100250, 5373, 103225, 70633, 3837, 102309, 74763, 99564, 41146, 55338, 100438, 106115, 9370, 100650, 3837, 100002, 99931, 31548, 99178, 33071, 105252, 99595, 28291, 9370, 103440, 3837, 101207, 115563, 107941, 105252, 81217, 101070, 86119, 1773, 100141, 103440, 99726, 100939, 99391, 3837, 100069, 100939, 29258, 3837, 32664, 100438, 5373, 100150, 101070, 104126, 74763, 100939, 26288, 37265], "Java": [43429, 108386, 3837, 113282, 111972, 107253, 100047, 101090, 103440, 108723, 99931, 106115, 102544, 5373, 99877, 100166, 100882, 100250, 5373, 103225, 70633, 3837, 102309, 74763, 99564, 41146, 55338, 100438, 106115, 9370, 100650, 3837, 100002, 99931, 31548, 99178, 33071, 105252, 99595, 28291, 9370, 103440, 3837, 101207, 115563, 107941, 105252, 81217, 101070, 86119, 1773, 100141, 103440, 99726, 100939, 99391, 3837, 100069, 100939, 29258, 3837, 32664, 100438, 5373, 100150, 101070, 104126, 74763, 100939, 26288, 37265]}
@@ -10,7 +10,7 @@
1010
", "Python": [85336, 116350, 104160, 39907, 99604, 99999, 97480, 36993, 99518, 102478, 3837, 102716, 104160, 18830, 319, 22441, 16, 5373, 99950, 100553, 24339, 9909, 99393, 99451, 24339, 7552, 85336, 116350, 220, 22441, 22441, 17, 5373, 29767, 101953, 24339, 85336, 116350, 220, 22441, 18, 5373, 105608, 24339, 85336, 116350, 220, 22441, 22441, 19, 5373, 99759, 64952, 32320, 99368, 24339, 85336, 116350, 220, 22441, 20, 5373, 47815, 76837, 99322, 29767, 24339, 85336, 116350, 220, 100700, 99559, 30440, 118393, 100849, 105157, 104316, 31139, 319], "Java": [85336, 116350, 104160, 39907, 99604, 99999, 97480, 36993, 99518, 102478, 3837, 102716, 104160, 18830, 319, 22441, 16, 5373, 99950, 100553, 24339, 9909, 99393, 99451, 24339, 7552, 85336, 116350, 220, 43429, 17, 5373, 29767, 101953, 24339, 85336, 116350, 220, 22441, 18, 5373, 105608, 24339, 85336, 116350, 220, 43429, 19, 5373, 99759, 64952, 32320, 99368, 24339, 85336, 116350, 220, 22441, 20, 5373, 47815, 76837, 99322, 29767, 24339, 85336, 116350, 220, 100700, 99559, 30440, 118393, 100849, 105157, 104316, 31139, 319]}
1111
{"HumanAnswer": "  你好,过敏性鼻炎喷嚏、鼻痒、流涕和鼻堵是最常见的四大症状。目前临床上主要是应用内窥镜下等离子低温消融术,选择性地进行筛前神经、翼管神经阻断术,降低鼻腔副交感神经的兴奋性,消除过敏区域神经对外界各种刺激,如气候、灰尘、花粉等的敏感性,过敏性鼻炎就可以自然而愈,不易复发。
1212
", "Python": [22441, 22441, 108386, 11, 107270, 33071, 102228, 100439, 102125, 121875, 5373, 102228, 108681, 5373, 88653, 119392, 33108, 102228, 101476, 104890, 102716, 104978, 101368, 1773, 100004, 99635, 101717, 104312, 99892, 31843, 112808, 100811, 16872, 49567, 108510, 109878, 32320, 99368, 99216, 3837, 50404, 33071, 29490, 71817, 101737, 24562, 102398, 5373, 101401, 35551, 102398, 100318, 63789, 99216, 3837, 101134, 102228, 102504, 99310, 38109, 98650, 102398, 9370, 105487, 33071, 3837, 105109, 107270, 101065, 102398, 102330, 97120, 100646, 104313, 3837, 29524, 102730, 5373, 114267, 5373, 99232, 99742, 49567, 9370, 105521, 33071, 3837, 107270, 33071, 102228, 100439, 102003, 117536, 100939, 3837, 106921, 111574, 8997], "Java": [43429, 108386, 11, 107270, 33071, 102228, 100439, 102125, 121875, 5373, 102228, 108681, 5373, 88653, 119392, 33108, 102228, 101476, 104890, 102716, 104978, 101368, 1773, 100004, 99635, 101717, 104312, 99892, 31843, 112808, 100811, 16872, 49567, 108510, 109878, 32320, 99368, 99216, 3837, 50404, 33071, 29490, 71817, 101737, 24562, 102398, 5373, 101401, 35551, 102398, 100318, 63789, 99216, 3837, 101134, 102228, 102504, 99310, 38109, 98650, 102398, 9370, 105487, 33071, 3837, 105109, 107270, 101065, 102398, 102330, 97120, 100646, 104313, 3837, 29524, 102730, 5373, 114267, 5373, 99232, 99742, 49567, 9370, 105521, 33071, 3837, 107270, 33071, 102228, 100439, 102003, 117536, 100939, 3837, 106921, 111574, 8997]}
13-
{"HumanAnswer": "  新生婴儿应在出生后一个月内,到父亲或母亲户口所在地的户口登记机关(辖区派出所)办理出生入户登记。
13+
{"HumanAnswer": "  新生婴儿应在出生后一个月内,到父亲或母亲户口所在地的户口登记机关(辖区派出所)办理出生入户登记。
1414
  办理时需提供以下材料:
1515
  1、小孩的出生医学证明
1616
  2、父母的户口簿、身份证和结婚证。", "Python": [22441, 22441, 102900, 102833, 110391, 102246, 33447, 105033, 31843, 3837, 26939, 102037, 57191, 102079, 109200, 108176, 9370, 109200, 104141, 100776, 9909, 103022, 106644, 7552, 103990, 102246, 111981, 104141, 1773, 2529, 22441, 22441, 103990, 13343, 58362, 99553, 87752, 100643, 5122, 319, 22441, 22441, 16, 5373, 104902, 9370, 102246, 104316, 104022, 319, 22441, 22441, 17, 5373, 103953, 9370, 109200, 113649, 5373, 105765, 33108, 104388, 33477, 1773], "Java": [43429, 102900, 102833, 110391, 102246, 33447, 105033, 31843, 3837, 26939, 102037, 57191, 102079, 109200, 108176, 9370, 109200, 104141, 100776, 9909, 103022, 106644, 7552, 103990, 102246, 111981, 104141, 1773, 2529, 43429, 103990, 13343, 58362, 99553, 87752, 100643, 5122, 319, 43429, 16, 5373, 104902, 9370, 102246, 104316, 104022, 319, 43429, 17, 5373, 103953, 9370, 109200, 113649, 5373, 105765, 33108, 104388, 33477, 1773]}
@@ -59,7 +59,7 @@
5959
{"HumanAnswer": "1.及时治疗:主要是改善脑血液循环。可以在医生的指导下使用扩血管药物和银杏叶制剂等。  2.早期预防:对脑供血不足的防治重点在脑血管方面,尤其是血脂和低密度脂蛋白增高要对症处理。  3.合理饮食:平时多吃新鲜蔬菜(如洋葱、西红柿等)、水果、鱼、黑木耳、少量醋、干红葡萄酒等,可以起抗氧化作用,延缓脑动脉硬化的发生。  4.适当的户外活动:如快走、慢跑、散步等,每次30-40分钟,每周至少5天,或者打打太极拳、垂钓、登山等。  5.保持良好的心态和健康用脑:平时看看电视、报纸;做些手工劳作或家务事;也可以参加一些文体活动,如唱歌、跳舞、书法、打球等,调制性情,增强脑的思维活动;避免情绪激动和过度疲劳。", "Python": [16, 58883, 100667, 101899, 5122, 104312, 104009, 99931, 116417, 1773, 104964, 103998, 9370, 109767, 37029, 99834, 102890, 104459, 33108, 99660, 108202, 100027, 115031, 49567, 1773, 22441, 22441, 17, 58883, 105184, 104332, 5122, 32664, 99931, 83744, 99389, 102004, 9370, 102681, 99887, 18493, 99931, 102890, 99522, 3837, 104033, 118112, 33108, 99285, 106651, 100553, 102835, 117015, 30534, 32664, 99769, 54542, 1773, 22441, 22441, 18, 58883, 100745, 104579, 5122, 104325, 108851, 104838, 104451, 7, 29524, 117956, 5373, 117700, 49567, 8, 5373, 104618, 5373, 100655, 5373, 56652, 116690, 5373, 108521, 106960, 5373, 99251, 99425, 107358, 49567, 3837, 73670, 71618, 118283, 100154, 3837, 99771, 99982, 99931, 109826, 99927, 105302, 99726, 1773, 22441, 22441, 19, 58883, 109776, 105813, 99600, 5122, 29524, 99234, 99314, 5373, 99843, 99803, 5373, 111261, 49567, 3837, 102173, 18, 15, 12, 19, 15, 83031, 3837, 106854, 104102, 20, 35727, 3837, 100631, 75437, 75437, 116674, 5373, 102566, 103429, 5373, 112357, 49567, 1773, 22441, 22441, 20, 58883, 100662, 104205, 106479, 33108, 99722, 11622, 99931, 5122, 104325, 101997, 100234, 5373, 107574, 24968, 99190, 97084, 107171, 99697, 19403, 57191, 114791, 29826, 24968, 104047, 101061, 101883, 111048, 99600, 3837, 29524, 109283, 5373, 112084, 5373, 102702, 5373, 117248, 49567, 3837, 47872, 43316, 33071, 39374, 3837, 101138, 99931, 9370, 102141, 99600, 24968, 101153, 104405, 105694, 33108, 105831, 108351, 1773], "Java": [16, 58883, 100667, 101899, 5122, 104312, 104009, 99931, 116417, 1773, 104964, 103998, 9370, 109767, 37029, 99834, 102890, 104459, 33108, 99660, 108202, 100027, 115031, 49567, 1773, 43429, 17, 58883, 105184, 104332, 5122, 32664, 99931, 83744, 99389, 102004, 9370, 102681, 99887, 18493, 99931, 102890, 99522, 3837, 104033, 118112, 33108, 99285, 106651, 100553, 102835, 117015, 30534, 32664, 99769, 54542, 1773, 43429, 18, 58883, 100745, 104579, 5122, 104325, 108851, 104838, 104451, 7, 29524, 117956, 5373, 117700, 49567, 8, 5373, 104618, 5373, 100655, 5373, 56652, 116690, 5373, 108521, 106960, 5373, 99251, 99425, 107358, 49567, 3837, 73670, 71618, 118283, 100154, 3837, 99771, 99982, 99931, 109826, 99927, 105302, 99726, 1773, 43429, 19, 58883, 109776, 105813, 99600, 5122, 29524, 99234, 99314, 5373, 99843, 99803, 5373, 111261, 49567, 3837, 102173, 18, 15, 12, 19, 15, 83031, 3837, 106854, 104102, 20, 35727, 3837, 100631, 75437, 75437, 116674, 5373, 102566, 103429, 5373, 112357, 49567, 1773, 43429, 20, 58883, 100662, 104205, 106479, 33108, 99722, 11622, 99931, 5122, 104325, 101997, 100234, 5373, 107574, 24968, 99190, 97084, 107171, 99697, 19403, 57191, 114791, 29826, 24968, 104047, 101061, 101883, 111048, 99600, 3837, 29524, 109283, 5373, 112084, 5373, 102702, 5373, 117248, 49567, 3837, 47872, 43316, 33071, 39374, 3837, 101138, 99931, 9370, 102141, 99600, 24968, 101153, 104405, 105694, 33108, 105831, 108351, 1773]}
6060
{"HumanAnswer": "您好:肠道检查包括:
6161
(1)粪便检查:
62-
  (2)直肠指诊:
62+
  (2)直肠指诊:
6363
  (3)乙状结肠镜检查:
6464
  (4)钡灌肠X线检查:
6565
  (5)纤维结肠镜检查
@@ -93,6 +93,6 @@
9393
{"HumanAnswer": "不合法  属于盗用   协议也是无效的   不受保护", "Python": [16530, 101431, 4102, 4102, 100409, 100591, 11622, 9238, 4102, 101136, 100000, 107128, 9370, 9238, 4102, 107524, 100153], "Java": [16530, 101431, 9238, 100409, 100591, 11622, 45393, 101136, 100000, 107128, 9370, 45393, 107524, 100153]}
9494
{"HumanAnswer": "您好  一般是可以的,具体的咨询社保部门", "Python": [111308, 4102, 4102, 100141, 105903, 9370, 3837, 108247, 100703, 106732, 99667], "Java": [111308, 9238, 100141, 105903, 9370, 3837, 108247, 100703, 106732, 99667]}
9595
{"HumanAnswer": "针对你的问题答复如下:    《民法通则》第六十六条 没有代理权、超越代理权或者代理权终止后的行为,只有经过被代理人的追认,被代理人才承担民事责任。未经追认的行为,由行为人承担民事责任。本人知道他人以本人名义实施民事行为而不作否认表示的,视为同意。以上答复,如果满意,敬请采纳,并给予评价。", "Python": [101092, 103929, 86119, 110463, 104506, 5122, 45393, 4102, 26940, 69721, 24339, 31935, 46448, 25067, 102651, 117602, 4102, 80443, 101259, 40981, 5373, 104840, 101259, 40981, 100631, 101259, 40981, 107660, 33447, 104796, 3837, 101043, 101897, 99250, 101259, 103947, 99626, 28951, 3837, 99250, 101259, 101050, 102016, 108669, 99531, 1773, 102887, 99626, 28951, 104796, 3837, 67071, 101070, 17340, 102016, 108669, 99531, 1773, 102043, 99392, 104287, 23031, 102043, 107765, 100355, 108669, 101070, 105145, 19403, 109433, 51463, 9370, 3837, 103097, 101185, 1773, 70589, 110463, 3837, 62244, 100545, 3837, 114131, 115250, 90395, 102062, 103964, 1773], "Java": [101092, 103929, 86119, 110463, 104506, 5122, 19070, 26940, 69721, 24339, 31935, 46448, 25067, 102651, 117602, 4102, 80443, 101259, 40981, 5373, 104840, 101259, 40981, 100631, 101259, 40981, 107660, 33447, 104796, 3837, 101043, 101897, 99250, 101259, 103947, 99626, 28951, 3837, 99250, 101259, 101050, 102016, 108669, 99531, 1773, 102887, 99626, 28951, 104796, 3837, 67071, 101070, 17340, 102016, 108669, 99531, 1773, 102043, 99392, 104287, 23031, 102043, 107765, 100355, 108669, 101070, 105145, 19403, 109433, 51463, 9370, 3837, 103097, 101185, 1773, 70589, 110463, 3837, 62244, 100545, 3837, 114131, 115250, 90395, 102062, 103964, 1773]}
96-
{"HumanAnswer": "你在网上的棋牌室花了人民币多少钱啊  你说的跑路是什么意思啊",
97-
"Python": [107740, 31139, 101913, 101386, 99478, 108225, 104142, 105957, 103924, 4102, 4102, 105665, 9370, 99803, 45995, 102021, 100313, 103924],
96+
{"HumanAnswer": "你在网上的棋牌室花了人民币多少钱啊  你说的跑路是什么意思啊",
97+
"Python": [107740, 31139, 101913, 101386, 99478, 108225, 104142, 105957, 103924, 4102, 4102, 105665, 9370, 99803, 45995, 102021, 100313, 103924],
9898
"Java": [107740, 31139, 101913, 101386, 99478, 108225, 104142, 105957, 103924, 9238, 105665, 9370, 99803, 45995, 102021, 100313, 103924]}

src/test/resources/stream_runs.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
{
5656
"event": "done",
5757
"data": "[DONE]"
58-
}
58+
}
5959
],
6060
"create_stream_thread_and_run_response": [
6161
{"event": "thread.created",
@@ -120,7 +120,7 @@
120120
{
121121
"event": "done",
122122
"data": "[DONE]"
123-
}
123+
}
124124
],
125125
"create_stream_require_action_function_1": [
126126
{
@@ -182,7 +182,7 @@
182182
{
183183
"event": "done",
184184
"data": "[DONE]"
185-
}
185+
}
186186
],
187187
"create_stream_require_action_function_2": [
188188
{

0 commit comments

Comments
 (0)