Lilli98 commited on
Commit
f466cd4
·
verified ·
1 Parent(s): 7cd8c1a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -18,10 +18,9 @@ import random
18
  import json
19
  from datetime import datetime
20
  from pathlib import Path
21
-
22
  import streamlit as st
23
  import pandas as pd
24
- import openai
25
  from huggingface_hub import upload_file, HfApi
26
 
27
  # ---------------------------
@@ -87,7 +86,9 @@ def upload_log_to_hf(local_path: Path, participant_id: str):
87
  # ---------------------------
88
  # OpenAI helper
89
  # ---------------------------
90
- openai.api_key = os.getenv("OPENAI_API_KEY")
 
 
91
 
92
  def call_llm_for_order(role: str, local_state: dict, info_sharing_visible: bool, demand_history: list, max_tokens=40, temperature=0.7):
93
  """
@@ -114,7 +115,7 @@ def call_llm_for_order(role: str, local_state: dict, info_sharing_visible: bool,
114
  )
115
 
116
  try:
117
- resp = openai.ChatCompletion.create(
118
  model=OPENAI_MODEL,
119
  messages=[
120
  {"role": "system", "content": "You are an automated Beer Game agent who decides weekly orders."},
@@ -124,7 +125,7 @@ def call_llm_for_order(role: str, local_state: dict, info_sharing_visible: bool,
124
  temperature=temperature,
125
  n=1
126
  )
127
- raw = resp.choices[0].message.get("content", "").strip()
128
  except Exception as e:
129
  raw = f"OPENAI_ERROR: {str(e)}"
130
  # fallback later
@@ -478,12 +479,12 @@ with col_sidebar:
478
  # quick test prompt
479
  try:
480
  test_prompt = "You are a helpful agent. Reply with '42'."
481
- resp = openai.ChatCompletion.create(
482
  model=OPENAI_MODEL,
483
  messages=[{"role":"user","content":test_prompt}],
484
  max_tokens=10
485
  )
486
- st.write("LLM raw:", resp.choices[0].message.get("content"))
487
  except Exception as e:
488
  st.error(f"LLM test failed: {e}")
489
 
 
18
  import json
19
  from datetime import datetime
20
  from pathlib import Path
21
+ from openai import OpenAI
22
  import streamlit as st
23
  import pandas as pd
 
24
  from huggingface_hub import upload_file, HfApi
25
 
26
  # ---------------------------
 
86
  # ---------------------------
87
  # OpenAI helper
88
  # ---------------------------
89
+
90
+ OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
91
+ client = OpenAI(api_key=OPENAI_API_KEY)
92
 
93
  def call_llm_for_order(role: str, local_state: dict, info_sharing_visible: bool, demand_history: list, max_tokens=40, temperature=0.7):
94
  """
 
115
  )
116
 
117
  try:
118
+ resp = client.chat.completions.create(
119
  model=OPENAI_MODEL,
120
  messages=[
121
  {"role": "system", "content": "You are an automated Beer Game agent who decides weekly orders."},
 
125
  temperature=temperature,
126
  n=1
127
  )
128
+ raw = resp.choices[0].message.content.strip()
129
  except Exception as e:
130
  raw = f"OPENAI_ERROR: {str(e)}"
131
  # fallback later
 
479
  # quick test prompt
480
  try:
481
  test_prompt = "You are a helpful agent. Reply with '42'."
482
+ resp = client.chat.completions.create(
483
  model=OPENAI_MODEL,
484
  messages=[{"role":"user","content":test_prompt}],
485
  max_tokens=10
486
  )
487
+ st.write("LLM raw:", resp.choices[0].message.content)
488
  except Exception as e:
489
  st.error(f"LLM test failed: {e}")
490