File size: 1,254 Bytes
db1214c 3630c06 db1214c 163a1e0 db1214c af12585 163a1e0 81b486e af12585 81b486e 163a1e0 db1214c 163a1e0 af12585 907512f af12585 81b486e af12585 81b486e af12585 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | import os
from openai import OpenAI
from env import EmailEnv
env = EmailEnv()
def call_llm(text):
try:
client = OpenAI(
api_key=os.environ.get("API_KEY"),
base_url=os.environ.get("API_BASE_URL")
)
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "Classify email and suggest reply."},
{"role": "user", "content": text}
]
)
return response.choices[0].message.content
except:
return "fallback"
try:
print("[START] task=easy_task", flush=True)
obs = env.reset()
text = obs["text"]
_ = call_llm(text) # required API call
# fallback logic
if "meeting" in text.lower():
action = {"label": "important", "reply": "Sure, I will attend the meeting."}
elif "lottery" in text.lower():
action = {"label": "spam", "reply": "This looks like spam."}
else:
action = {"label": "normal", "reply": "Sounds good!"}
reward = env.step(action)
print(f"[STEP] reward={reward}", flush=True)
print(f"[END] score={reward}", flush=True)
except Exception as e:
print("[ERROR]", str(e), flush=True) |