Mayuresh Agashe commited on
Commit
db88ae6
·
1 Parent(s): 615173e

cmd tool dev (#10)

Browse files

* Update init

* Update router

* Update router

* Update router

* Update router

* Update router

* Update router

* Update router.py

* Update router

* Update vercel.json

* Update vercel.json

* Update router

* Modify AST nodes inplace and write to file

TechdocsAPI/backend/router.py CHANGED
@@ -17,6 +17,7 @@ app.add_middleware(
17
 
18
  @app.get("/api/response_check", tags=["Resource Server"])
19
  def api_response_check():
 
20
  response_result = GeneralResponse.get_instance(data={},
21
  status="not_allowed",
22
  message=["Not authenticated"]
@@ -38,6 +39,7 @@ def api_response_check():
38
 
39
  @app.post("/auth/signup", summary="Creates new user account", response_model=GeneralResponse, tags=["Auth Server"])
40
  async def signup(response: UserAuth):
 
41
  response_result = GeneralResponse.get_instance(data={},
42
  status="not_allowed",
43
  message=["Not authenticated"]
@@ -48,16 +50,19 @@ async def signup(response: UserAuth):
48
 
49
  @app.post("/auth/login", summary="Logs in user", response_model=TokenSchema, tags=["Auth Server"])
50
  async def login(response:LoginCreds):
 
51
  return ops_login(response)
52
 
53
  @app.put("/auth/regenerate_api_key",summary="Forget Password",response_model=APIKey,tags=["Auth Server"],dependencies=[Depends(JWTBearer())])
54
  async def regenerate_api_key(access_token: str = Depends(JWTBearer())):
 
55
  user_sub=Auth.get_user_credentials(access_token)
56
 
57
  return ops_regenerate_api_key(user_sub)
58
 
59
  @app.post("/api/inference", summary="Inference", response_model=Inference, tags=["Resource Server"], dependencies=[Depends(JWTBearer())])
60
  async def inference(code_block:str, api_key: str,access_token:str=Depends(JWTBearer())):
 
61
  user_sub=Auth.get_user_credentials(access_token)
62
 
63
  return ops_inference(code_block,api_key,user_sub)
 
17
 
18
  @app.get("/api/response_check", tags=["Resource Server"])
19
  def api_response_check():
20
+ print("api_response_check")
21
  response_result = GeneralResponse.get_instance(data={},
22
  status="not_allowed",
23
  message=["Not authenticated"]
 
39
 
40
  @app.post("/auth/signup", summary="Creates new user account", response_model=GeneralResponse, tags=["Auth Server"])
41
  async def signup(response: UserAuth):
42
+ print("signup")
43
  response_result = GeneralResponse.get_instance(data={},
44
  status="not_allowed",
45
  message=["Not authenticated"]
 
50
 
51
  @app.post("/auth/login", summary="Logs in user", response_model=TokenSchema, tags=["Auth Server"])
52
  async def login(response:LoginCreds):
53
+ print("login")
54
  return ops_login(response)
55
 
56
  @app.put("/auth/regenerate_api_key",summary="Forget Password",response_model=APIKey,tags=["Auth Server"],dependencies=[Depends(JWTBearer())])
57
  async def regenerate_api_key(access_token: str = Depends(JWTBearer())):
58
+ print("regenerate_api_key")
59
  user_sub=Auth.get_user_credentials(access_token)
60
 
61
  return ops_regenerate_api_key(user_sub)
62
 
63
  @app.post("/api/inference", summary="Inference", response_model=Inference, tags=["Resource Server"], dependencies=[Depends(JWTBearer())])
64
  async def inference(code_block:str, api_key: str,access_token:str=Depends(JWTBearer())):
65
+ print("inference")
66
  user_sub=Auth.get_user_credentials(access_token)
67
 
68
  return ops_inference(code_block,api_key,user_sub)
techdocs/utils/functools.py CHANGED
@@ -41,3 +41,8 @@ def request_inference(config, code_block, max_retries=1):
41
  config.update({"access_token":get_access_token(data)})
42
 
43
  return request_inference(config,config["access_token"], code_block, max_retries=max_retries-1)
 
 
 
 
 
 
41
  config.update({"access_token":get_access_token(data)})
42
 
43
  return request_inference(config,config["access_token"], code_block, max_retries=max_retries-1)
44
+
45
+
46
+
47
+
48
+
techdocs/utils/parse.py CHANGED
@@ -7,20 +7,18 @@ from utils.functools import *
7
 
8
 
9
  # Function to extract and print the outermost nested function with line number
10
- def extract_outermost_function(node, config, line_number=1,):
11
- base_url = "http://localhost:8000"
12
  if isinstance(node, ast.FunctionDef):
13
  function_def = ast.unparse(node)
14
- print(f"Function starting at line {line_number}:\n{function_def}")
15
- print("=" * 30)
16
-
17
- response = request_inference(config=config,code_block=function_def)
18
 
19
 
20
  for child in ast.iter_child_nodes(node):
21
- if isinstance(child, ast.FunctionDef):
22
- line_number = child.lineno
23
- extract_outermost_function(child, line_number)
24
 
25
  # Function to traverse directories recursively and extract functions from Python files
26
  def extract_functions_from_directory(config):
@@ -32,4 +30,7 @@ def extract_functions_from_directory(config):
32
  with open(file_path, "r",errors='ignore') as file:
33
  content = file.read()
34
  parsed = ast.parse(content)
35
- extract_outermost_function(parsed, config)
 
 
 
 
7
 
8
 
9
  # Function to extract and print the outermost nested function with line number
10
+ def extract_outermost_function(node, config):
11
+
12
  if isinstance(node, ast.FunctionDef):
13
  function_def = ast.unparse(node)
14
+ response = request_inference(config=config, code_block=function_def)
15
+ docstr = response['docstr']
16
+ docstring = ast.Expr(value=ast.Str(s=docstr))
17
+ node.body.insert(0, docstring)
18
 
19
 
20
  for child in ast.iter_child_nodes(node):
21
+ extract_outermost_function(child, config)
 
 
22
 
23
  # Function to traverse directories recursively and extract functions from Python files
24
  def extract_functions_from_directory(config):
 
30
  with open(file_path, "r",errors='ignore') as file:
31
  content = file.read()
32
  parsed = ast.parse(content)
33
+ extract_outermost_function(parsed, config)
34
+ docstr_code = ast.unparse(parsed)
35
+ with open(file_path, "w",errors='ignore') as file:
36
+ file.write(docstr_code)
testing/test.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ def add(a, b):
2
+ return a + b
3
+
4
+
5
+
6
+ def multiply(a, b):
7
+ return a * b
8
+
9
+ def subtract(a, b):
10
+ return a - b
11
+
12
+ def divide(a, b):
13
+ if b == 0:
14
+ raise ValueError("Cannot divide by zero")
15
+ return a / b
16
+
17
+
18
+ def func(*args, **kwargs):
19
+ def wrapper(*args, **kwargs):
20
+ return func(*args, **kwargs)
21
+ return wrapper