Shakeel401 commited on
Commit
624426e
·
verified ·
1 Parent(s): 9111a92

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -18
app.py CHANGED
@@ -24,32 +24,29 @@ AIRTABLE_TABLE = "Appointments"
24
  # ---- Ephemeral Key Endpoint ----
25
  @app.get("/get-ephemeral-key")
26
  def get_ephemeral_key():
27
- import requests, os
28
-
29
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
30
- if not OPENAI_API_KEY:
31
- return {"error": "Missing OPENAI_API_KEY"}
32
-
33
- url = "https://api.openai.com/v1/realtime/sessions"
34
  headers = {
35
  "Authorization": f"Bearer {OPENAI_API_KEY}",
36
  "Content-Type": "application/json",
37
  }
 
 
38
  body = {
39
- "model": "gpt-4o-realtime-preview",
40
- "voice": "verse"
 
 
 
 
 
41
  }
42
 
43
- try:
44
- res = requests.post(url, headers=headers, json=body)
45
- data = res.json()
46
- # ✅ Return only the ephemeral key
47
- if "client_secret" in data:
48
- return {"client_secret": data["client_secret"]}
49
- else:
50
- return {"error": "Missing client_secret in response", "details": data}
51
- except Exception as e:
52
- return {"error": str(e)}
53
 
54
 
55
  # ---- Add Appointment ----
 
24
  # ---- Ephemeral Key Endpoint ----
25
  @app.get("/get-ephemeral-key")
26
  def get_ephemeral_key():
 
 
27
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
28
+ url = "https://api.openai.com/v1/realtime/client_secrets"
 
 
 
29
  headers = {
30
  "Authorization": f"Bearer {OPENAI_API_KEY}",
31
  "Content-Type": "application/json",
32
  }
33
+
34
+ # Session configuration matches GA spec
35
  body = {
36
+ "session": {
37
+ "type": "realtime",
38
+ "model": "gpt-4o-realtime-preview",
39
+ "audio": {
40
+ "output": {"voice": "verse"} # optional
41
+ }
42
+ }
43
  }
44
 
45
+ res = requests.post(url, headers=headers, json=body)
46
+ print(res)
47
+ data = res.json()
48
+ print(data)
49
+ return data
 
 
 
 
 
50
 
51
 
52
  # ---- Add Appointment ----