11parser = argparse.ArgumentParser(description=
'LLM client example')
12parser.add_argument(
'--remote', default=
'/llm_nws/rpc:i', type=str, help=
'remote port')
14args = parser.parse_args()
18if not yarp.Network.checkNetwork():
19 print(
'Please start a YARP name server first')
22options = yarp.Property()
23options.put(
'device',
'LLM_nwc_yarp')
24options.put(
'local',
'/llmClientExample/client')
25options.put(
'remote', args.remote)
27device = yarp.PolyDriver(options)
29if not device.isValid():
30 print(
'Remote device not available')
33llm = device.viewILLM()
36 print(
'Unable to get ILLM interface')
39if not llm.setPrompt(
'You are a helpful mathematician.'):
40 print(
'Failed to set prompt')
43prompt = yarp.SVector(1)
45if not llm.readPrompt(prompt):
46 print(
'Failed to read prompt')
49 print(f
'Prompt is: {prompt[0]}')
51answer = yarp.LLM_Message()
53question =
'What is 2 + 2?';
54print(f
'Asking: {question}')
56if not llm.ask(question, answer):
57 print(
'Failed to ask question')
61print(f
'* type: {answer.type}')
62print(f
'* content: {answer.content}')
63print(f
'* parameters: {list(answer.parameters)}')
64print(f
'* arguments: {list(answer.arguments)}')
66print(
'Deleting conversation')
68if not llm.refreshConversation():
69 print(
'Failed to refresh conversation')
72question =
'What is 3 + 3?'
74print(f
'Asking: {question}')
76if not llm.ask(question, answer):
77 print(
'Failed to ask question')
81print(f
'* type: {answer.type}')
82print(f
'* content: {answer.content}')
83print(f
'* parameters: {list(answer.parameters)}')
84print(f
'* arguments: {list(answer.arguments)}')
86conversation = yarp.LLMVector()
88if not llm.getConversation(conversation):
89 print(
'Failed to get conversation')
92 print(
'Conversation:')
94 for msg
in conversation:
95 print(msg.toString_c())
97print(
'Deleting conversation and prompt')
99if not llm.deleteConversation():
100 print(
'Failed to delete conversation')
103if not llm.setPrompt(
'You are the worst mathematician ever, you always provide wrong answers.'):
104 print(
'Failed to set prompt')
107if not llm.readPrompt(prompt):
108 print(
'Failed to read prompt')
111 print(f
'Prompt is: {prompt[0]}')
113question =
'What is 2 + 2?'
115print(f
'Asking: {question}')
117if not llm.ask(question, answer):
118 print(
'Failed to ask question')
122print(f
'* type: {answer.type}')
123print(f
'* content: {answer.content}')
124print(f
'* parameters: {list(answer.parameters)}')
125print(f
'* arguments: {list(answer.arguments)}')