Skip to content

Commit

Permalink
chore: Improvements (#10)
Browse files Browse the repository at this point in the history
* feat: store env variables

* 1. fetch repos based on user query everytime
  • Loading branch information
Hk669 authored Jul 12, 2024
1 parent 620355f commit 68e4ef7
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 21 deletions.
23 changes: 19 additions & 4 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,8 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"dotenv": "^16.4.5"
}
}
17 changes: 10 additions & 7 deletions client/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,16 @@ function App() {
const token = localStorage.getItem("jwt_token");
if (token) {
try {
const response = await fetch(`http://127.0.0.1:8000/verify-token`, {
method: "GET",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
});
const response = await fetch(
`${process.env.REACT_APP_API_URL}/verify-token`,
{
method: "GET",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
},
}
);
if (response.ok) {
const data = await response.json();
setIsAuthenticated(true);
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Input/Input.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const Input = ({ onSubmit }) => {

try {
const response = await axios.post(
`http://127.0.0.1:8000/api/recommendations/`,
`${process.env.REACT_APP_API_URL}/api/recommendations/`,
{
username: username,
languages: languages,
Expand Down
8 changes: 5 additions & 3 deletions client/src/components/Login/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import React from "react";
import "./Login.css";
import { FaGithub } from "react-icons/fa";

const API_URL = process.env.REACT_APP_API_URL;

const Login = () => {
const handleLogin = () => {
window.location.href = `http://127.0.0.1:8000/github-login`;
window.location.href = `${API_URL}/github-login`;
};

return (
Expand Down Expand Up @@ -59,8 +61,8 @@ const Login = () => {
your skills and interests.
</li>
<li>
<strong>Exposure:</strong> Enables you to contribute to
the open-source community and make a difference.
<strong>Exposure:</strong> Enables you to contribute to the
open-source community and make a difference.
</li>
<li>
<strong>Secure, Fast, and Free to Use:</strong> Access all
Expand Down
14 changes: 9 additions & 5 deletions src/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import uvicorn
from .user_data import get_repos
from src.db import (recommend,
get_topic_based_recommendations,
get_chromadb_collection,
upsert_to_chroma_db)
get_topic_based_recommendations)
from src.models import User, GithubUser, get_user_collection

load_dotenv()
Expand Down Expand Up @@ -165,7 +163,7 @@ async def get_recommendations(request: Request, current_user: dict = Depends(get
body = await request.json()
extra_topics = body.get("extra_topics", [])
languages = body.get("languages", [])
username = body.get("username", current_user.get("username"))

urls = []
user = User(username=current_user["username"], access_token=current_user["access_token"],extra_topics=extra_topics, extra_languages=languages)

Expand All @@ -175,6 +173,13 @@ async def get_recommendations(request: Request, current_user: dict = Depends(get
logger.info("Generating topic-based recommendations")
return get_topic_based_recommendations(user)

try:
fetched_repos = await main(language_topics, access_token=user.access_token, extra_topics=extra_topics, extra_languages=languages)
logger.info(f"Fetched {len(fetched_repos)} repositories")
except Exception as e:
logger.error(f"Error fetching repositories: {str(e)}")
raise ValueError("Error fetching repositories")

try:
urls = recommend(user_details, language_topics)
except Exception as e:
Expand All @@ -184,7 +189,6 @@ async def get_recommendations(request: Request, current_user: dict = Depends(get

if urls and len(urls) < 10:
logger.info("Fewer than 10 recommendations found, fetching more repositories based on topics")
fetched_repos = await main(language_topics, access_token=user.access_token, extra_topics=extra_topics, extra_languages=languages)
urls = recommend(user_details, language_topics)

seen_full_names = set()
Expand Down
2 changes: 1 addition & 1 deletion src/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ async def main(language_topics,
results = await asyncio.gather(*tasks)
for result in results:
unique_repos.update(result)
print(f"Unique Repositories: {unique_repos}")
print(f"Unique Repositories: {len(unique_repos)}")

logger.info(f"Found {len(unique_repos)} unique repositories\n--------")

Expand Down

0 comments on commit 68e4ef7

Please sign in to comment.