mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-01-08 22:38:05 -05:00
fix: resolve deprecation warnings for pythonjsonlogger, PyGithub, and get_matching_events
- Update pythonjsonlogger.jsonlogger.JsonFormatter to pythonjsonlogger.json.JsonFormatter - Update Github(token) to Github(auth=Auth.Token(token)) for remaining instances - Replace deprecated get_matching_events with search_events using EventFilter Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
@@ -143,7 +143,7 @@ class GitHubDataCollector:
|
||||
try:
|
||||
installation_token = self._get_installation_access_token(installation_id)
|
||||
|
||||
with Github(installation_token) as github_client:
|
||||
with Github(auth=Auth.Token(installation_token)) as github_client:
|
||||
repo = github_client.get_repo(repo_name)
|
||||
issue = repo.get_issue(issue_number)
|
||||
comments = []
|
||||
@@ -237,7 +237,7 @@ class GitHubDataCollector:
|
||||
def _get_pr_commits(self, installation_id: str, repo_name: str, pr_number: int):
|
||||
commits = []
|
||||
installation_token = self._get_installation_access_token(installation_id)
|
||||
with Github(installation_token) as github_client:
|
||||
with Github(auth=Auth.Token(installation_token)) as github_client:
|
||||
repo = github_client.get_repo(repo_name)
|
||||
pr = repo.get_pull(pr_number)
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ class GithubManager(Manager):
|
||||
reaction: The reaction to add (e.g. "eyes", "+1", "-1", "laugh", "confused", "heart", "hooray", "rocket")
|
||||
installation_token: GitHub installation access token for API access
|
||||
"""
|
||||
with Github(installation_token) as github_client:
|
||||
with Github(auth=Auth.Token(installation_token)) as github_client:
|
||||
repo = github_client.get_repo(github_view.full_repo_name)
|
||||
# Add reaction based on view type
|
||||
if isinstance(github_view, GithubInlinePRComment):
|
||||
@@ -199,7 +199,7 @@ class GithubManager(Manager):
|
||||
outgoing_message = message.message
|
||||
|
||||
if isinstance(github_view, GithubInlinePRComment):
|
||||
with Github(installation_token) as github_client:
|
||||
with Github(auth=Auth.Token(installation_token)) as github_client:
|
||||
repo = github_client.get_repo(github_view.full_repo_name)
|
||||
pr = repo.get_pull(github_view.issue_number)
|
||||
pr.create_review_comment_reply(
|
||||
@@ -211,7 +211,7 @@ class GithubManager(Manager):
|
||||
or isinstance(github_view, GithubIssueComment)
|
||||
or isinstance(github_view, GithubIssue)
|
||||
):
|
||||
with Github(installation_token) as github_client:
|
||||
with Github(auth=Auth.Token(installation_token)) as github_client:
|
||||
repo = github_client.get_repo(github_view.full_repo_name)
|
||||
issue = repo.get_issue(number=github_view.issue_number)
|
||||
issue.create_comment(outgoing_message)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import asyncio
|
||||
import time
|
||||
|
||||
from github import Github
|
||||
from github import Auth, Github
|
||||
from integrations.github.github_view import (
|
||||
GithubInlinePRComment,
|
||||
GithubIssueComment,
|
||||
@@ -47,7 +47,7 @@ def fetch_github_issue_context(
|
||||
context_parts.append(f'Title: {github_view.title}')
|
||||
context_parts.append(f'Description:\n{github_view.description}')
|
||||
|
||||
with Github(user_token) as github_client:
|
||||
with Github(auth=Auth.Token(user_token)) as github_client:
|
||||
repo = github_client.get_repo(github_view.full_repo_name)
|
||||
issue = repo.get_issue(github_view.issue_number)
|
||||
if issue.labels:
|
||||
|
||||
@@ -735,7 +735,7 @@ class GithubFactory:
|
||||
payload['installation']['id']
|
||||
).token
|
||||
|
||||
with Github(access_token) as gh:
|
||||
with Github(auth=Auth.Token(access_token)) as gh:
|
||||
repo = gh.get_repo(selected_repo)
|
||||
login = (
|
||||
payload['organization']['login']
|
||||
@@ -872,7 +872,7 @@ class GithubFactory:
|
||||
access_token = integration.get_access_token(installation_id).token
|
||||
|
||||
head_ref = None
|
||||
with Github(access_token) as gh:
|
||||
with Github(auth=Auth.Token(access_token)) as gh:
|
||||
repo = gh.get_repo(selected_repo)
|
||||
pull_request = repo.get_pull(issue_number)
|
||||
head_ref = pull_request.head.ref
|
||||
|
||||
@@ -20,6 +20,7 @@ from openhands.events.action import (
|
||||
AgentFinishAction,
|
||||
MessageAction,
|
||||
)
|
||||
from openhands.events.event_filter import EventFilter
|
||||
from openhands.events.event_store_abc import EventStoreABC
|
||||
from openhands.events.observation.agent import AgentStateChangedObservation
|
||||
from openhands.integrations.service_types import Repository
|
||||
@@ -203,18 +204,27 @@ def get_summary_for_agent_state(
|
||||
def get_final_agent_observation(
|
||||
event_store: EventStoreABC,
|
||||
) -> list[AgentStateChangedObservation]:
|
||||
return event_store.get_matching_events(
|
||||
source=EventSource.ENVIRONMENT,
|
||||
event_types=(AgentStateChangedObservation,),
|
||||
limit=1,
|
||||
events = event_store.search_events(
|
||||
reverse=True,
|
||||
limit=1,
|
||||
filter=EventFilter(
|
||||
source=EventSource.ENVIRONMENT.value,
|
||||
include_types=(AgentStateChangedObservation,),
|
||||
),
|
||||
)
|
||||
return [e for e in events if isinstance(e, AgentStateChangedObservation)]
|
||||
|
||||
|
||||
def get_last_user_msg(event_store: EventStoreABC) -> list[MessageAction]:
|
||||
return event_store.get_matching_events(
|
||||
source=EventSource.USER, event_types=(MessageAction,), limit=1, reverse='true'
|
||||
events = event_store.search_events(
|
||||
reverse=True,
|
||||
limit=1,
|
||||
filter=EventFilter(
|
||||
source=EventSource.USER.value,
|
||||
include_types=(MessageAction,),
|
||||
),
|
||||
)
|
||||
return [e for e in events if isinstance(e, MessageAction)]
|
||||
|
||||
|
||||
def extract_summary_from_event_store(
|
||||
@@ -226,13 +236,18 @@ def extract_summary_from_event_store(
|
||||
conversation_link = CONVERSATION_URL.format(conversation_id)
|
||||
summary_instruction = get_summary_instruction()
|
||||
|
||||
instruction_event: list[MessageAction] = event_store.get_matching_events(
|
||||
query=json.dumps(summary_instruction),
|
||||
source=EventSource.USER,
|
||||
event_types=(MessageAction,),
|
||||
limit=1,
|
||||
instruction_events = event_store.search_events(
|
||||
reverse=True,
|
||||
limit=1,
|
||||
filter=EventFilter(
|
||||
query=json.dumps(summary_instruction),
|
||||
source=EventSource.USER.value,
|
||||
include_types=(MessageAction,),
|
||||
),
|
||||
)
|
||||
instruction_event: list[MessageAction] = [
|
||||
e for e in instruction_events if isinstance(e, MessageAction)
|
||||
]
|
||||
|
||||
final_agent_observation = get_final_agent_observation(event_store)
|
||||
|
||||
@@ -247,15 +262,20 @@ def extract_summary_from_event_store(
|
||||
|
||||
event_id: int = instruction_event[0].id
|
||||
|
||||
agent_messages: list[MessageAction | AgentFinishAction] = (
|
||||
event_store.get_matching_events(
|
||||
start_id=event_id,
|
||||
source=EventSource.AGENT,
|
||||
event_types=(MessageAction, AgentFinishAction),
|
||||
reverse=True,
|
||||
limit=1,
|
||||
)
|
||||
agent_messages_events = event_store.search_events(
|
||||
start_id=event_id,
|
||||
reverse=True,
|
||||
limit=1,
|
||||
filter=EventFilter(
|
||||
source=EventSource.AGENT.value,
|
||||
include_types=(MessageAction, AgentFinishAction),
|
||||
),
|
||||
)
|
||||
agent_messages: list[MessageAction | AgentFinishAction] = [
|
||||
e
|
||||
for e in agent_messages_events
|
||||
if isinstance(e, (MessageAction, AgentFinishAction))
|
||||
]
|
||||
|
||||
if len(agent_messages) == 0:
|
||||
logger.warning(
|
||||
|
||||
@@ -552,11 +552,11 @@ def get_uvicorn_json_log_config() -> dict:
|
||||
},
|
||||
# Actual JSON formatters used by handlers below
|
||||
'json': {
|
||||
'()': 'pythonjsonlogger.jsonlogger.JsonFormatter',
|
||||
'()': 'pythonjsonlogger.json.JsonFormatter',
|
||||
'fmt': '%(message)s %(levelname)s %(name)s %(asctime)s %(exc_info)s',
|
||||
},
|
||||
'json_access': {
|
||||
'()': 'pythonjsonlogger.jsonlogger.JsonFormatter',
|
||||
'()': 'pythonjsonlogger.json.JsonFormatter',
|
||||
'fmt': '%(message)s %(levelname)s %(name)s %(asctime)s %(client_addr)s %(request_line)s %(status_code)s',
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user