mirror of
https://github.com/j93es/browser-use-oauth.git
synced 2026-06-04 09:11:53 +09:00
[Refactor] 리팩터링
This commit is contained in:
parent
26b40e0e65
commit
bbd2d6d636
20 changed files with 397 additions and 257 deletions
40
lib/browser_use_utils/run_agent.py
Normal file
40
lib/browser_use_utils/run_agent.py
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
from typing import Any
|
||||
from pydantic import BaseModel
|
||||
from lib.browser_use_utils.clean_resources import clean_agent_resources
|
||||
from lib.config import GOOGLE_MODEL
|
||||
from browser_use import (
|
||||
Agent,
|
||||
Controller,
|
||||
)
|
||||
from lib.browser_use_utils.create_google_ai import create_google_ai
|
||||
|
||||
|
||||
async def run_agent(session, initial_actions, ReturnModel: type[BaseModel], task: str) -> tuple[bool, str, Any | None]:
|
||||
|
||||
controller = Controller(output_model=ReturnModel, exclude_actions=['search_google'])
|
||||
agent = Agent(
|
||||
browser_session=session,
|
||||
initial_actions=initial_actions,
|
||||
task=task,
|
||||
llm=create_google_ai(GOOGLE_MODEL),
|
||||
controller=controller,
|
||||
)
|
||||
|
||||
try:
|
||||
response = await agent.run()
|
||||
final_result = response.final_result()
|
||||
|
||||
if final_result is None:
|
||||
return False, "LLM이 반환한 최종 결과가 없습니다.", None
|
||||
except Exception as e:
|
||||
# API 쿼터 문제인지 확인
|
||||
if "ResourceExhausted" in str(e) or "429" in str(e):
|
||||
return False, "API 쿼터 에러로 인한 실패", None
|
||||
# 일반 에러 처리
|
||||
else:
|
||||
return False, "일반 에러로 인한 실패", None
|
||||
finally:
|
||||
await clean_agent_resources(agent)
|
||||
|
||||
return True, "ok", final_result
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue