v4
Browse files- inference.py +7 -11
inference.py
CHANGED
|
@@ -40,7 +40,7 @@ refund / replace / reject / ask_proof
|
|
| 40 |
return "reject"
|
| 41 |
|
| 42 |
|
| 43 |
-
#
|
| 44 |
def safe_post(url, json=None, retries=3):
|
| 45 |
for i in range(retries):
|
| 46 |
try:
|
|
@@ -51,7 +51,7 @@ def safe_post(url, json=None, retries=3):
|
|
| 51 |
raise Exception("Failed after retries")
|
| 52 |
|
| 53 |
|
| 54 |
-
#
|
| 55 |
def log_start(**kwargs):
|
| 56 |
print("[START]", kwargs, flush=True)
|
| 57 |
|
|
@@ -62,7 +62,7 @@ def log_end(**kwargs):
|
|
| 62 |
print("[END]", kwargs, flush=True)
|
| 63 |
|
| 64 |
|
| 65 |
-
# MAIN
|
| 66 |
async def main():
|
| 67 |
client = OpenAI(
|
| 68 |
base_url=API_BASE_URL,
|
|
@@ -74,12 +74,9 @@ async def main():
|
|
| 74 |
task_scores = []
|
| 75 |
|
| 76 |
try:
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
res = safe_post(
|
| 80 |
-
f"{SPACE_URL}/reset",
|
| 81 |
-
json={"task": task}
|
| 82 |
-
)
|
| 83 |
result = res.json()
|
| 84 |
|
| 85 |
state = result["observation"]["echoed_message"]
|
|
@@ -108,7 +105,7 @@ async def main():
|
|
| 108 |
error=None
|
| 109 |
)
|
| 110 |
|
| 111 |
-
# GET
|
| 112 |
score = result.get("score", 0.5)
|
| 113 |
score = max(0.01, min(0.99, score))
|
| 114 |
|
|
@@ -128,6 +125,5 @@ async def main():
|
|
| 128 |
)
|
| 129 |
|
| 130 |
|
| 131 |
-
# ENTRY
|
| 132 |
if __name__ == "__main__":
|
| 133 |
asyncio.run(main())
|
|
|
|
| 40 |
return "reject"
|
| 41 |
|
| 42 |
|
| 43 |
+
# SAFE REQUEST
|
| 44 |
def safe_post(url, json=None, retries=3):
|
| 45 |
for i in range(retries):
|
| 46 |
try:
|
|
|
|
| 51 |
raise Exception("Failed after retries")
|
| 52 |
|
| 53 |
|
| 54 |
+
# LOGGING
|
| 55 |
def log_start(**kwargs):
|
| 56 |
print("[START]", kwargs, flush=True)
|
| 57 |
|
|
|
|
| 62 |
print("[END]", kwargs, flush=True)
|
| 63 |
|
| 64 |
|
| 65 |
+
# MAIN
|
| 66 |
async def main():
|
| 67 |
client = OpenAI(
|
| 68 |
base_url=API_BASE_URL,
|
|
|
|
| 74 |
task_scores = []
|
| 75 |
|
| 76 |
try:
|
| 77 |
+
# run 3 tasks
|
| 78 |
+
for _ in range(3):
|
| 79 |
+
res = safe_post(f"{SPACE_URL}/reset")
|
|
|
|
|
|
|
|
|
|
| 80 |
result = res.json()
|
| 81 |
|
| 82 |
state = result["observation"]["echoed_message"]
|
|
|
|
| 105 |
error=None
|
| 106 |
)
|
| 107 |
|
| 108 |
+
# GET SCORE FROM ENV
|
| 109 |
score = result.get("score", 0.5)
|
| 110 |
score = max(0.01, min(0.99, score))
|
| 111 |
|
|
|
|
| 125 |
)
|
| 126 |
|
| 127 |
|
|
|
|
| 128 |
if __name__ == "__main__":
|
| 129 |
asyncio.run(main())
|