MCPcopy Create free account
hub / github.com/dashscope/dashscope-sdk-java / run

Method run

samples/AssistantCallSearch.java:34–67  ·  view source on GitHub ↗
(String assistantId)

Source from the content-addressed store, hash-verified

32 }
33
34 static public void run(String assistantId) throws ApiException, NoApiKeyException, InvalidateParameter, InputRequiredException, InterruptedException{
35 // create a thread
36 Threads threads = new Threads();
37 AssistantThread assistantThread = threads.create(ThreadParam.builder().build());
38
39 Runs runs = new Runs();
40 // create a new message
41 TextMessageParam textMessageParam = TextMessageParam.builder().role("user").content("请帮忙查询今日北京天气?").build();
42 Messages messages = new Messages();
43 ThreadMessage threadMessage = messages.create(assistantThread.getId(), textMessageParam);
44 System.out.println(threadMessage);
45 RunParam runParam = RunParam.builder().assistantId(assistantId).build();
46 Run run = runs.create(assistantThread.getId(), runParam);
47 while(true){
48 if(run.getStatus().equals(Run.Status.CANCELLED) ||
49 run.getStatus().equals(Run.Status.COMPLETED) ||
50 run.getStatus().equals(Run.Status.FAILED) ||
51 run.getStatus().equals(Run.Status.REQUIRES_ACTION)||
52 run.getStatus().equals(Run.Status.EXPIRED)){
53 break;
54 }else{
55 Thread.sleep(1000);
56 }
57 run = runs.retrieve(assistantThread.getId(), run.getId());
58 System.out.println(run);
59 }
60
61 GeneralListParam listParam = GeneralListParam.builder().limit(100l).build();
62 ListResult<ThreadMessage> threadMessages = messages.list(assistantThread.getId(), listParam);
63 for(ThreadMessage threadMessage2: threadMessages.getData()){
64 System.out.println(threadMessage2);
65 }
66
67 }
68
69 public static void main(String[] args) throws ApiException, NoApiKeyException, InputRequiredException, InvalidateParameter, InterruptedException {
70 Assistant assistant = createAssistant();

Callers 2

mainMethod · 0.95
mainMethod · 0.45

Calls 10

createMethod · 0.95
createMethod · 0.95
createMethod · 0.95
retrieveMethod · 0.95
listMethod · 0.95
builderMethod · 0.80
getIdMethod · 0.80
getDataMethod · 0.80
buildMethod · 0.65
equalsMethod · 0.45

Tested by

no test coverage detected