moon_shoot_api.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from openai import OpenAI
  2. class MoonShotHandle():
  3. def __init__(self, api_key=None, api_base=None):
  4. self.OPENAI_API_KEY = 'sk-tz1VaKqksTzk0F8HxlU4YVGwj7oa1g0c0puGNUZrdn9MDtzm'
  5. self.model = "moonshot-v1-8k"
  6. def chat(self, question):
  7. return self.chat_with_chatgpt(question)
  8. def chat_with_chatgpt(self, prompt):
  9. client = OpenAI(
  10. api_key=self.OPENAI_API_KEY,
  11. base_url="https://api.moonshot.cn/v1",
  12. )
  13. chat_completion = client.chat.completions.create(
  14. messages=[
  15. {
  16. "role": "user",
  17. "content": prompt,
  18. }
  19. ],
  20. model=self.model,
  21. )
  22. response = chat_completion.choices[0].message.content
  23. return response
  24. # single_title_prompt = """
  25. # 我会给你一个视频标题,需要你帮我用你所学的知识来帮我分析出以下信息,信息我都写到 json 里面了
  26. # {
  27. # "key_words": [], # 返回三个关键词
  28. # "search_keys": [], # 标题可能的搜索关键词,返回 3 个
  29. # "extra_keys": [], # 关心这个视频的用户还会关心哪些关键词, 返回 3 个
  30. # "tone": 标题的语气,用一个词概括,
  31. # "target_audience": 标题的受众群体,用一个词概括,
  32. # "target_age": 标题的受众年龄段,从 老年, 中年,青年,小孩, 不限, 这五个里面选择,
  33. # "target_gender": 受众性别,
  34. # "address": 受众可能属于哪个城市,
  35. # "theme": 标题的主题, 用一个词概括
  36. # }
  37. # 只需要返回一个 json,key 和上面的一样,
  38. # 我给你的标题是:
  39. # """
  40. # single_title_prompt = single_title_prompt + "家里的盐该怎么选"
  41. # for i in range(30):
  42. # res = MoonShotHandle().chat(single_title_prompt)
  43. # print(res)