naotokui commited on
Commit
db68f64
1 Parent(s): b78ec41

fixed: API key

Browse files
Files changed (1) hide show
  1. app.py +7 -5
app.py CHANGED
@@ -86,18 +86,19 @@ def get_answer(question):
86
  response = openai.ChatCompletion.create(
87
  model="gpt-3.5-turbo",
88
  messages=[
89
- {"role": "system", "content": "You are a rhythm generator. You generate rhythm patterns with the resolution of the 8th note"},
90
- {"role": "user", "content": "Please generate a rhythm pattern. You use the following drums. Kick drum:BD, Snare drum:SD, Closed-hihat:CH, Open-hihat:OH, Low-tom:LT, Mid-tom:MT, High-tom:HTYou need to write the time resolution first."},
91
  {"role": "assistant", "content": markdown_table_sample2},
92
- # {"role": "user", "content": "4分音符単位で生成して下さい. ドラムはBD, SD, CH, OH, LT, MT, HTを使います。最初に時間解像度の逆数を書いて下さい"},
93
- # {"role": "assistant", "content": markdown_table_sample},
94
  {"role": "user", "content": question}
95
  ]
96
  )
97
  return response["choices"][0]["message"]["content"]
98
 
99
  def generate_rhythm(query, state):
100
- if state["gen_count"] > MAX_QUERY or len(state["user_token"]) > 0:
 
101
  return [None, "You need to set your ChatGPT API Key to try more than %d times" % MAX_QUERY]
102
  state["gen_count"] = state["gen_count"] + 1
103
 
@@ -123,6 +124,7 @@ def generate_rhythm(query, state):
123
  # %%
124
 
125
  def on_token_change(user_token, state):
 
126
  openai.api_key = user_token or os.environ.get("OPENAI_API_KEY")
127
  state["user_token"] = user_token
128
  return state
 
86
  response = openai.ChatCompletion.create(
87
  model="gpt-3.5-turbo",
88
  messages=[
89
+ {"role": "system", "content": "You are a rhythm generator."},
90
+ {"role": "user", "content": "Please generate a rhythm pattern. You use the following drums. Kick drum:BD, Snare drum:SD, Closed-hihat:CH, Open-hihat:OH, Low-tom:LT, Mid-tom:MT, High-tom:HT. use 'x' for an accented beat, 'o' for a weak beat. You need to write the time resolution first."},
91
  {"role": "assistant", "content": markdown_table_sample2},
92
+ {"role": "user", "content": "Please generate a rhythm pattern. The resolution is the fourth note. You use the following drums. Kick drum:BD, Snare drum:SD, Closed-hihat:CH, Open-hihat:OH, Low-tom:LT, Mid-tom:MT, High-tom:HT. use 'x' for an accented beat, 'o' for a weak beat. You need to write the time resolution first."},
93
+ {"role": "assistant", "content": markdown_table_sample},
94
  {"role": "user", "content": question}
95
  ]
96
  )
97
  return response["choices"][0]["message"]["content"]
98
 
99
  def generate_rhythm(query, state):
100
+ print(state)
101
+ if state["gen_count"] > MAX_QUERY and len(state["user_token"]) == 0:
102
  return [None, "You need to set your ChatGPT API Key to try more than %d times" % MAX_QUERY]
103
  state["gen_count"] = state["gen_count"] + 1
104
 
 
124
  # %%
125
 
126
  def on_token_change(user_token, state):
127
+ print(user_token)
128
  openai.api_key = user_token or os.environ.get("OPENAI_API_KEY")
129
  state["user_token"] = user_token
130
  return state