lorashen commited on
Commit
22fec82
·
verified ·
1 Parent(s): d17e944

upload camelai examples

Browse files
examples/camelai/eval.py ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ import re
3
+ import csv
4
+ from datetime import date,timedelta
5
+ from openai import OpenAI
6
+ def resolve(slot):
7
+ pos=slot.find("place_name")
8
+ if pos!=-1:
9
+ bgpos=slot[pos:].find(":")
10
+ citypos=slot[pos+bgpos:].find("'")
11
+ oldcity=slot[pos+bgpos+1:pos+bgpos+citypos]
12
+ oldcity=oldcity.strip()
13
+ if oldcity=="my city":
14
+ newcity="new york"
15
+ slot=slot[:pos+bgpos+1]+str(newcity)+slot[pos+bgpos+citypos:]
16
+ pos=slot.find("date")
17
+ if pos!=-1:
18
+ bgpos=slot[pos:].find(":")
19
+ datepos=slot[pos+bgpos:].find("'")
20
+ olddate=slot[pos+bgpos+1:pos+bgpos+datepos]
21
+ olddate=olddate.strip()
22
+ today=date.today()
23
+ weekday=date.isoweekday(today)% 7
24
+ #print(today)
25
+ #print(weekday)
26
+ newdate2=None
27
+ if olddate=="today":
28
+ newdate=str(today)
29
+ elif olddate=="tomorrow":
30
+ newdate=today+timedelta(days=1)
31
+ elif olddate=="this week":
32
+ weekday=date.isoweekday(today)% 7
33
+ newdate2=today+ timedelta(days=7-weekday)
34
+ newdate=today-timedelta(days=weekday-1)
35
+ elif olddate=="last week":
36
+ weekday=date.isoweekday(today)% 7
37
+ newdate2=today-timedelta(days=weekday)
38
+ newdate=today-timedelta(days=weekday+6)
39
+
40
+ elif olddate=="this weekend":
41
+ weekday=date.isoweekday(today)% 7
42
+ newdate=today+timedelta(days=6-weekday)
43
+ newdate2=today+timedelta(days=7-weekday)
44
+ elif olddate=="sunday":
45
+ weekday=date.isoweekday(today)% 7
46
+ newdate=today+timedelta(7-weekday)
47
+ elif olddate=="august fifteenth":
48
+ if str(today).find("-")!=-1:
49
+ ypos=str(today).find("-")
50
+ newdate=str(today)[:ypos+1]+"08-15"
51
+ else:
52
+ newdate="08-15"
53
+ else:
54
+ newdate=olddate
55
+ #print(slot)
56
+ slot=slot[:pos+bgpos+1]+str(newdate)+slot[pos+bgpos+datepos:]
57
+ if newdate2:
58
+ slot=slot+",'date2:"+str(newdate2)+"'"
59
+ #print(slot)
60
+ pos=slot.find("timeofday")
61
+ oldtimeofday=""
62
+ if pos!=-1:
63
+ bgpos=slot[pos:].find(":")
64
+ datepos=slot[pos+bgpos:].find("'")
65
+ oldtimeofday=slot[pos+bgpos+1:pos+bgpos+datepos]
66
+ oldtimeofday=oldtimeofday.strip()
67
+ cpos=slot[pos:].rfind(",")
68
+ if cpos!=-1:
69
+ slot=slot[:cpos]+slot[pos+bgpos+datepos+1:]
70
+ else:
71
+ cpos=slot[pos:].find(",")
72
+ if cpos==-1:
73
+ slot=slot[:pos]+slot[pos+bgpos+datepos+1:]
74
+ else:
75
+ slot=slot[:pos]+slot[cpos+1:]
76
+ pos=slot.find("time:")
77
+ if pos==-1:
78
+ pos=slot.find("time :")
79
+ if pos!=-1:
80
+ bgpos=slot[pos:].find(":")
81
+ timepos=slot[pos+bgpos:].find("'")
82
+ oldtime=slot[pos+bgpos+1:pos+bgpos+timepos]
83
+ oldtime=oldtime.strip()
84
+ newtime=oldtime.replace("five","05:00").replace("six","06:00").replace("nine","09:00").replace("ten","10:00")
85
+ if not(newtime.endswith("am") or newtime.endswith("pm")):
86
+ if oldtimeofday=="morning":
87
+ newtime=newtime+" am"
88
+ elif oldtimeofday=="evening":
89
+ newtime=newtime+" pm"
90
+ elif oldtimeofday.find("afternoon")!=-1:
91
+ newtime=newtime+" pm"
92
+ #print(slot)
93
+ slot=slot[:pos+bgpos+1]+str(newtime)+slot[pos+bgpos+timepos:]
94
+ #print(slot)
95
+ else:
96
+ if oldtimeofday.find("afternoon")!=-1:
97
+ newtime="15:00"
98
+ #print(slot)
99
+ slot=slot+",'time:'"+newtime
100
+ #print(slot)
101
+
102
+
103
+ return slot
104
+ def read_data(file_path):
105
+ queries=[]
106
+ with open(file_path, newline='') as csvfile:
107
+ spamreader = csv.reader(csvfile, delimiter=',', quotechar='"')
108
+ count=0
109
+ for row in spamreader:
110
+ if count==0:
111
+ count+=1
112
+ continue
113
+ #print(row[2])
114
+ #print(len(row))
115
+ iid=row[0]
116
+ slot=row[3]
117
+ slot=slot.strip('[]')
118
+ slot=resolve(slot)
119
+ query={"iid":iid,"query":row[1],"intent":row[2],"slot":slot}#,"slots":slot,"domain":row[4]}
120
+ queries.append(query)
121
+ return queries
122
+ if __name__=="__main__":
123
+ datep=re.compile(r"(======)*202[45]-\d\d-\d\d")
124
+ client = OpenAI()
125
+ tasks=read_data("~/data/test.csv")
126
+ intp=re.compile(r"intent:[a-z_]+(,|\x1b)")
127
+ resp=re.compile(r'{"code":"SUCCESS","data"(.)+')#[":, \}\{a-zA-Z0-9\_]+,"msg":".."}')
128
+ for i in range(19,20):
129
+ print("-----*****------")
130
+ print(i)
131
+ data=[]
132
+ with open(str(i)+".log") as f:
133
+ lines=f.readlines()
134
+
135
+ for line in lines:
136
+ if datep.match(line):
137
+ continue
138
+ else:
139
+ data.append(line)
140
+
141
+ content="\n".join(data)
142
+ intentf=intp.search(content)
143
+ if intentf:
144
+ intent=intentf.group(0)
145
+ if intent.find("weather")!=-1 or intent.find("news_query")!=-1 or intent.find("qa")!=-1 or intent.find("stock")!=-1 or intent.find("general")!=-1 or intent.find("currency")!=-1:
146
+ print("ChatCompletionMessage(content='')")
147
+ #pass
148
+ else:
149
+ resf= resp.search(content)
150
+ if resf:
151
+ res=resf.group(0)
152
+ msg=[{"role": "system", "content":"please judge the following result is right or wrong. if slot is {} and result also {}, it is right. if slot are same, it is right.if time is same, no matter if has am/pm, it is right. if slot is descriptor:all, then can neglect it, other descriptor can not neglect. the slot person is same with slot from_person and to_person. the place_name will be resolved, so if it is added by state name and country name, it is right."},{"role":"user", "content":"The golden slot is :{"+tasks[i]["slot"]+"}. The result is "+res}],
153
+ print(msg)
154
+ completion = client.chat.completions.create(
155
+ model="gpt-4",
156
+ messages=[{"role": "system", "content":"please judge the following result is right or wrong. if slot is {} and result also {}, it is right. if slot are same, it is right.if time is same, no matter if has am/pm, it is right. if slot is descriptor:all, then can neglect it, other descriptor can not neglect. the slot person is same with slot from_person and to_person. if slot is query:song name, can be neglected. the place_name will be resolved, so if it is added by state name and country name, it is right."},{"role":"user", "content":"The golden slot is :{"+tasks[i]["slot"]+"}. The result is "+res}],
157
+ )
158
+ print(completion.choices[0].message)
159
+ else:
160
+ print("ChatCompletionMessage(content='the result is wrong')")
161
+ continue
162
+ else:
163
+ if content.find("\"results\"")==-1 and content.find("\"data\"")==-1 and content.find("\"success\"")==-1:
164
+ print("ChatCompletionMessage(content='the result is wrong. no server response.')")
165
+ continue
166
+ goldintent=tasks[i]["intent"]
167
+ if goldintent.find("weather")!=-1 or goldintent.find("news_query")!=-1 or goldintent.find("qa")!=-1 or goldintent.find("stock")!=-1 or goldintent.find("general")!=-1 or goldintent.find("currency")!=-1:
168
+ msg=[{"role": "system", "content":"please judge the following content finish the task is right or wrong. Must has the server response ,if not, it's wrong. If is weather_query, need to provide the weather condition. if intent is qa, the response need to provide the answer to the question, and if only provide url, it is wrong. also need to check if the annotaion are the same with server response"},{"role": "user", "content": "the task is "+tasks[i]["query"]+". The annotation is "+tasks[i]["slot"]+"\n"+"\n".join(data)+"\nyour answer is :"}],
169
+ print(msg)
170
+ try:
171
+ completion = client.chat.completions.create(
172
+ model="gpt-4",
173
+ messages=[{"role": "system", "content":"please judge the following content finish the task is right or wrong. Must has the server response ,if not, it's wrong. If intent is weather_query, need to provide the weather condition, and if no weather condition, it is wrong. if intent is qa, the response need to provide the answer to the question, and if only provide url, it is wrong. also need to check if the annotaion are the same with server response"},{"role": "user", "content": "the task is "+tasks[i]["query"]+". The annotation is "+tasks[i]["slot"]+"\n"+"\n".join(data)+"\nyour answer is :"}],
174
+ )
175
+
176
+ print(completion.choices[0].message)
177
+ except:
178
+ completion = client.chat.completions.create(
179
+ model="gpt-4",
180
+ messages=[{"role": "system", "content":"please judge the following content finish the task is right or wrong. Must has the server response ,if not, it's wrong. If intent is weather_query, need to provide the weather condition, and if no weather condition, it is wrong. if intent is qa, the response need to provide the answer to the question, and if only provide url, it is wrong. also need to check if the annotaion are the same with server response"},{"role": "user", "content": "the task is "+tasks[i]["query"]+". The annotation is "+tasks[i]["slot"]+"\n"+"\n".join(data)[-16000:]+"\nyour answer is :"}],
181
+ )
182
+ print(completion.choices[0].message)
183
+
184
+
185
+ else:
186
+ msg=[{"role": "system", "content":"please judge the following content finish the task is right or wrong. Must has the server response {\"code\":\"SUCCESS\"},if not, it's wrong. if response is not supported intent, it is wrong."},{"role": "user", "content": "the task is "+tasks[i]["query"]+". The annotation is "+tasks[i]["slot"]+"\n"+"\n".join(data)+"\nyour answer is :"}],
187
+ print(msg)
188
+ completion = client.chat.completions.create(
189
+ model="gpt-4",
190
+ messages=[{"role": "system", "content":"please judge the following content finish the task is right or wrong. Must has the server response {\"code\":\"SUCCESS\"},if not, it's wrong. if response is not supported intent, it is wrong."},{"role": "user", "content": "the task is "+tasks[i]["query"]+". The annotation is "+tasks[i]["slot"]+"\n"+"\n".join(data)+"\nyour answer is :"}],
191
+ )
192
+
193
+ print(completion.choices[0].message)
194
+
195
+
196
+
examples/camelai/eval.sh ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ python3 eval.py > eval.log
2
+ python3 stat.py
examples/camelai/file_test.py ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from camel.societies.workforce import Workforce
2
+
3
+ from camel.models import ModelFactory
4
+ from camel.types import ModelPlatformType, ModelType
5
+ from camel.configs import ChatGPTConfig
6
+ from datetime import date, datetime
7
+ import requests
8
+ import json
9
+ import csv
10
+ import sys
11
+ import asyncio
12
+ # Define the model, here in this case we use gpt-4o-mini
13
+ model = ModelFactory.create(
14
+ model_platform=ModelPlatformType.OPENAI,
15
+ model_type=ModelType.GPT_4,
16
+ model_config_dict=ChatGPTConfig().as_dict(), # [Optional] the config for model
17
+ )
18
+ from camel.agents import ChatAgent
19
+ pmsys_msg="you are controlling smart home system, you have intentagent, timeagent, locationagent, urlagent, and requestagent to complete the user's task. You should first use intentagent to complete the intent prediction. Then if the result has time or location params, please try to ask timeagent or locationagent to solve the time and location. At last you should use requestagent to send and receive request from other servers such as weather server and response to user to finalize the task."
20
+ intentsys_msg="read the examples and results, copy iid and predict intent for the sentence. for 'iid:7199,query:set the alarm to two pm' first predict the domain, as domain:alarm, then copy the iid from query,iid:7199, then the intent and slots, as the format: intent:alarm_set,time:two pm. the intents are calendar:calendar_set,calendar_remove,calendar_query\n\
21
+ lists:lists_query,lists_remove,lists_createoradd\n\
22
+ music:play_music,music_likeness,playlists_createoradd,music_settings,music_dislikeness,music_query\n\
23
+ news:news_query,news_subscription\n\
24
+ alarm:alarm_set,alarm_query,alarm_remove,alarm_change\n\
25
+ email:email_sendemail,email_query,email_querycontact,email_subscription,email_addcontact,email_remove\n\
26
+ iot:iot_hue_lightchange,iot_coffee,iot_hue_lightdim,iot_hue_lightup,audio_volume_mute,iot_hue_lightoff,audio_volume_up,iot_wemo_off,audio_volume_other,iot_cleaning,iot_wemo_on,audio_volume_down\n\
27
+ weather:weather_query\n\
28
+ datetime:datetime_query,datetime_convert\n\
29
+ stock:qa_stock\n\
30
+ qa:qa_factoid,general_quirky,qa_definition,general_joke,qa_maths\n\
31
+ greet:general_greet\n\
32
+ currency:qa_currency\n\
33
+ transport:transport_taxi,transport_ticket,transport_query,transport_traffic\n\
34
+ recommendation:recommendation_events,recommendation_movies,recommendation_locations\n\
35
+ podcast:play_podcasts\n\
36
+ audiobook:play_audiobook\n\
37
+ radio:play_radio,radio_query\n\
38
+ takeaway:takeaway_query,takeaway_order\n\
39
+ social:social_query,social_post\n\
40
+ cooking:cooking_recipe\n\
41
+ phone:phone_text,phone_notification\n\
42
+ game:play_game\
43
+ "
44
+ timesys_msg="read time params, and convert to formated time. if has date, call the time_tool getdate function to get date, format should be year-month-date. the time is 10:00. if has time, the time format should be 10:00. this morning the time will be 10:00, this afternoon the time will be 15:00"
45
+ locationsys_msg="read the location params, and convert to formated location. current location is new york."
46
+ urlsys_msg="read the params, and choose the function to send and receive the requests. iid should also be string. choose the url from the provided servers' url list:\
47
+ qa server is http://api.serpstack.com/search? access_key = {key}& query = {query}\n\
48
+ news query server is http://api.mediastack.com/v1/news?access_key={key}&keywords={keyword}&date={date}&sort=published_desc\n\
49
+ news subscription server http://127.0.0.1:3020/news,intent(news_subscription),iid,news_topic,\
50
+ weather server first request https://geocoding-api.open-meteo.com/v1/search?name={place_name}&count=10&language=en&format=json to get latitude and latitude, then request https://api.open-meteo.com/v1/forecast?latitude={latitude}&longitude={longitude}&hourly=temperature_2m&models=gfs_seamless\n\
51
+ stock server is first to get the stock symbol http://api.serpstack.com/search? access_key = {key}& query = {name} stock symbol , then request to this server http://api.marketstack.com/v1/eod? access_key = {key}& symbols = {symbol}&limit=5\n\
52
+ currency server is https://www.amdoren.com/api/currency.php?api_key={key}&from={currency}&to={currency2}&amount={amount}\n\
53
+ http://127.0.0.1:3000/alarm, intent(alarm_query,alarm_set),iid,event_name,descriptor,time,from_time,to_time,\
54
+ http://127.0.0.1:3001/audiobook,intent(play_audiobook), iid,player_setting,house_place,media_type,descriptor,audiobook_name,author_name,\
55
+ http://127.0.0.1:3002/calendar,intent(calendar_query,calendar_remove,calendar_set),iid,event_name,descriptor,person,relation,date,time,from_time,to_time,\
56
+ http://127.0.0.1:3003/cooking,intent(cooking_recipe),iid,food_type,descriptor,\
57
+ http://127.0.0.1:3004/datetime,intent(datetime_convert,datetime_query),iid,place_name,descriptor,time_zone,time_zone2,date,time,time2,\
58
+ http://127.0.0.1:3005/email,intent(email_query,email_sendemail),iid,setting,person,to_person,from_person,relation,to_relation,from_relation,email_folder,time,date,email_address,app_name,query,content,personal_info,\
59
+ http://127.0.0.1:3006/game,intent(play_game),iid,game_name,\
60
+ http://127.0.0.1:3007/iot,intent(iot_coffee,iot_hue_lightchange,iot_hue_lightdim,iot_hue_lightup,audio_volume_mute,iot_hue_lightoff,audio_volume_up,iot_wemo_off,audio_volume_other,iot_cleaning,iot_wemo_on,audio_volume_down),iid,device_type,house_place,time,color_type,change_amount,item_name,setting,\
61
+ http://127.0.0.1:3008/lists,intent(lists_query,lists_remove,lists_createoradd),iid,list_name,item_name,descriptor,time,date,\
62
+ http://127.0.0.1:3009/music,intent(play_music,music_likeness,playlists_createoradd,music_settings,music_dislikeness,music_query),iid,player_setting,descriptor,artist_name,song_name,playlist_name,music_genre,query,\
63
+ http://127.0.0.1:3010/phone,intent(phone_text,phone_notification),iid,device_type,event_name,text,\
64
+ http://127.0.0.1:3011/podcasts,intent(play_podcasts),iid,podcast_name,player_setting,podcast_descriptor,\
65
+ http://127.0.0.1:3013/radio,intent(play_radio,radio_query),iid,radio_name,app_name,person_name,music_genre,device_type,house_place,player_setting,descriptor,query,time,\
66
+ http://127.0.0.1:3014/recommendation,intent(recommendation_events,recommendation_movies,recommendation_locations),iid,business_type,food_type,movie_type,movie_name,date,place_name,event_name,descriptor,\
67
+ http://127.0.0.1:3015/social,intent(social_query,social_post),iid,media_type,person,business_name,content,date,descriptor,\
68
+ http://127.0.0.1:3017/takeaway,intent(takeaway_query,takeaway_order),iid,food_type,order_type,business_type,business_name,place_name,date,time,descriptor,\
69
+ http://127.0.0.1:3018/transport,intent(transport_taxi,transport_ticket,transport_query,transport_traffic),iid,transport_agency,transport_type,business_type,business_name,place_name,to_place_name,from_place_name,query,date,time,descriptor,\
70
+ then all the url format should be http://127.0.0.1:3002/calendar?intent=calendar_remove&event_name=meeting"
71
+ requestsys_msg="for qa, news query, weather, stock, and currency, just use the url. for other request, use the url and generate params, params should be json format, like this{\"intent\": \"calendar_remove\", \"event_name\": \"haircut appointment\", \"date\": \"2024-11-20\"}. choose the function to call. Then call the function and receive the response from the server."
72
+ response_msg="analyse the result from server, and generate response for the user."
73
+ def getdate() -> str:
74
+ r"""request the date.
75
+
76
+
77
+ Returns:
78
+ string: The response.
79
+ """
80
+ from datetime import date, datetime
81
+ results = date.today()
82
+ return str(results)
83
+
84
+ from camel.toolkits import FunctionTool
85
+ time_tool = FunctionTool(getdate)
86
+
87
+ timeagent = ChatAgent(
88
+ system_message=timesys_msg,
89
+ model=model,
90
+ tools=[time_tool],
91
+ message_window_size=10, # [Optional] the length for chat memory
92
+ )
93
+
94
+ def req(url: str ) -> str:
95
+ r"""request the url.
96
+
97
+ Args:
98
+ url (str): URL for the new :class:`Request` object.
99
+
100
+ Returns:
101
+ string: The response of the server.
102
+ """
103
+ response=requests.get(url)
104
+ print(response.text)
105
+ '''
106
+ else:
107
+ response = requests.post(url, data=params)
108
+
109
+ # 打印返回结果
110
+ print(response.text)
111
+ result=""
112
+ if response.status_code >= 400:
113
+ print(params)#["iid"])
114
+ #result="code "+str(response.status_code)+"."
115
+ response = requests.post(url, data=json.dumps(params))
116
+ if response.status_code >= 400:
117
+ result="code "+str(response.status_code)+"."
118
+ else:
119
+ pass
120
+ res=json.loads(response.text)
121
+ if res["data"]["response"]=="true":
122
+ count+=1
123
+ result="true"
124
+ else:
125
+ print(params)#["iid"])
126
+ result="false"
127
+ print(res["data"]["response"])
128
+ '''
129
+ return response.text
130
+
131
+
132
+ # Wrap the function with FunctionTool
133
+ #req_withquery_tool = FunctionTool(req_withquery)
134
+ req_tool = FunctionTool(req)
135
+
136
+ pmagent = ChatAgent(
137
+ system_message=pmsys_msg,
138
+ model=model,
139
+ message_window_size=10, # [Optional] the length for chat memory
140
+ )
141
+ intentagent = ChatAgent(
142
+ system_message=intentsys_msg,
143
+ model=model,
144
+ message_window_size=10, # [Optional] the length for chat memory
145
+ )
146
+ locationagent = ChatAgent(
147
+ system_message=locationsys_msg,
148
+ model=model,
149
+ message_window_size=10, # [Optional] the length for chat memory
150
+ )
151
+ urlagent = ChatAgent(
152
+ system_message=urlsys_msg,
153
+ model=model,
154
+ message_window_size=10, # [Optional] the length for chat memory
155
+ )
156
+ requestagent = ChatAgent(
157
+ system_message=requestsys_msg,
158
+ model=model,
159
+ tools=[req_tool],
160
+ message_window_size=10, # [Optional] the length for chat memory
161
+ )
162
+ responseagent = ChatAgent(
163
+ system_message=response_msg,
164
+ model=model,
165
+ message_window_size=10, # [Optional] the length for chat memory
166
+ )
167
+
168
+ # Create a workforce instance
169
+ workforce = Workforce("A Simple Workforce")
170
+ # Add the worker agent to the workforce
171
+ workforce.add_single_agent_worker(
172
+ "An agent that can do program manage",
173
+ worker=pmagent,
174
+ )
175
+ workforce.add_single_agent_worker(
176
+ "An agent that can predict intent and key info",
177
+ worker=intentagent,
178
+ ).add_single_agent_worker(
179
+ "An agent that can provide date and time and format it",
180
+ worker=timeagent,
181
+ ).add_single_agent_worker(
182
+ "An agent that can provide location and format it",
183
+ worker=locationagent,
184
+ ).add_single_agent_worker(
185
+ "An agentthat can provide the url and query",
186
+ worker=urlagent,
187
+ ).add_single_agent_worker(
188
+ "An agentthat can make request to the server and receive the response",
189
+ worker=requestagent,
190
+ ).add_single_agent_worker(
191
+ "An agentthat can analyse the server result and generate response, this agent will finish the whole task",
192
+ worker=responseagent,
193
+ )
194
+ from camel.tasks import Task#,TaskState
195
+
196
+ def read_data(file_path):
197
+ queries=[]
198
+ with open(file_path, newline='') as csvfile:
199
+ spamreader = csv.reader(csvfile, delimiter=',', quotechar='"')
200
+ count=0
201
+ for row in spamreader:
202
+ if count==0:
203
+ count+=1
204
+ continue
205
+ #print(row[2])
206
+ #print(len(row))
207
+ iid=row[0]
208
+ query={"iid":iid,"query":row[1]}#,"slots":slot,"domain":row[4]}
209
+ queries.append(query)
210
+ return queries
211
+ if __name__=="__main__":
212
+ tasks=read_data("~/data/test.csv")
213
+ #print(tasks)
214
+ index = int(sys.argv[1])
215
+ tasks=tasks[index:index+1]
216
+ for sent in tasks:
217
+ print("---------*****************************************-----------")
218
+ #test_sent = json.dumps(sent)
219
+ print(sent["iid"])
220
+
221
+ # the id of the task can be any string to mark the task
222
+ task = Task(
223
+ content=sent["query"],
224
+ #alexa lights brighter",
225
+ #book me a train ticket for this afternoon to chicago",#add dentist appointment for friday at five",#what's the weather today?",
226
+ id="0",
227
+ )
228
+ try:
229
+ task = workforce.process_task(task)
230
+ print(task.result)
231
+ except:
232
+ pass
233
+ #if task.state == TaskState.FAILED:
234
+ #asyncio.run(workforce._handle_failed_task(task))
examples/camelai/run.sh CHANGED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ for f in $(seq 0 99);
3
+ do
4
+ echo $f
5
+ timeout 240s python3 file_test.py $f > $f.log
6
+ done
examples/camelai/stat.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ wrong=0
3
+ right=0
4
+ wrongcount=0
5
+ rightcount=0
6
+ judgesent=re.compile(r"ChatCompletionMessage")
7
+ with open("eval.log") as f:
8
+ lines=f.readlines()
9
+ for line in lines:
10
+ lowline=line.lower()
11
+ if line.startswith("-----**"):
12
+ if wrong>0:
13
+ wrongcount+=1
14
+ elif right>0:
15
+ rightcount+=1
16
+ else:
17
+ print("error")
18
+ wrong=0
19
+ right=0
20
+ elif judgesent.match(line):
21
+ if lowline.find("wrong")!=-1 or lowline.find("incorrect")!=-1 or lowline.find("not completed")!=-1:
22
+ wrong+=1
23
+ elif lowline.find("right")!=-1 or lowline.find("correct")!=-1:
24
+ right+=1
25
+ elif lowline.find("content=''")!=-1:
26
+ pass
27
+ else:
28
+ print("error")
29
+ if wrong>0:
30
+ wrongcount+=1
31
+ else:
32
+ rightcount+=1
33
+ acc=float(rightcount)/100
34
+ print(acc,"right",rightcount,"wrong",wrongcount)