33import os
44from .core .gimie_methods import extract_gimie
55from .core .models import convert_jsonld_to_pydantic , convert_pydantic_to_zod_form_dict
6- from .core .genai_model import llm_request_repo_infos
6+ from .core .genai_model import llm_request_repo_infos , llm_request_userorg_infos
7+ from .core .users_parser import parse_github_user
8+ from .core .orgs_parser import parse_github_organization
79from .utils .utils import merge_jsonld
810
11+ from pprint import pprint
912
1013
1114app = FastAPI ()
1215
1316@app .get ("/" )
1417def index ():
15- return {"title" : "Hello, welcome to the Git Metadata Extractor v0.1 .0. Gimie Version 0.7.2. " }
18+ return {"title" : f "Hello, welcome to the Git Metadata Extractor v0.2 .0. Gimie Version 0.7.2. LLM Model { os . environ [ 'MODEL' ] } " }
1619
1720@app .get ("/v1/extract/json/{full_path:path}" )
1821async def extract (full_path :str ):
1922
2023 jsonld_gimie_data = extract_gimie (full_path , format = "json-ld" )
2124
2225 try :
23- llm_result = llm_request_repo_infos (str (full_path ))
24- except Exception as e :
25- raise HTTPException (
26- status_code = 424 ,
27- detail = f"Error from LLM service: { e } "
28- )
26+ llm_result = await llm_request_repo_infos (str (full_path ), output_format = "json-ld" , max_tokens = 30000 )
27+ merged_results = merge_jsonld (jsonld_gimie_data , llm_result )
28+ pydantic_data = convert_jsonld_to_pydantic (merged_results ["@graph" ])
2929
30- merged_results = merge_jsonld ( jsonld_gimie_data , llm_result )
30+ except Exception as e :
3131
32- pydantic_data = convert_jsonld_to_pydantic (merged_results ["@graph" ])
32+ pydantic_data = convert_jsonld_to_pydantic (jsonld_gimie_data ["@graph" ])
33+ print (f"Warning: LLM service failed, using fallback data: { e } " )
3334
3435 zod_data = convert_pydantic_to_zod_form_dict (pydantic_data )
3536
3637 return {"link" : full_path ,
3738 "output" : zod_data }
3839
3940@app .get ("/v1/extract/json-ld/{full_path:path}" )
40- async def extract (full_path :str ):
41+ async def extract_jsonld (full_path :str ):
4142
4243 jsonld_gimie_data = extract_gimie (full_path , format = "json-ld" )
4344
4445 try :
45- llm_result = llm_request_repo_infos (str (full_path ))
46+ llm_result = await llm_request_repo_infos (str (full_path ), max_tokens = 20000 )
4647 except Exception as e :
4748 raise HTTPException (
4849 status_code = 424 ,
@@ -53,26 +54,82 @@ async def extract(full_path:str):
5354
5455 return {"link" : full_path ,
5556 "output" : merged_results }
57+
58+ @app .get ("/v1/org/llm/json/{full_path:path}" )
59+ async def get_org_json (full_path : str ):
60+
61+ try :
62+ org_metadata = parse_github_organization (full_path .split ("/" )[- 1 ])
63+
64+ parsed_org_metadata = await llm_request_userorg_infos (org_metadata , item_type = "org" )
65+
66+ org_metadata_dict = org_metadata .model_dump ()
67+ org_metadata_dict .update (parsed_org_metadata )
68+
69+ except Exception as e :
70+ raise HTTPException (
71+ status_code = 424 ,
72+ detail = f"Error from Organization JSON service: { e } "
73+ )
74+
75+ return {"link" : full_path ,
76+ "output" : org_metadata_dict }
77+
78+ @app .get ("/v1/user/llm/json/{full_path:path}" )
79+ async def get_user_json (full_path : str ):
80+
81+ try :
82+ user_metadata = parse_github_user (full_path .split ("/" )[- 1 ])
83+
84+ parsed_user_metadata = await llm_request_userorg_infos (user_metadata , item_type = "user" )
85+
86+ user_metadata_dict = user_metadata .model_dump ()
87+
88+ user_metadata_dict .update (parsed_user_metadata )
89+
90+ except Exception as e :
91+ raise HTTPException (
92+ status_code = 424 ,
93+ detail = f"Error from Get User service: { e } "
94+ )
95+
96+ return {"link" : full_path ,
97+ "output" : user_metadata_dict }
5698
57- @app .get ("/v1/gimie/{full_path:path}" )
58- async def gimie (full_path :str ,
59- format :str = "json-ld" ):
99+ @app .get ("/v1/repository/gimie/json-ld/{full_path:path}" )
100+ async def gimie (full_path :str ):
60101 try :
61- gimie_output = extract_gimie (full_path , format = format )
102+ gimie_output = extract_gimie (full_path , format = "json-ld" )
62103 except Exception as e :
63104 raise HTTPException (
64- status_code = 424 , #?
65- detail = f"Error from LLM service: { e } "
105+ status_code = 424 ,
106+ detail = f"Error from Gimie service: { e } "
66107 )
67108
68109 return {"link" : full_path ,
69110 "output" : gimie_output }
70111
71- @app .get ("/v1/llm/{full_path:path}" )
72- async def llm (full_path :str ):
112+ @app .get ("/v1/repository/llm/json-ld/{full_path:path}" )
113+ async def llm_jsonld (full_path :str ):
114+
115+ try :
116+ llm_result = await llm_request_repo_infos (str (full_path ), max_tokens = 20000 )
117+ except Exception as e :
118+ raise HTTPException (
119+ status_code = 424 ,
120+ detail = f"Error from LLM service: { e } "
121+ )
122+
123+ return {"link" : full_path ,
124+ "output" : llm_result }
125+
126+ @app .get ("/v1/repository/llm/json/{full_path:path}" )
127+ async def llm_json (full_path :str ):
128+
129+ jsonld_gimie_data = extract_gimie (full_path , format = "json-ld" )
73130
74131 try :
75- llm_result = llm_request_repo_infos (str (full_path ))
132+ llm_result = await llm_request_repo_infos (str (full_path ), gimie_output = jsonld_gimie_data , output_format = "json" , max_tokens = 20000 )
76133 except Exception as e :
77134 raise HTTPException (
78135 status_code = 424 ,
0 commit comments