Commit
·
531ba0a
1
Parent(s):
3960366
Clean up code
Browse files- agent/agent_config/prompts.py +1 -4
- agent/core.py +2 -2
- tools/code_index.py +2 -50
- tools/github_tools.py +0 -3
- tools/utils.py +0 -6
agent/agent_config/prompts.py
CHANGED
@@ -29,7 +29,4 @@ system_message = {
|
|
29 |
"Do not attempt to use any other tools such as web_search."
|
30 |
"DO NOT HALLUCINATE OR MAKE UP TOOLS."
|
31 |
)
|
32 |
-
}
|
33 |
-
|
34 |
-
# "STRICTLY use the `retrieve_context` tool to get the relevant code snippets or metadata about the codebase to formulate your response.\n\n"
|
35 |
-
# "Stick to the context that your retri"
|
|
|
29 |
"Do not attempt to use any other tools such as web_search."
|
30 |
"DO NOT HALLUCINATE OR MAKE UP TOOLS."
|
31 |
)
|
32 |
+
}
|
|
|
|
|
|
agent/core.py
CHANGED
@@ -61,7 +61,7 @@ async def run_agent(issue_url: str, branch_name: str = "main") -> str:
|
|
61 |
issue_title = function_result.get("title")
|
62 |
issue_body = function_result.get("body")
|
63 |
issue_description_cache = issue_title + "\n" + issue_body if issue_title or issue_body else None
|
64 |
-
print("ISSUE DESCRIPTION CACHE
|
65 |
|
66 |
if function_name == "retrieve_context":
|
67 |
if "issue_description" in function_params:
|
@@ -69,7 +69,7 @@ async def run_agent(issue_url: str, branch_name: str = "main") -> str:
|
|
69 |
issue_description_cache
|
70 |
and (function_params["issue_description"] != issue_description_cache)
|
71 |
):
|
72 |
-
print("
|
73 |
function_params["issue_description"] = issue_description_cache
|
74 |
function_result = names_to_functions[function_name](**function_params)
|
75 |
|
|
|
61 |
issue_title = function_result.get("title")
|
62 |
issue_body = function_result.get("body")
|
63 |
issue_description_cache = issue_title + "\n" + issue_body if issue_title or issue_body else None
|
64 |
+
print("ISSUE DESCRIPTION CACHE:", issue_description_cache)
|
65 |
|
66 |
if function_name == "retrieve_context":
|
67 |
if "issue_description" in function_params:
|
|
|
69 |
issue_description_cache
|
70 |
and (function_params["issue_description"] != issue_description_cache)
|
71 |
):
|
72 |
+
print("Overriding incorrect issue_description with correct one from cache.")
|
73 |
function_params["issue_description"] = issue_description_cache
|
74 |
function_result = names_to_functions[function_name](**function_params)
|
75 |
|
tools/code_index.py
CHANGED
@@ -2,14 +2,12 @@ import asyncio
|
|
2 |
import numpy as np
|
3 |
import os
|
4 |
from sklearn.metrics.pairwise import cosine_similarity
|
5 |
-
import
|
6 |
-
from typing import List, Dict
|
7 |
from llama_index.core import VectorStoreIndex, Document, Settings, get_response_synthesizer
|
8 |
from llama_index.core.query_engine import RetrieverQueryEngine
|
9 |
from llama_index.core.postprocessor import SimilarityPostprocessor
|
10 |
from llama_index.embeddings.mistralai import MistralAIEmbedding
|
11 |
from llama_index.llms.mistralai import MistralAI
|
12 |
-
from mistralai import Mistral
|
13 |
from config import MISTRAL_API_KEY
|
14 |
from tools.utils import fetch_repo_files, fetch_file_content
|
15 |
|
@@ -61,25 +59,6 @@ def select_relevant_files_semantic(issue_description: str, file_paths: List[str]
|
|
61 |
|
62 |
return top_files
|
63 |
|
64 |
-
|
65 |
-
# print(select_relevant_files_semantic(
|
66 |
-
# '''
|
67 |
-
# 🛠️ Configuration Error: Placeholder values detected in host_config.json
|
68 |
-
# This file still includes default placeholders like:
|
69 |
-
|
70 |
-
# <evalai_user_auth_token>
|
71 |
-
# <host_team_pk>
|
72 |
-
# <evalai_host_url>
|
73 |
-
# Please replace them with real values to proceed.
|
74 |
-
# ''',
|
75 |
-
# ['.github/FUNDING.yml', '.github/workflows/process_challenge.yml', '.gitignore', 'README.md', 'annotations/test_annotations_devsplit.json', 'annotations/test_annotations_testsplit.json', 'challenge_config.yaml', 'challenge_data/__init__.py', 'challenge_data/challenge_1/__init__.py', 'challenge_data/challenge_1/main.py', 'evaluation_script/__init__.py', 'evaluation_script/main.py', 'github/challenge_processing_script.py', 'github/config.py', 'github/host_config.json', 'github/requirements.txt', 'github/utils.py', 'logo.jpg', 'remote_challenge_evaluation/README.md', 'remote_challenge_evaluation/eval_ai_interface.py', 'remote_challenge_evaluation/evaluate.py', 'remote_challenge_evaluation/main.py', 'remote_challenge_evaluation/requirements.txt', 'run.sh', 'submission.json', 'templates/challenge_phase_1_description.html', 'templates/challenge_phase_2_description.html', 'templates/description.html', 'templates/evaluation_details.html', 'templates/submission_guidelines.html', 'templates/terms_and_conditions.html', 'worker/__init__.py', 'worker/run.py']))
|
76 |
-
|
77 |
-
|
78 |
-
# Assuming these are async now or wrapped appropriately
|
79 |
-
# async def fetch_repo_files(...)
|
80 |
-
# async def fetch_file_content(...)
|
81 |
-
# async def VectorStoreIndex.from_documents(...)
|
82 |
-
|
83 |
async def async_retry_on_429(func, *args, max_retries=3, delay=1, **kwargs):
|
84 |
for attempt in range(max_retries):
|
85 |
try:
|
@@ -128,20 +107,7 @@ async def build_repo_index(owner: str, repo: str, ref: str = "main", issue_descr
|
|
128 |
return index
|
129 |
|
130 |
|
131 |
-
# print(build_repo_index("aditi-dsi", "EvalAI-Starters", "master",
|
132 |
-
# '''
|
133 |
-
# 🛠️ Configuration Error: Placeholder values detected in host_config.json
|
134 |
-
# This file still includes default placeholders like:
|
135 |
-
|
136 |
-
# <evalai_user_auth_token>
|
137 |
-
# <host_team_pk>
|
138 |
-
# <evalai_host_url>
|
139 |
-
# Please replace them with real values to proceed.
|
140 |
-
# '''))
|
141 |
-
|
142 |
-
|
143 |
async def retrieve_context(owner: str, repo: str, ref: str, issue_description: str) -> List[str]:
|
144 |
-
print("Issue Description:", issue_description)
|
145 |
index = await build_repo_index(owner, repo, ref, issue_description)
|
146 |
Settings.llm = MistralAI(model="codestral-latest", api_key=MISTRAL_API_KEY)
|
147 |
Settings.embed_model = MistralAIEmbedding(model_name="codestral-embed", api_key=MISTRAL_API_KEY)
|
@@ -165,21 +131,7 @@ async def retrieve_context(owner: str, repo: str, ref: str, issue_description: s
|
|
165 |
"- DO NOT include generic, loosely related, or unrelated content.\n"
|
166 |
)
|
167 |
|
168 |
-
print("Query:", query)
|
169 |
-
|
170 |
-
# If query_engine.query is sync, wrap it in a thread
|
171 |
response = await asyncio.to_thread(query_engine.query, query)
|
172 |
|
173 |
print(response)
|
174 |
-
return response
|
175 |
-
|
176 |
-
# print(retrieve_context("aditi-dsi", "EvalAI-Starters", "master",
|
177 |
-
# '''
|
178 |
-
# 🛠️ Configuration Error: Placeholder values detected in host_config.json
|
179 |
-
# This file still includes default placeholders like:
|
180 |
-
|
181 |
-
# <evalai_user_auth_token>
|
182 |
-
# <host_team_pk>
|
183 |
-
# <evalai_host_url>
|
184 |
-
# Please replace them with real values to proceed.
|
185 |
-
# '''))
|
|
|
2 |
import numpy as np
|
3 |
import os
|
4 |
from sklearn.metrics.pairwise import cosine_similarity
|
5 |
+
from typing import List
|
|
|
6 |
from llama_index.core import VectorStoreIndex, Document, Settings, get_response_synthesizer
|
7 |
from llama_index.core.query_engine import RetrieverQueryEngine
|
8 |
from llama_index.core.postprocessor import SimilarityPostprocessor
|
9 |
from llama_index.embeddings.mistralai import MistralAIEmbedding
|
10 |
from llama_index.llms.mistralai import MistralAI
|
|
|
11 |
from config import MISTRAL_API_KEY
|
12 |
from tools.utils import fetch_repo_files, fetch_file_content
|
13 |
|
|
|
59 |
|
60 |
return top_files
|
61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
async def async_retry_on_429(func, *args, max_retries=3, delay=1, **kwargs):
|
63 |
for attempt in range(max_retries):
|
64 |
try:
|
|
|
107 |
return index
|
108 |
|
109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
async def retrieve_context(owner: str, repo: str, ref: str, issue_description: str) -> List[str]:
|
|
|
111 |
index = await build_repo_index(owner, repo, ref, issue_description)
|
112 |
Settings.llm = MistralAI(model="codestral-latest", api_key=MISTRAL_API_KEY)
|
113 |
Settings.embed_model = MistralAIEmbedding(model_name="codestral-embed", api_key=MISTRAL_API_KEY)
|
|
|
131 |
"- DO NOT include generic, loosely related, or unrelated content.\n"
|
132 |
)
|
133 |
|
|
|
|
|
|
|
134 |
response = await asyncio.to_thread(query_engine.query, query)
|
135 |
|
136 |
print(response)
|
137 |
+
return response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tools/github_tools.py
CHANGED
@@ -27,7 +27,6 @@ def get_issue_details(owner, repo, issue_num):
|
|
27 |
else:
|
28 |
raise Exception(f"Failed to fetch issue: {response.status_code} {response.text}")
|
29 |
|
30 |
-
# print(get_issue_details("aditi-dsi", "testing-cryptope", "4"))
|
31 |
|
32 |
def post_comment(owner, repo, issue_num, comment_body):
|
33 |
installation_id = get_installation_id(owner, repo)
|
@@ -43,5 +42,3 @@ def post_comment(owner, repo, issue_num, comment_body):
|
|
43 |
return response.json()
|
44 |
else:
|
45 |
raise Exception(f"Failed to post comment: {response.status_code} {response.text}")
|
46 |
-
|
47 |
-
# print(post_comment("aditi-dsi", "testing-cryptope", "3", "This is a test comment from OpenSorus."))
|
|
|
27 |
else:
|
28 |
raise Exception(f"Failed to fetch issue: {response.status_code} {response.text}")
|
29 |
|
|
|
30 |
|
31 |
def post_comment(owner, repo, issue_num, comment_body):
|
32 |
installation_id = get_installation_id(owner, repo)
|
|
|
42 |
return response.json()
|
43 |
else:
|
44 |
raise Exception(f"Failed to post comment: {response.status_code} {response.text}")
|
|
|
|
tools/utils.py
CHANGED
@@ -70,8 +70,6 @@ def get_installation_id(owner, repo):
|
|
70 |
else:
|
71 |
raise Exception(f"Failed to get installation ID for {owner}/{repo}: {response.status_code} {response.text}")
|
72 |
|
73 |
-
# print(get_installation_id("aditi-dsi", "testing-cryptope"))
|
74 |
-
|
75 |
|
76 |
def get_installation_token(installation_id):
|
77 |
"""Return a valid installation token, fetch new if expired or missing."""
|
@@ -92,7 +90,6 @@ def get_installation_token(installation_id):
|
|
92 |
installation_tokens[installation_id] = {"token": token, "expires_at": expires_at}
|
93 |
return token
|
94 |
|
95 |
-
# print(get_installation_token(69452220))
|
96 |
|
97 |
async def fetch_repo_files(owner: str, repo: str, ref: str = "main") -> List[str]:
|
98 |
"""
|
@@ -115,7 +112,6 @@ async def fetch_repo_files(owner: str, repo: str, ref: str = "main") -> List[str
|
|
115 |
file_paths = [item["path"] for item in tree if item["type"] == "blob"]
|
116 |
return file_paths
|
117 |
|
118 |
-
# print(fetch_repo_files("aditi-dsi", "EvalAI-Starters", "master"))
|
119 |
|
120 |
async def fetch_file_content(owner: str, repo: str, path: str, ref: str = "main") -> str:
|
121 |
"""
|
@@ -137,5 +133,3 @@ async def fetch_file_content(owner: str, repo: str, path: str, ref: str = "main"
|
|
137 |
content_json = response.json()
|
138 |
content = base64.b64decode(content_json["content"]).decode("utf-8", errors="ignore")
|
139 |
return content
|
140 |
-
|
141 |
-
# print(fetch_file_content("aditi-dsi", "testing-cryptope", "frontend/src/lib/buildSwap.ts", "main"))
|
|
|
70 |
else:
|
71 |
raise Exception(f"Failed to get installation ID for {owner}/{repo}: {response.status_code} {response.text}")
|
72 |
|
|
|
|
|
73 |
|
74 |
def get_installation_token(installation_id):
|
75 |
"""Return a valid installation token, fetch new if expired or missing."""
|
|
|
90 |
installation_tokens[installation_id] = {"token": token, "expires_at": expires_at}
|
91 |
return token
|
92 |
|
|
|
93 |
|
94 |
async def fetch_repo_files(owner: str, repo: str, ref: str = "main") -> List[str]:
|
95 |
"""
|
|
|
112 |
file_paths = [item["path"] for item in tree if item["type"] == "blob"]
|
113 |
return file_paths
|
114 |
|
|
|
115 |
|
116 |
async def fetch_file_content(owner: str, repo: str, path: str, ref: str = "main") -> str:
|
117 |
"""
|
|
|
133 |
content_json = response.json()
|
134 |
content = base64.b64decode(content_json["content"]).decode("utf-8", errors="ignore")
|
135 |
return content
|
|
|
|