Skip to content

Commit

Permalink
Merge pull request #22 from bettersg/agent/uat/openai-assistants-api-1
Browse files Browse the repository at this point in the history
Agent/uat/openai assistants api 1
  • Loading branch information
sarge1989 authored Mar 24, 2024
2 parents cbf32ec + 63afe90 commit e6a83a4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
31 changes: 16 additions & 15 deletions base/agent_base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,18 @@ def get_website_content(self, link):

def message_handler(self, message: MessagePayload):
messageId = message.messageId
try:
vote = self.check_message(message)
except UnsupportedMessageTypeException as e:
logging.info("Message type not supported")
return
except Exception as e:
raise ValueError(f"Error in check_message implementation: {e}")
# check if valid Vote
if not isinstance(vote, Vote):
raise TypeError(f"Expected Vote, got {type(vote)} from check_message implementation")

api_host = os.getenv("API_HOST")
agent_name = os.getenv("AGENT_NAME")
if not api_host:
raise ValueError("API_HOST environment variable not set")
if not agent_name:
raise ValueError("AGENT_NAME environment variable not set")

auth_req = google.auth.transport.requests.Request()
id_token = google.oauth2.id_token.fetch_id_token(auth_req, api_host)
headers = {"Authorization": f"Bearer {id_token}"}
try:
auth_req = google.auth.transport.requests.Request()
id_token = google.oauth2.id_token.fetch_id_token(auth_req, api_host)
headers = {"Authorization": f"Bearer {id_token}"}
except Exception as e:
raise ValueError(f"Error fetching ID token: {e}")
try:
vote_initialisation = VoteInitialisation(factCheckerName=agent_name)
res = requests.post(f"{api_host}/messages/{messageId}/voteRequests", json=vote_initialisation.model_dump(mode="json"), headers=headers)
Expand All @@ -58,6 +49,16 @@ def message_handler(self, message: MessagePayload):

if messageId not in vote_request_path:
raise ValueError(f"Vote request path does not contain messageId")
try:
vote = self.check_message(message)
except UnsupportedMessageTypeException as e:
logging.info("Message type not supported")
return
except Exception as e:
raise ValueError(f"Error in check_message implementation: {e}")
# check if valid Vote
if not isinstance(vote, Vote):
raise TypeError(f"Expected Vote, got {type(vote)} from check_message implementation")

try:
res = requests.patch(f"{api_host}/{vote_request_path}", json=vote.model_dump(mode="json"), headers=headers)
Expand Down
2 changes: 1 addition & 1 deletion implementation/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def process_call(tool_call):

start = time()

while not agent_complete and ((time() - start) < 60):
while not agent_complete and ((time() - start) < 120):
sleep(1)
run = client.beta.threads.runs.retrieve(
thread_id=thread.id,
Expand Down

0 comments on commit e6a83a4

Please sign in to comment.