Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit e2c75f7

Browse files
authored
Make swelancer agent use an async completion function (#51)
1 parent 12621cb commit e2c75f7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

swelancer_agent.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@
3636
from nanoeval_alcatraz.task_to_alcatraz_config import task_to_alcatraz_config
3737
from nanoeval_alcatraz.alcatraz_computer_interface import AlcatrazComputerInterface
3838

39-
from openai import OpenAI
39+
from openai import AsyncOpenAI
4040
import os
4141
import tiktoken
4242

4343

44-
client = OpenAI(
44+
client = AsyncOpenAI(
4545
api_key=os.environ.get("OPENAI_API_KEY"), # This is the default and can be omitted
4646
)
4747

@@ -65,10 +65,10 @@ def trim_messages(messages: list[dict[str, Any]], max_tokens: int, model: str =
6565
messages.pop(1)
6666
return messages
6767

68-
def get_model_response(messages: list[dict[str, Any]]) -> str:
68+
async def get_model_response(messages: list[dict[str, Any]]) -> str:
6969
messages = trim_messages(messages, 110000)
7070

71-
chat_completion = client.chat.completions.create(
71+
chat_completion = await client.chat.completions.create(
7272
messages=messages, # type: ignore
7373
model="gpt-4o",
7474
)
@@ -126,7 +126,7 @@ async def run(self, task: ComputerTask) -> AsyncGenerator[Step | FinalResult, No
126126
print(messages)
127127

128128
for remaining_turns in range(max_turns, 0, -1):
129-
model_response = get_model_response(messages)
129+
model_response = await get_model_response(messages)
130130
print(model_response)
131131

132132
messages.append({"role": "assistant", "content": model_response})
@@ -182,4 +182,4 @@ async def run(self, task: ComputerTask) -> AsyncGenerator[Step | FinalResult, No
182182
raise
183183
yield FinalResultSuccessful(
184184
grade=Grade(score=0, grader_log=f"Grading failed with error: {str(e)}")
185-
)
185+
)

0 commit comments

Comments
 (0)