Basshole commited on
Commit
ffd3b69
·
verified ·
1 Parent(s): c6fd6e0

Upload 5why.py

Browse files
Files changed (1) hide show
  1. 5why.py +47 -0
5why.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import os
3
+
4
+ from openai import OpenAI
5
+ client = OpenAI(
6
+ api_key= os.environ["gptkey"]
7
+ )
8
+ def ideagen(context):
9
+ total_prompt_tokens_used = 0
10
+ total_completion_tokens_used = 0
11
+
12
+ #print(context)
13
+
14
+ messages_base = [
15
+ {"role": "system", "content": "請扮演行銷策略的大師,善於觀察社會巨觀的的發展和人與人之間微觀的互動,從中挖掘出不為人察覺的行為洞察,好的洞察可以幫助找出問題背後的問題,透過一層層深入的分析,幫助找出問題的核心。"},
16
+ ]
17
+ messages_base.extend([{"role": "user", "content": f"請幫助我分析{context}問題的成因。"}])
18
+ messages_base.extend([{"role": "user", "content": "請用以下的格式回答:我'問題A',因為'理由A',之後將'理由A'變成新的問題,重複以上的分析:我'理由A',因為'理由B',請重複以上的動作五次,每次都挖掘更深入的心理動機,但第三次請給我一個出乎意料的理由,理由來自於更尖銳、深刻的人群觀察,接露這些人不為人知的一面,請用markdown格式回覆我,包含'編號'、'問題'、'理由'欄位"}])
19
+ messages_base.extend([{"role": "user", "content": "請發揮你的創意跟想像並盡可能描述更多細節,必須要讓看到的人有驚豔的感覺。請使用繁體中文。"}])
20
+
21
+ full_text = ""
22
+ total_price = 0
23
+
24
+
25
+ #for _ in range(loop):
26
+ response = client.chat.completions.create(
27
+ model='gpt-4-0125-preview',
28
+ max_tokens=2000,
29
+ temperature=0.7,
30
+ messages=messages_base
31
+ )
32
+ completed_text = response.choices[0].message.content
33
+ total_prompt_tokens_used += response.usage.prompt_tokens
34
+ total_completion_tokens_used += response.usage.completion_tokens
35
+ price = total_prompt_tokens_used*0.03/1000 + total_completion_tokens_used*0.06/1000
36
+
37
+ full_text += completed_text + "\n\n----------\n\n"
38
+ total_price += price
39
+
40
+
41
+ price = "price:" + str(total_prompt_tokens_used*0.03/1000 + total_completion_tokens_used*0.06/1000) + "$"
42
+
43
+ full_text += "\n\n" + "price:" + str(total_price)
44
+
45
+
46
+ #return response.choices[0].message.content
47
+ return full_text