-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgh_search.py
67 lines (51 loc) · 3.53 KB
/
gh_search.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from transformers import AutoTokenizer, AutoModel
import torch
from pycozo.client import Client
import numpy as np
from sklearn.manifold import TSNE
tokenizer = AutoTokenizer.from_pretrained('sentence-transformers/all-MiniLM-L6-v2')
model = AutoModel.from_pretrained('sentence-transformers/all-MiniLM-L6-v2')
def embedding(text):
inputs = tokenizer(text, return_tensors='pt', truncation=True, max_length=384)
with torch.no_grad():
vectors = model(**inputs)
# print(len(vectors.last_hidden_state.mean(dim=1).view(-1).numpy().tolist()))
return list(vectors.last_hidden_state.mean(dim=1).view(-1).numpy())
new_code = {
"code": "@@ -67,6 +67,8 @@ export const handleDocumentAnalyze = async (\n const verifiedResponse = verifyResponseOfSubmit(response);\n if (!verifiedResponse || !verifiedResponse.results) {\n if (!suppressRateLimitErrors) {\n+ vscode.window.showErrorMessage(CONSTANTS.analyzeCommandTimeoutMessage);\n+ }\n getExtensionEventEmitter().fire({\n type: 'Analysis_Error',\n data: '',\n@@ -77,8 +79,6 @@ export const handleDocumentAnalyze = async (\n name: currentWorkSpaceFolder,\n },\n });\n- vscode.window.showErrorMessage(CONSTANTS.analyzeCommandTimeoutMessage);\n- }\n\n return failedResponseReturn;\n } else if (verifiedResponse.status === 'failed') {\n@@ -121,7 +121,20 @@ export const handleDocumentAnalyze = async (\n\n // convert problem paths to absolute path and normalize them\n const workspaceFolderPath = vscode.workspace.workspaceFolders?.[0].uri.fsPath;\n- if (!workspaceFolderPath) {return failedResponseReturn;}\n+ if (!workspaceFolderPath) {\n+ getExtensionEventEmitter().fire({\n+ type: 'Analysis_Error',\n+ data: '',\n+ });\n+ getExtensionEventEmitter().fire({\n+ type: 'CURRENT_PROJECT',\n+ data: {\n+ name: currentWorkSpaceFolder,\n+ },\n+ });\n+\n+ return failedResponseReturn;\n+ }\n verifiedResponse.results.forEach(result => {\n result.path = path.join(workspaceFolderPath, result.path);\n });",
"repo": "MetabobProject/metabob-vscode",
"commit_id": "f2fc157",
"file": "ext-src/helpers/HandleDocumentAnalyze.ts",
"commit_message": "fix analyze button remains disabled when analyze fails",
"explanation": "Description: Fixes the issue where the analyze button remained disabled after a failed analysis.\nReason: To ensure that the analyze button is re-enabled and the user is notified of the analysis failure.\nChanges: Added error message notifications and event triggers to handle analysis errors and re-enable the analyze button.\nImpact: Improves the user experience by providing feedback on analysis failures and allowing users to re-trigger the analysis process."
}
client = Client('sqlite', 'explanations.db')
# insert new code
script = """
?[code, code_embedding, commit_message, llm_explanation] <- $new_code
:insert gh_explanations
"""
try:
res = client.run(script, {'new_code': new_code})
except Exception as e:
print(f"An error occurred: {e}")
script = """
?[code, code_embedding, commit_message, llm_explanation] := *gh_explanations[code, code_embedding, commit_message, llm_explanation]
"""
try:
res = client.run(script)
except Exception as e:
print(f"An error occurred: {e}")
print(res)
script = '''
?[dist, code] :=
~gh_explanations:index{code | query: v, bind_distance: dist, k: 10, ef: 50}, v = vec($embedding)
:order dist
:limit 4
'''
try:
res = client.run(script, {'embedding': str(embedding(new_code['code']))})
except Exception as e:
print(f"An error occurred: {e}")
print(res)
client.close()