CoolFace
Apppublic

rishil2005/github-issue-triage-env

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes
inference.py79 linesDownload Raw Back to root
1from __future__ import annotations2import os3import json4from openai import OpenAI5 6from environment import IssueEnvironment7from models import AgentAction, IssueObservation8 9# The grader automatically injects these environment variables!10client = OpenAI(11    base_url=os.environ.get("API_BASE_URL", "https://api.openai.com/v1"), 12    api_key=os.environ.get("API_KEY", "dummy") 13)14 15def dummy_agent_logic(observation: IssueObservation) -> AgentAction:16    prompt = f"""17    You are triaging a GitHub issue.18    Title: {observation.title}19    Body: {observation.body}20 21    Rules:22    - If it's a feature request -> {{"action_type": "AddLabel", "label": "enhancement", "comment": null}}23    - If it's a bug WITH steps -> {{"action_type": "AddLabel", "label": "bug", "comment": null}}24    - If it's a bug WITHOUT steps -> {{"action_type": "RequestMoreInfo", "label": null, "comment": "Need steps"}}25    26    Return ONLY valid JSON matching the exact keys above. Do not include markdown formatting like ```json.27    """28    29    try:30        response = client.chat.completions.create(31            model="gpt-3.5-turbo", 32            messages=[{"role": "user", "content": prompt}],33            temperature=034        )35        36        content = response.choices[0].message.content.strip()37        if content.startswith("```json"):38            content = content[7:-3].strip()39        elif content.startswith("```"):40            content = content[3:-3].strip()41 42        result = json.loads(content)43        return AgentAction(**result)44        45    except Exception as e:46        return AgentAction(47            action_type="RequestMoreInfo", 48            comment="Please share more details and reproducible steps."49        )50 51def main() -> None:52    env = IssueEnvironment(dataset_path="dataset.json")53    observation = env.reset()54 55    task_num = 156 57    while observation is not None:58        # 1. Tell the grader a NEW task is starting59        print(f"[START] Task_{task_num}")60        61        action = dummy_agent_logic(observation)62        next_obs, reward, done, _info = env.step(action)63 64        # 2. Normalize our old reward into a float between 0.0 and 1.065        score = 1.0 if reward > 0 else 0.066        67        print(f"[STEP] Action: {action.action_type}")68        69        # 3. Tell the grader the task is done and feed it the 1.0 or 0.0 score70        print(f"[END] Task_{task_num} Total Score: {score}")71 72        observation = next_obs73        task_num += 174 75        if done:76            break77 78if __name__ == "__main__":79    main()