Spaces:
Running
Running
Update app.py
Browse files
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 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
13 |
max_tokens=500
|
14 |
)
|
15 |
-
|
|
|
|
|
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
|