MCPcopy Create free account
hub / github.com/Alibaba-NLP/DeepResearch / doubao_api

Function doubao_api

WebAgent/WebWalker/src/rag_system.py:148–190  ·  view source on GitHub ↗
(ds, output_path)

Source from the content-addressed store, hash-verified

146 asyncio.run(run_gemini_api())
147
148def doubao_api(ds, output_path):
149 if ARK_API_KEY is None or ARK_MODEL is None:
150 print("Please set ARK_API_KEY environment variable.")
151 return
152 client = Ark(base_url="https://ark.cn-beijing.volces.com/api/v3", api_key=ARK_API_KEY)
153 MAX_WORKERS = 10
154
155 def call(data):
156 try:
157 completion = client.bot_chat.completions.create(
158 model=ARK_MODEL,
159 messages=[
160 {"role": "system", "content": "你是豆包,是由字节跳动开发的 AI 人工智能助手"},
161 {"role": "user", "content": data["question"]}
162 ]
163 )
164 return completion.choices[0].message.content
165 except Exception as e:
166 print(f"Error: {e}")
167 return
168
169 if not os.path.exists(output_path):
170 open(output_path, "w").close()
171 visited = set()
172 with open(output_path, "r", encoding="utf-8") as f:
173 visited.update(json.loads(line)["question"] for line in f)
174 data_list = []
175 for item in ds["question"]:
176 if item not in visited:
177 temp = {"question": item}
178 data_list.append(temp)
179
180 with tqdm(total=len(data_list)) as pbar:
181 with concurrent.futures.ThreadPoolExecutor(max_workers=MAX_WORKERS) as executor:
182 future_to_data = {executor.submit(call, data): data for data in data_list}
183 for future in concurrent.futures.as_completed(future_to_data):
184 outputs = future.result()
185 data = future_to_data[future]
186 if outputs:
187 data["pred"] = outputs
188 with open(output_path, "a", encoding="utf-8") as f:
189 f.write(json.dumps(data, ensure_ascii=False) + "\n")
190 pbar.update(1)
191
192def kimi_api(ds, output_path):
193 if MOONSHOT_API_KEY is None:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected