Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def get_repo(category: str = ""):
repo_id = None
for _ in range(2):
try:
repo_id = gorse_client.get_recommend(current_user.login, category)[0]
repo_id = gorse_client.get_recommend(current_user.login, category)[0].id
break
except UnknownObjectException:
logging.warn("repo %s not found" % repo_id)
Expand Down Expand Up @@ -624,8 +624,22 @@ def get_neighbors_v2(repo_name: str):
try:
n = int(request.args.get("n", default="3"))
offset = int(request.args.get("offset", default="0"))
description = request.args.get("description", default="")
scores = gorse_client.get_neighbors(repo_name.lower(), n, offset)
if not current_user.is_authenticated:
if len(scores) == 0:
try:
gorse_client.get_item(repo_name)
except gorse.GorseException as e:
if e.status_code != 404:
raise
items = []
if description:
items = gorse_client.search_items(description, n + offset)
scores = [
{"Id": item["ItemId"], "Score": 0}
for item in items[offset : offset + n]
]
response = Response(
json.dumps({"is_authenticated": False, "scores": scores}),
mimetype="application/json",
Expand All @@ -641,6 +655,15 @@ def get_neighbors_v2(repo_name: str):
except gorse.GorseException as e:
if e.status_code == 404:
upsert.delay(current_user.token["access_token"], repo_name.replace(":", "/"))
items = []
if description:
items = gorse_client.search_items(description, n + offset)
scores = [
{"Id": item["ItemId"], "Score": 0}
for item in items[offset : offset + n]
]
else:
raise

github_client = Github(current_user.token["access_token"])
response = Response(
Expand Down Expand Up @@ -670,9 +693,15 @@ def extension_recommend_v2():
mimetype="application/json",
)
try:
recommended_items = gorse_client.get_recommend(
current_user.login, n=3, write_back_type="read", write_back_delay="24h"
)
recommended_items = [
score.id
for score in gorse_client.get_recommend(
current_user.login,
n=3,
write_back_type="read",
write_back_delay="24h",
)
]
github_client = Github(current_user.token["access_token"])
return Response(
json.dumps(
Expand Down Expand Up @@ -712,7 +741,9 @@ def extension_recommend_latency(user_id: str):
# If the user is in Gorse.
gorse_client.get_user(user_id)
try:
repo_names = gorse_client.get_recommend(user_id, n=3)
repo_names = [
score.id for score in gorse_client.get_recommend(user_id, n=3)
]
return Response(
json.dumps({"has_login": True, "recommend": repo_names}),
mimetype="application/json",
Expand Down
5 changes: 5 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ positive_feedback_ttl = 0
# The time-to-live (days) of items, 0 means disabled. The default value is 0.
item_ttl = 0

[recommend.search]

# Item fields to index for search. Values use expr syntax.
columns = ["item.ItemId", "item.Comment"]

[[recommend.non-personalized]]

# The name of the leaderboard.
Expand Down
6 changes: 5 additions & 1 deletion extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ chrome.runtime.onMessage.addListener(
sendResponse(r);
})
} else if (request.neighbors) {
fetch(`https://gitrec.gorse.io/api/v2/neighbors/${request.neighbors}?offset=${request.offset}&n=6`, {
const params = new URLSearchParams({ offset: request.offset, n: 6 });
if (request.description) {
params.set('description', request.description);
}
fetch(`https://gitrec.gorse.io/api/v2/neighbors/${request.neighbors}?${params}`, {
credentials: 'include'
}).then(r => r.json()).then(r => {
sendResponse(r);
Expand Down
3 changes: 2 additions & 1 deletion extension/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ $(document).ready(function () {
})

function loadSimilarRepos() {
chrome.runtime.sendMessage({ neighbors: itemId, offset: similarOffset }, function (result) {
const description = $(".BorderGrid-cell p.f4.my-3").first().text().trim();
chrome.runtime.sendMessage({ neighbors: itemId, offset: similarOffset, description: description }, function (result) {
if (result.is_authenticated) {
renderSimilarDiv(result);
} else {
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ openai~=1.77.0
pickledb==1.3.2
protobuf==6.33.1
PyGithub==1.55
PyGorse==0.4.10
PyGorse==0.5.1
python-dateutil==2.8.1
python-dotenv==1.2.2
pytz==2022.1
Expand Down
Loading