Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- baseline/run_baseline.py +21 -4
baseline/run_baseline.py
CHANGED
|
@@ -27,10 +27,19 @@ BASE_URL = os.getenv("OPENENV_URL", "http://127.0.0.1:8000")
|
|
| 27 |
API_BASE_URL = os.getenv("OPENAI_BASE_URL", "https://api.openai.com/v1")
|
| 28 |
MODEL_NAME = os.getenv("OPENENV_MODEL", "gpt-4o-mini")
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
async def openai_agent(observation) -> Action:
|
| 36 |
"""Uses LLM to suggest a code fix."""
|
|
@@ -53,6 +62,14 @@ Provide ONLY a valid JSON object matching this schema:
|
|
| 53 |
"think": "Your chain-of-thought reasoning before patching (important!)"
|
| 54 |
}}
|
| 55 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
try:
|
| 57 |
response = await client.chat.completions.create(
|
| 58 |
model=MODEL_NAME,
|
|
|
|
| 27 |
API_BASE_URL = os.getenv("OPENAI_BASE_URL", "https://api.openai.com/v1")
|
| 28 |
MODEL_NAME = os.getenv("OPENENV_MODEL", "gpt-4o-mini")
|
| 29 |
|
| 30 |
+
_client = None
|
| 31 |
+
|
| 32 |
+
def get_openai_client():
|
| 33 |
+
global _client
|
| 34 |
+
if _client is None:
|
| 35 |
+
api_key = os.getenv("OPENAI_API_KEY")
|
| 36 |
+
if not api_key:
|
| 37 |
+
return None
|
| 38 |
+
_client = AsyncOpenAI(
|
| 39 |
+
api_key=api_key,
|
| 40 |
+
base_url=API_BASE_URL
|
| 41 |
+
)
|
| 42 |
+
return _client
|
| 43 |
|
| 44 |
async def openai_agent(observation) -> Action:
|
| 45 |
"""Uses LLM to suggest a code fix."""
|
|
|
|
| 62 |
"think": "Your chain-of-thought reasoning before patching (important!)"
|
| 63 |
}}
|
| 64 |
"""
|
| 65 |
+
client = get_openai_client()
|
| 66 |
+
if not client:
|
| 67 |
+
return Action(
|
| 68 |
+
patch=observation.buggy_code,
|
| 69 |
+
task_id=observation.task_id,
|
| 70 |
+
think="Skipping LLM call: OPENAI_API_KEY not set."
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
try:
|
| 74 |
response = await client.chat.completions.create(
|
| 75 |
model=MODEL_NAME,
|