artintel235 commited on
Commit
c139381
·
verified ·
1 Parent(s): 1e98b4a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -1
app.py CHANGED
@@ -14,6 +14,8 @@ def get_api_key():
14
  def generate_response(prompt, model_name, api_key, extra_instructions=""):
15
  openai.api_key = api_key
16
  try:
 
 
17
  messages = [{"role": "user", "content": prompt + "\n" + extra_instructions}]
18
  stream = client.chat.completions.create(
19
  model=model_name,
@@ -83,5 +85,4 @@ def main():
83
  st.session_state.messages.append({"role": "assistant", "content": full_response})
84
 
85
  if __name__ == "__main__":
86
- client = openai.OpenAI() # Initialize the client here
87
  main()
 
14
  def generate_response(prompt, model_name, api_key, extra_instructions=""):
15
  openai.api_key = api_key
16
  try:
17
+ client = openai.OpenAI() # Instantiate OpenAI client within the function
18
+
19
  messages = [{"role": "user", "content": prompt + "\n" + extra_instructions}]
20
  stream = client.chat.completions.create(
21
  model=model_name,
 
85
  st.session_state.messages.append({"role": "assistant", "content": full_response})
86
 
87
  if __name__ == "__main__":
 
88
  main()