generate_query.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from openai import OpenAI
  2. # os.environ["OPENAI_API_KEY"] = ""
  3. def openai_complete_if_cache(
  4. model="gpt-4o-mini", prompt=None, system_prompt=None, history_messages=[], **kwargs
  5. ) -> str:
  6. openai_client = OpenAI()
  7. messages = []
  8. if system_prompt:
  9. messages.append({"role": "system", "content": system_prompt})
  10. messages.extend(history_messages)
  11. messages.append({"role": "user", "content": prompt})
  12. response = openai_client.chat.completions.create(
  13. model=model, messages=messages, **kwargs
  14. )
  15. if not response.choices or response.choices[0].message is None:
  16. return ""
  17. return response.choices[0].message.content
  18. if __name__ == "__main__":
  19. description = ""
  20. prompt = f"""
  21. Given the following description of a dataset:
  22. {description}
  23. Please identify 5 potential users who would engage with this dataset. For each user, list 5 tasks they would perform with this dataset. Then, for each (user, task) combination, generate 5 questions that require a high-level understanding of the entire dataset.
  24. Output the results in the following structure:
  25. - User 1: [user description]
  26. - Task 1: [task description]
  27. - Question 1:
  28. - Question 2:
  29. - Question 3:
  30. - Question 4:
  31. - Question 5:
  32. - Task 2: [task description]
  33. ...
  34. - Task 5: [task description]
  35. - User 2: [user description]
  36. ...
  37. - User 5: [user description]
  38. ...
  39. """
  40. result = openai_complete_if_cache(model="gpt-4o-mini", prompt=prompt)
  41. file_path = "./queries.txt"
  42. with open(file_path, "w") as file:
  43. file.write(result)
  44. print(f"Queries written to {file_path}")