3636from nanoeval_alcatraz .task_to_alcatraz_config import task_to_alcatraz_config
3737from nanoeval_alcatraz .alcatraz_computer_interface import AlcatrazComputerInterface
3838
39- from openai import OpenAI
39+ from openai import AsyncOpenAI
4040import os
4141import 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