Shardul Dhekane commited on
Commit ·
1908b01
1
Parent(s): 03fba7d
config file initialize
Browse files- Dockerfile +0 -0
- inference.py +63 -0
- openenv.yaml +56 -0
- requirements.txt +0 -0
Dockerfile
ADDED
|
File without changes
|
inference.py
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import json
|
| 3 |
+
import argparse
|
| 4 |
+
from typing import Dict, Any, Optional
|
| 5 |
+
import requests
|
| 6 |
+
|
| 7 |
+
API_BASE_URL = os.environ.get("API_BASE_URL", "https://api.openai.com/v1")
|
| 8 |
+
MODEL_NAME = os.environ.get("MODEL_NAME", "gpt-4")
|
| 9 |
+
API_KEY = os.environ.get("API_KEY", os.environ.get("OPENAI_API_KEY", ""))
|
| 10 |
+
TEMPERATURE = float(os.environ.get("TEMPERATURE", "0.7"))
|
| 11 |
+
MAX_TOKENS = int(os.environ.get("MAX_TOKENS", "2000"))
|
| 12 |
+
|
| 13 |
+
FALLBACK_ACTION = '{"action_type": "request_changes", "comments": [], "suggestions": []}'
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class LLMClient:
|
| 17 |
+
|
| 18 |
+
def __init__(self, base_url: str, api_key: str, model: str):
|
| 19 |
+
self.base_url = base_url.rstrip('/')
|
| 20 |
+
self.api_key = api_key
|
| 21 |
+
self.model = model
|
| 22 |
+
self.api_type = self._detect_api_type()
|
| 23 |
+
|
| 24 |
+
def _detect_api_type(self) -> str:
|
| 25 |
+
if "googleapis.com" in self.base_url or "generativelanguage" in self.base_url:
|
| 26 |
+
return "gemini"
|
| 27 |
+
elif "openai.com" in self.base_url:
|
| 28 |
+
return "openai"
|
| 29 |
+
else:
|
| 30 |
+
return "openai_compatible"
|
| 31 |
+
|
| 32 |
+
def chat_completion(self, messages: list, temperature: float = 0.7, max_tokens: int = 2000) -> str:
|
| 33 |
+
if self.api_type == "gemini":
|
| 34 |
+
return self._gemini_completion(messages, temperature, max_tokens)
|
| 35 |
+
else:
|
| 36 |
+
return self._openai_completion(messages, temperature, max_tokens)
|
| 37 |
+
|
| 38 |
+
def _openai_completion(self, messages: list, temperature: float, max_tokens: int) -> str:
|
| 39 |
+
headers = {
|
| 40 |
+
"Authorization": f"Bearer {self.api_key}",
|
| 41 |
+
"Content-Type": "application/json"
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
payload = {
|
| 45 |
+
"model": self.model,
|
| 46 |
+
"messages": messages,
|
| 47 |
+
"temperature": temperature,
|
| 48 |
+
"max_tokens": max_tokens
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
try:
|
| 52 |
+
response = requests.post(
|
| 53 |
+
f"{self.base_url}/chat/completions",
|
| 54 |
+
headers=headers,
|
| 55 |
+
json=payload,
|
| 56 |
+
timeout=30
|
| 57 |
+
)
|
| 58 |
+
response.raise_for_status()
|
| 59 |
+
result = response.json()
|
| 60 |
+
return result["choices"][0]["message"]["content"]
|
| 61 |
+
except Exception as e:
|
| 62 |
+
print(f"OpenAI API error: {e}")
|
| 63 |
+
raise
|
openenv.yaml
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: code-review-agent-env
|
| 2 |
+
version: 1.0.0
|
| 3 |
+
description: |
|
| 4 |
+
A realistic code review environment where AI agents review pull requests,
|
| 5 |
+
identify issues, suggest improvements, and make approval decisions.
|
| 6 |
+
Models real-world software development workflows.
|
| 7 |
+
|
| 8 |
+
authors:
|
| 9 |
+
- Ashish <ashishkbaberwal@gmail.com>
|
| 10 |
+
- Shardul <shardulmd@gmail.com>
|
| 11 |
+
- Harshit <shakyanitin807@gmail.com>
|
| 12 |
+
tags:
|
| 13 |
+
- code-review
|
| 14 |
+
- software-engineering
|
| 15 |
+
- agent-evaluation
|
| 16 |
+
- real-world-task
|
| 17 |
+
|
| 18 |
+
license: MIT
|
| 19 |
+
|
| 20 |
+
environment:
|
| 21 |
+
class: environment.env.CodeReviewEnv
|
| 22 |
+
entry_point: environment.env:CodeReviewEnv
|
| 23 |
+
|
| 24 |
+
tasks:
|
| 25 |
+
- id: bug_detection_easy
|
| 26 |
+
name: "Easy: Detect Division by Zero"
|
| 27 |
+
difficulty: easy
|
| 28 |
+
|
| 29 |
+
- id: bug_detection_medium
|
| 30 |
+
name: "Medium: Memory Leak Detection"
|
| 31 |
+
difficulty: medium
|
| 32 |
+
|
| 33 |
+
- id: bug_detection_hard
|
| 34 |
+
name: "Hard: SQL Injection Vulnerability"
|
| 35 |
+
difficulty: hard
|
| 36 |
+
|
| 37 |
+
observation_space:
|
| 38 |
+
type: dict
|
| 39 |
+
description: |
|
| 40 |
+
Contains code diff, file context, and review status
|
| 41 |
+
|
| 42 |
+
action_space:
|
| 43 |
+
type: dict
|
| 44 |
+
description: |
|
| 45 |
+
Actions include adding comments, suggesting fixes, approving, or requesting changes
|
| 46 |
+
|
| 47 |
+
reward_range:
|
| 48 |
+
min: 0.0
|
| 49 |
+
max: 1.0
|
| 50 |
+
|
| 51 |
+
max_episode_steps: 50
|
| 52 |
+
|
| 53 |
+
requires_api_keys:
|
| 54 |
+
- API_KEY
|
| 55 |
+
- API_BASE_URL
|
| 56 |
+
- MODEL_NAME
|
requirements.txt
ADDED
|
File without changes
|