shukdevdatta123 commited on
Commit
6fe0a96
·
verified ·
1 Parent(s): 5fd0c51

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -7,12 +7,18 @@ def get_diagram_code(prompt, diagram_type, api_key):
7
  # Set the OpenAI API key dynamically based on user input
8
  openai.api_key = api_key
9
 
10
- response = openai.Completion.create(
11
- engine="gpt-4",
12
- prompt=f"Generate a {diagram_type} diagram in Mermaid.js syntax based on the following prompt: {prompt}",
 
 
 
 
13
  max_tokens=500
14
  )
15
- return response.choices[0].text.strip()
 
 
16
  except Exception as e:
17
  st.error(f"Error: {e}")
18
  return None
 
7
  # Set the OpenAI API key dynamically based on user input
8
  openai.api_key = api_key
9
 
10
+ # For GPT-4 and other chat models, use the v1/chat/completions endpoint
11
+ response = openai.ChatCompletion.create(
12
+ model="gpt-4", # Make sure you're using the right model
13
+ messages=[
14
+ {"role": "system", "content": "You are a helpful assistant."},
15
+ {"role": "user", "content": f"Generate a {diagram_type} diagram in Mermaid.js syntax based on the following prompt: {prompt}"}
16
+ ],
17
  max_tokens=500
18
  )
19
+
20
+ return response['choices'][0]['message']['content'].strip()
21
+
22
  except Exception as e:
23
  st.error(f"Error: {e}")
24
  return None