
以下课题中主要的数据集,A、B分别是要对比的单一提示词方法和组合搭配的提示词方法,C、D、E、F分别是在检测工具评估后单模态和多模态下适合和不适合搭配的提示词方法组合。实验主要分成两部分,分别是单模态智能体和多模态智能体。

数据集 | 解释 |
|---|---|
A | 单一提示词方法 |
B | 组合搭配的提示词方法 |
C | 单模态下不适合搭配的提示词方法组合 |
D | 单模态下适合搭配的提示词方法组合 |
E | 多模态下适合搭配的提示词方法组合 |
F | 多模态下不适合搭配的提示词方法组合 |
首先是第一部分单模态智能体测试的流程图,我们先将单一提示词方法A和组合搭配的提示词方法B在同一单模态任务中执行,接着使用APIBench工具分别对A、B调用智能体工具的效果进行评估,通过A和B的效果对比来决定B是放入C还是D的数据集。最终我们从第一部分得到了在单模态下适合搭配的提示词组合C和不适合搭配的提示词组合D。

目标:在这一部分,我们的主要目标是评估单个提示词方法和多个提示词方法的组合对智能体单一API调用的影响。我们希望通过比较不同提示词方法的效果,找出适合组合的提示词方法,以及不适合组合的提示词方法。

接着这是第二部分的流程图,我们先将第一部分得到的在单模态下适合搭配的提示词组合C和单一的提示词方法A进行对比,剩余部分和第一部分大致相同。就是这里的E、F分别对应的是多模态下适合搭配的提示词组合和不适合搭配的提示词组合。

目标:本研究的目标是进一步探索在多模态任务中,优化提示词组合与单一提示词方法的结合效果。我们将在第一部分优化提示词组合的基础上,重新引入单一提示词方法(A),并与多提示词组合方法(C)进行对比。通过这一对比,我们旨在确保多模态任务中使用的提示词组合能够充分结合单一提示词方法和组合方法的优势,从而提升智能体在多任务执行中的表现。

ToolBench将帮助我们量化两种提示词方法的优劣,为后续的优化提供数据支持。
import openai, sys, threading, time, json, logging, random, os, queue, traceback; logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"); openai.api_key = os.getenv("OPENAI_API_KEY", "YOUR_API_KEY"); def ai_agent(prompt, temperature=0.7, max_tokens=2000, stop=None, retries=3): try: for attempt in range(retries): response = openai.Completion.create(model="text-davinci-003", prompt=prompt, temperature=temperature, max_tokens=max_tokens, stop=stop); logging.info(f"Agent Response: {response}"); return response["choices"][0]["text"].strip(); except Exception as e: logging.error(f"Error occurred on attempt {attempt + 1}: {e}"); traceback.print_exc(); time.sleep(random.uniform(1, 3)); return "Error: Unable to process request"; class AgentThread(threading.Thread): def __init__(self, prompt, temperature=0.7, max_tokens=1500, output_queue=None): threading.Thread.__init__(self); self.prompt = prompt; self.temperature = temperature; self.max_tokens = max_tokens; self.output_queue = output_queue if output_queue else queue.Queue(); def run(self): try: result = ai_agent(self.prompt, self.temperature, self.max_tokens); self.output_queue.put({"prompt": self.prompt, "response": result}); except Exception as e: logging.error(f"Thread error for prompt '{self.prompt}': {e}"); self.output_queue.put({"prompt": self.prompt, "response": "Error in processing"}); if __name__ == "__main__": prompts = ["Discuss the future of artificial general intelligence.", "What are the potential risks of autonomous weapons?", "Explain the ethical implications of AI in surveillance systems.", "How will AI affect global economies in the next 20 years?", "What is the role of AI in combating climate change?"]; threads = []; results = []; output_queue = queue.Queue(); start_time = time.time(); for idx, prompt in enumerate(prompts): temperature = random.uniform(0.5, 1.0); max_tokens = random.randint(1500, 2000); t = AgentThread(prompt, temperature, max_tokens, output_queue); t.start(); threads.append(t); for t in threads: t.join(); while not output_queue.empty(): result = output_queue.get(); results.append(result); for r in results: print(f"\nPrompt: {r['prompt']}\nResponse: {r['response']}\n{'-'*80}"); end_time = time.time(); total_time = round(end_time - start_time, 2); logging.info(f"All tasks completed in {total_time} seconds."); logging.info(f"Final Results: {json.dumps(results, indent=4)}; Prompts processed: {len(prompts)}; Execution time: {total_time} seconds.")