2121import com .alibaba .cloud .ai .dashscope .api .DashScopeApi ;
2222import com .alibaba .cloud .ai .dashscope .api .DashScopeApi .ChatCompletionFinishReason ;
2323import com .alibaba .cloud .ai .dashscope .chat .DashScopeChatModel ;
24+ import com .alibaba .cloud .ai .dashscope .chat .DashScopeChatOptions ;
2425import com .alibaba .cloud .ai .dashscope .tool .DashScopeFunctionTestConfiguration ;
2526import com .alibaba .cloud .ai .dashscope .chat .tool .MockOrderService ;
2627import com .alibaba .cloud .ai .dashscope .chat .tool .MockWeatherService ;
@@ -75,7 +76,7 @@ public class DashScopeChatClientIT {
7576 private DashScopeChatModel dashscopeChatModel ;
7677
7778 @ Autowired
78- private DashScopeApi dashscopeApi ;
79+ private DashScopeApi dashscopeChatApi ;
7980
8081 @ Value ("classpath:/prompts/rag/system-qa.st" )
8182 private Resource systemResource ;
@@ -85,7 +86,7 @@ public class DashScopeChatClientIT {
8586
8687 @ Test
8788 void callTest () throws IOException {
88- DocumentRetriever retriever = new DashScopeDocumentRetriever (dashscopeApi ,
89+ DocumentRetriever retriever = new DashScopeDocumentRetriever (dashscopeChatApi ,
8990 DashScopeDocumentRetrieverOptions .builder ().withIndexName ("spring-ai知识库" ).build ());
9091
9192 ChatClient chatClient = ChatClient .builder (dashscopeChatModel )
@@ -102,14 +103,20 @@ void callTest() throws IOException {
102103
103104 @ Test
104105 void streamTest () throws InterruptedException , IOException {
105- DocumentRetriever retriever = new DashScopeDocumentRetriever (dashscopeApi ,
106+ DocumentRetriever retriever = new DashScopeDocumentRetriever (dashscopeChatApi ,
106107 DashScopeDocumentRetrieverOptions .builder ().withIndexName ("spring-ai知识库" ).build ());
107108 ChatClient chatClient = ChatClient .builder (dashscopeChatModel )
108109 .defaultAdvisors (
109110 new DocumentRetrievalAdvisor (retriever , systemResource .getContentAsString (StandardCharsets .UTF_8 )))
110111 .build ();
111112
112- Flux <ChatResponse > response = chatClient .prompt ().user ("如何快速开始百炼?" ).stream ().chatResponse ();
113+ Flux <ChatResponse > response = chatClient .prompt ()
114+ .user ("如何快速开始百炼?" )
115+ .options (DashScopeChatOptions .builder ()
116+ .withIncrementalOutput (true )
117+ .build ())
118+ .stream ()
119+ .chatResponse ();
113120
114121 CountDownLatch cdl = new CountDownLatch (1 );
115122 response .subscribe (data -> {
@@ -159,7 +166,7 @@ void callWithFunctionBeanTest() {
159166
160167 @ Test
161168 void callWithFunctionAndRagTest () throws IOException {
162- DocumentRetriever retriever = new DashScopeDocumentRetriever (dashscopeApi ,
169+ DocumentRetriever retriever = new DashScopeDocumentRetriever (dashscopeChatApi ,
163170 DashScopeDocumentRetrieverOptions .builder ().withIndexName ("spring-ai知识库" ).build ());
164171
165172 ChatClient chatClient = ChatClient .builder (dashscopeChatModel )
@@ -178,7 +185,7 @@ void callWithFunctionAndRagTest() throws IOException {
178185
179186 @ Test
180187 void streamCallWithFunctionAndRagTest () throws InterruptedException , IOException {
181- DocumentRetriever retriever = new DashScopeDocumentRetriever (dashscopeApi ,
188+ DocumentRetriever retriever = new DashScopeDocumentRetriever (dashscopeChatApi ,
182189 DashScopeDocumentRetrieverOptions .builder ().withIndexName ("spring-ai知识库" ).build ());
183190
184191 ChatClient chatClient = ChatClient .builder (dashscopeChatModel )
@@ -187,7 +194,13 @@ void streamCallWithFunctionAndRagTest() throws InterruptedException, IOException
187194 .defaultFunctions ("weatherFunction" )
188195 .build ();
189196
190- Flux <ChatResponse > response = chatClient .prompt ().user ("上海今天的天气如何?" ).stream ().chatResponse ();
197+ Flux <ChatResponse > response = chatClient .prompt ()
198+ .user ("上海今天的天气如何?" )
199+ .options (DashScopeChatOptions .builder ()
200+ .withIncrementalOutput (true )
201+ .build ())
202+ .stream ()
203+ .chatResponse ();
191204
192205 CountDownLatch cdl = new CountDownLatch (1 );
193206 response .subscribe (data -> {
@@ -206,7 +219,7 @@ void streamCallWithFunctionAndRagTest() throws InterruptedException, IOException
206219
207220 @ Test
208221 void callWithReferencedRagTest () throws IOException {
209- DocumentRetriever retriever = new DashScopeDocumentRetriever (dashscopeApi ,
222+ DocumentRetriever retriever = new DashScopeDocumentRetriever (dashscopeChatApi ,
210223 DashScopeDocumentRetrieverOptions .builder ().withIndexName ("spring-ai知识库" ).build ());
211224
212225 ChatClient chatClient = ChatClient .builder (dashscopeChatModel )
@@ -232,7 +245,7 @@ void callWithReferencedRagTest() throws IOException {
232245
233246 @ Test
234247 void streamCallWithReferencedRagTest () throws IOException , InterruptedException {
235- DocumentRetriever retriever = new DashScopeDocumentRetriever (dashscopeApi ,
248+ DocumentRetriever retriever = new DashScopeDocumentRetriever (dashscopeChatApi ,
236249 DashScopeDocumentRetrieverOptions .builder ().withIndexName ("spring-ai知识库" ).build ());
237250
238251 ChatClient chatClient = ChatClient .builder (dashscopeChatModel )
@@ -272,7 +285,7 @@ void streamCallWithReferencedRagTest() throws IOException, InterruptedException
272285
273286 @ Test
274287 void callWithMemory () throws IOException {
275- DocumentRetriever retriever = new DashScopeDocumentRetriever (dashscopeApi ,
288+ DocumentRetriever retriever = new DashScopeDocumentRetriever (dashscopeChatApi ,
276289 DashScopeDocumentRetrieverOptions .builder ().withIndexName ("spring-ai知识库" ).build ());
277290
278291 ChatClient chatClient = ChatClient .builder (dashscopeChatModel )
@@ -309,24 +322,24 @@ void callWithMemory() throws IOException {
309322 @ Test
310323 void reader () {
311324 String filePath = "/Users/nuocheng.lxm/Desktop/新能源产业有哪些-36氪.pdf" ;
312- DashScopeDocumentCloudReader reader = new DashScopeDocumentCloudReader (filePath , dashscopeApi , null );
325+ DashScopeDocumentCloudReader reader = new DashScopeDocumentCloudReader (filePath , dashscopeChatApi , null );
313326 List <Document > documentList = reader .get ();
314- DashScopeDocumentTransformer transformer = new DashScopeDocumentTransformer (dashscopeApi );
327+ DashScopeDocumentTransformer transformer = new DashScopeDocumentTransformer (dashscopeChatApi );
315328 List <Document > transformerList = transformer .apply (documentList );
316329 System .out .println (transformerList .size ());
317330 }
318331
319332 @ Test
320333 void embed () {
321- DashScopeEmbeddingModel embeddingModel = new DashScopeEmbeddingModel (dashscopeApi );
334+ DashScopeEmbeddingModel embeddingModel = new DashScopeEmbeddingModel (dashscopeChatApi );
322335 Document document = new Document ("你好阿里云" );
323336 float [] vectorList = embeddingModel .embed (document );
324337 System .out .println (vectorList .length );
325338 }
326339
327340 @ Test
328341 void vectorStore () {
329- DashScopeCloudStore cloudStore = new DashScopeCloudStore (dashscopeApi , new DashScopeStoreOptions ("诺成SpringAI" ));
342+ DashScopeCloudStore cloudStore = new DashScopeCloudStore (dashscopeChatApi , new DashScopeStoreOptions ("诺成SpringAI" ));
330343 List <Document > documentList = Arrays .asList (
331344 new Document ("file_f0b6b18b14994ed8a0b45648ce5d0da5_10001" , "abc" , new HashMap <>()),
332345 new Document ("file_d3083d64026d4864b4558d18f9ca2a6d_10001" , "abc" , new HashMap <>()),
0 commit comments