Spaces:
Runtime error
Runtime error
concurrent github requests
Browse files- api/main.py +18 -2
- test.py +36 -10
api/main.py
CHANGED
@@ -4,6 +4,7 @@ from pydantic import BaseModel
|
|
4 |
from dotenv import load_dotenv
|
5 |
|
6 |
from api.external_services import InitiazlizeGithubService, InitiazlizeActiveloopService
|
|
|
7 |
|
8 |
# Load environment variables
|
9 |
load_dotenv()
|
@@ -22,6 +23,15 @@ class UserCodeRequest(BaseModel):
|
|
22 |
userCode: str
|
23 |
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
@app.post("/upload")
|
26 |
async def scrape_and_upload_to_activeloop(repo_request: GitHubRepoRequest):
|
27 |
# Add logic to scrape and upload to ActiveLoop
|
@@ -32,10 +42,16 @@ async def scrape_and_upload_to_activeloop(repo_request: GitHubRepoRequest):
|
|
32 |
|
33 |
owner, repo = github_service.parse_github_url(repo_request.githubRepoUrl)
|
34 |
file_types = [".py", ".js", ".ts", ".md", "ipynb"]
|
|
|
|
|
35 |
for file_type in file_types:
|
36 |
-
|
37 |
-
|
38 |
|
|
|
|
|
|
|
|
|
39 |
return {"status": "success", "message": "Repo processed successfully"}
|
40 |
|
41 |
|
|
|
4 |
from dotenv import load_dotenv
|
5 |
|
6 |
from api.external_services import InitiazlizeGithubService, InitiazlizeActiveloopService
|
7 |
+
import asyncio
|
8 |
|
9 |
# Load environment variables
|
10 |
load_dotenv()
|
|
|
23 |
userCode: str
|
24 |
|
25 |
|
26 |
+
async def process_file(owner, repo, file_type):
|
27 |
+
docs = github_service.load_repo_data(owner, repo, file_type)
|
28 |
+
activeloop_service.upload_to_activeloop(docs)
|
29 |
+
return {
|
30 |
+
"status": "success",
|
31 |
+
"message": f"File type {file_type} processed successfully",
|
32 |
+
}
|
33 |
+
|
34 |
+
|
35 |
@app.post("/upload")
|
36 |
async def scrape_and_upload_to_activeloop(repo_request: GitHubRepoRequest):
|
37 |
# Add logic to scrape and upload to ActiveLoop
|
|
|
42 |
|
43 |
owner, repo = github_service.parse_github_url(repo_request.githubRepoUrl)
|
44 |
file_types = [".py", ".js", ".ts", ".md", "ipynb"]
|
45 |
+
tasks = []
|
46 |
+
|
47 |
for file_type in file_types:
|
48 |
+
task = process_file(owner, repo, file_type)
|
49 |
+
tasks.append(task)
|
50 |
|
51 |
+
results = await asyncio.gather(*tasks)
|
52 |
+
# docs = github_service.load_repo_data(owner, repo, file_type)
|
53 |
+
# activeloop_service.upload_to_activeloop(docs)
|
54 |
+
print(results)
|
55 |
return {"status": "success", "message": "Repo processed successfully"}
|
56 |
|
57 |
|
test.py
CHANGED
@@ -2,7 +2,7 @@ import textwrap
|
|
2 |
from fastapi import FastAPI
|
3 |
from pydantic import BaseModel
|
4 |
from dotenv import load_dotenv
|
5 |
-
|
6 |
from api.external_services import InitiazlizeGithubService, InitiazlizeActiveloopService
|
7 |
|
8 |
# Load environment variables
|
@@ -11,14 +11,40 @@ load_dotenv()
|
|
11 |
github_service = InitiazlizeGithubService()
|
12 |
activeloop_service = InitiazlizeActiveloopService()
|
13 |
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
|
21 |
-
# retrieve
|
22 |
-
intro_question = "what this code is talking about?"
|
23 |
-
answer = activeloop_service.query_engine.query(intro_question)
|
24 |
-
print(answer.__dict__)
|
|
|
2 |
from fastapi import FastAPI
|
3 |
from pydantic import BaseModel
|
4 |
from dotenv import load_dotenv
|
5 |
+
import asyncio
|
6 |
from api.external_services import InitiazlizeGithubService, InitiazlizeActiveloopService
|
7 |
|
8 |
# Load environment variables
|
|
|
11 |
github_service = InitiazlizeGithubService()
|
12 |
activeloop_service = InitiazlizeActiveloopService()
|
13 |
|
14 |
+
|
15 |
+
async def process_file(owner, repo, file_type):
|
16 |
+
docs1 = github_service.load_repo_data(owner, repo, file_type)
|
17 |
+
return docs1
|
18 |
+
|
19 |
+
|
20 |
+
async def main():
|
21 |
+
repo_url = "https://github.com/facebookresearch/segment-anything"
|
22 |
+
|
23 |
+
owner, repo = github_service.parse_github_url(repo_url)
|
24 |
+
file_types = [".py", ".js", ".ts", ".md", "ipynb"]
|
25 |
+
tasks = []
|
26 |
+
for file_type in file_types:
|
27 |
+
task = process_file(owner, repo, file_type)
|
28 |
+
tasks.append(task)
|
29 |
+
|
30 |
+
results = await asyncio.gather(*tasks)
|
31 |
+
# docs = github_service.load_repo_data(owner, repo, file_type)
|
32 |
+
# activeloop_service.upload_to_activeloop(docs)
|
33 |
+
print(results)
|
34 |
+
a = 1
|
35 |
+
# activeloop_service.upload_to_activeloop(docs1)
|
36 |
+
|
37 |
+
|
38 |
+
if __name__ == "__main__":
|
39 |
+
asyncio.run(main())
|
40 |
+
|
41 |
+
# # upload
|
42 |
+
# owner, repo = github_service.parse_github_url(repo_url)
|
43 |
+
# docs = github_service.load_repo_data(owner, repo)
|
44 |
+
# activeloop_service.upload_to_activeloop(docs)
|
45 |
|
46 |
|
47 |
+
# # retrieve
|
48 |
+
# intro_question = "what this code is talking about?"
|
49 |
+
# answer = activeloop_service.query_engine.query(intro_question)
|
50 |
+
# print(answer.__dict__)
|