MCPcopy Create free account
hub / github.com/X-PLUG/MobileAgent / inference_chat

Function inference_chat

Mobile-Agent-v2/MobileAgent/api.py:9–40  ·  view source on GitHub ↗
(chat, model, api_url, token)

Source from the content-addressed store, hash-verified

7
8
9def inference_chat(chat, model, api_url, token):
10 headers = {
11 "Content-Type": "application/json",
12 "Authorization": f"Bearer {token}"
13 }
14
15 data = {
16 "model": model,
17 "messages": [],
18 "max_tokens": 2048,
19 'temperature': 0.0,
20 "seed": 1234
21 }
22
23 for role, content in chat:
24 data["messages"].append({"role": role, "content": content})
25
26 while True:
27 try:
28 res = requests.post(api_url, headers=headers, json=data)
29 res_json = res.json()
30 res_content = res_json['choices'][0]['message']['content']
31 except:
32 print("Network Error:")
33 try:
34 print(res.json())
35 except:
36 print("Request Failed")
37 else:
38 break
39
40 return res_content

Callers 1

run.pyFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected