Spaces:
Runtime error
Runtime error
HemanthSai7
commited on
Commit
•
9b1f57f
1
Parent(s):
08fce87
Update
Browse files
TechdocsAPI/backend/__init__.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import mysql.connector
|
|
|
2 |
|
3 |
from fastapi import FastAPI, status
|
4 |
from fastapi.exceptions import HTTPException
|
@@ -7,10 +8,10 @@ from fastapi.templating import Jinja2Templates
|
|
7 |
from backend.utils import DBConnection
|
8 |
from backend.core.ConfigEnv import config
|
9 |
|
10 |
-
|
11 |
from langchain.chains import LLMChain
|
12 |
from langchain.prompts import PromptTemplate
|
13 |
-
|
14 |
|
15 |
app = FastAPI(
|
16 |
title="Techdocs",
|
@@ -30,12 +31,15 @@ try:
|
|
30 |
|
31 |
prompt = PromptTemplate(template=prompt, input_variables=["instruction"])
|
32 |
|
33 |
-
llm =
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
36 |
)
|
37 |
|
38 |
-
llmchain =
|
39 |
app.state.llmchain = llmchain
|
40 |
|
41 |
app.state.templates = Jinja2Templates(directory="./backend/templates")
|
|
|
1 |
import mysql.connector
|
2 |
+
from mysql.connector import errorcode
|
3 |
|
4 |
from fastapi import FastAPI, status
|
5 |
from fastapi.exceptions import HTTPException
|
|
|
8 |
from backend.utils import DBConnection
|
9 |
from backend.core.ConfigEnv import config
|
10 |
|
11 |
+
from langchain_community.llms import Clarifai
|
12 |
from langchain.chains import LLMChain
|
13 |
from langchain.prompts import PromptTemplate
|
14 |
+
|
15 |
|
16 |
app = FastAPI(
|
17 |
title="Techdocs",
|
|
|
31 |
|
32 |
prompt = PromptTemplate(template=prompt, input_variables=["instruction"])
|
33 |
|
34 |
+
llm = Clarifai(
|
35 |
+
pat=config.CLARIFAI_PAT,
|
36 |
+
user_id=config.USER_ID,
|
37 |
+
app_id=config.APP_ID,
|
38 |
+
model_id=config.MODEL_ID,
|
39 |
+
model_version_id=config.MODEL_VERSION_ID,
|
40 |
)
|
41 |
|
42 |
+
llmchain = prompt | llm
|
43 |
app.state.llmchain = llmchain
|
44 |
|
45 |
app.state.templates = Jinja2Templates(directory="./backend/templates")
|
TechdocsAPI/backend/core/ConfigEnv.py
CHANGED
@@ -14,7 +14,12 @@ class Settings(BaseSettings):
|
|
14 |
JWT_SECRET_KEY:str
|
15 |
JWT_REFRESH_SECRET_KEY:str
|
16 |
JWT_VERIFICATION_SECRET_KEY:str
|
17 |
-
GOOGLE_API_KEY:str
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
MAIL_SERVER_URL:str
|
20 |
MAIL_USERNAME:str
|
|
|
14 |
JWT_SECRET_KEY:str
|
15 |
JWT_REFRESH_SECRET_KEY:str
|
16 |
JWT_VERIFICATION_SECRET_KEY:str
|
17 |
+
# GOOGLE_API_KEY:str
|
18 |
+
APP_ID:str
|
19 |
+
USER_ID:str
|
20 |
+
MODEL_ID:str
|
21 |
+
CLARIFAI_PAT:str
|
22 |
+
MODEL_VERSION_ID:str
|
23 |
|
24 |
MAIL_SERVER_URL:str
|
25 |
MAIL_USERNAME:str
|
TechdocsAPI/backend/services/auth/ops.py
CHANGED
@@ -12,6 +12,9 @@ from fastapi import HTTPException, BackgroundTasks
|
|
12 |
from pydantic import ValidationError
|
13 |
from jose import jwt
|
14 |
|
|
|
|
|
|
|
15 |
async def ops_signup(bgtasks: BackgroundTasks, response_result: GeneralResponse, data: UserAuth):
|
16 |
"""Wrapper method to handle signup process.
|
17 |
|
@@ -30,7 +33,7 @@ async def ops_signup(bgtasks: BackgroundTasks, response_result: GeneralResponse,
|
|
30 |
# user with the entered credentials already exists
|
31 |
raise ExistingUserException(response_result)
|
32 |
verifiction_token = Auth.create_access_token(f"{data.username} {data.email}", secret_name='VERIFICATION')
|
33 |
-
verification_link = f"
|
34 |
|
35 |
email_body_params = {
|
36 |
"username": data.username,
|
@@ -109,8 +112,7 @@ def ops_regenerate_api_key(username:str) -> APIKey:
|
|
109 |
apikey = APIKey(api_key=apikey)
|
110 |
|
111 |
return apikey
|
112 |
-
|
113 |
-
|
114 |
|
115 |
def ops_inference(source_code:str,api_key:str,username:str):
|
116 |
response_result = GeneralResponse.get_instance(data={},
|
@@ -129,8 +131,9 @@ def ops_inference(source_code:str,api_key:str,username:str):
|
|
129 |
|
130 |
|
131 |
llm_response = app.state.llmchain.invoke({"instruction": source_code_message})
|
|
|
132 |
|
133 |
-
docstring = Inference(docstr=llm_response
|
134 |
|
135 |
return docstring
|
136 |
|
@@ -164,4 +167,3 @@ def ops_verify_email(request: Request, response_result: GeneralResponse, token:s
|
|
164 |
|
165 |
except (jwt.JWTError, ValidationError):
|
166 |
return app.state.templates.TemplateResponse("verification_failure.html", context={"request": request})
|
167 |
-
|
|
|
12 |
from pydantic import ValidationError
|
13 |
from jose import jwt
|
14 |
|
15 |
+
# BASE_URL = "http://127.0.0.1:8000"
|
16 |
+
BASE_URL = "https://caffeinecrew-techdocs.hf.space"
|
17 |
+
|
18 |
async def ops_signup(bgtasks: BackgroundTasks, response_result: GeneralResponse, data: UserAuth):
|
19 |
"""Wrapper method to handle signup process.
|
20 |
|
|
|
33 |
# user with the entered credentials already exists
|
34 |
raise ExistingUserException(response_result)
|
35 |
verifiction_token = Auth.create_access_token(f"{data.username} {data.email}", secret_name='VERIFICATION')
|
36 |
+
verification_link = f"{BASE_URL}/auth/verify/{verifiction_token}"
|
37 |
|
38 |
email_body_params = {
|
39 |
"username": data.username,
|
|
|
112 |
apikey = APIKey(api_key=apikey)
|
113 |
|
114 |
return apikey
|
115 |
+
|
|
|
116 |
|
117 |
def ops_inference(source_code:str,api_key:str,username:str):
|
118 |
response_result = GeneralResponse.get_instance(data={},
|
|
|
131 |
|
132 |
|
133 |
llm_response = app.state.llmchain.invoke({"instruction": source_code_message})
|
134 |
+
print(llm_response)
|
135 |
|
136 |
+
docstring = Inference(docstr=llm_response)
|
137 |
|
138 |
return docstring
|
139 |
|
|
|
167 |
|
168 |
except (jwt.JWTError, ValidationError):
|
169 |
return app.state.templates.TemplateResponse("verification_failure.html", context={"request": request})
|
|
TechdocsAPI/backend/utils/Gemini_Prompt.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
You are an expert Code Documentation writer. Your job is to document Python codebases. The Documentation should be in "Goolge Style Python Docstrings". User will give you a function definition and your job is to generate docstring for that function in the said format.
|
2 |
Now I will define a format which you will be following to generate the docstings. For each function definition, you will generate the following:
|
3 |
1. Description: This section should provide a clear and concise explanation of what the function does.
|
@@ -172,4 +173,5 @@ def token_validation(token: str) -> bool:
|
|
172 |
"""
|
173 |
|
174 |
Code
|
175 |
-
{instruction}
|
|
|
|
1 |
+
<|im_start|>user
|
2 |
You are an expert Code Documentation writer. Your job is to document Python codebases. The Documentation should be in "Goolge Style Python Docstrings". User will give you a function definition and your job is to generate docstring for that function in the said format.
|
3 |
Now I will define a format which you will be following to generate the docstings. For each function definition, you will generate the following:
|
4 |
1. Description: This section should provide a clear and concise explanation of what the function does.
|
|
|
173 |
"""
|
174 |
|
175 |
Code
|
176 |
+
{instruction} <|im_end|>
|
177 |
+
<|im_start|>assistant
|
TechdocsAPI/requirements.txt
CHANGED
@@ -5,8 +5,11 @@ pydantic==1.10.12
|
|
5 |
python-jose[cryptography]
|
6 |
passlib[bcrypt]
|
7 |
mysql-connector-python
|
8 |
-
|
|
|
9 |
pydantic[email]
|
10 |
langchain
|
|
|
11 |
Pillow
|
12 |
jinja2
|
|
|
|
5 |
python-jose[cryptography]
|
6 |
passlib[bcrypt]
|
7 |
mysql-connector-python
|
8 |
+
mysql
|
9 |
+
# langchain-google-genai
|
10 |
pydantic[email]
|
11 |
langchain
|
12 |
+
langchain-community
|
13 |
Pillow
|
14 |
jinja2
|
15 |
+
clarifai
|
scripts/test.py
CHANGED
@@ -1,18 +1,19 @@
|
|
1 |
from dotenv import load_dotenv
|
|
|
2 |
load_dotenv()
|
3 |
import os
|
4 |
|
5 |
import mysql.connector
|
6 |
from mysql.connector import errorcode
|
7 |
|
8 |
-
config={
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
}
|
14 |
|
15 |
-
print(
|
16 |
|
17 |
try:
|
18 |
cnx = mysql.connector.connect(**config)
|
@@ -29,8 +30,12 @@ else:
|
|
29 |
|
30 |
cursor.execute("DROP TABLE IF EXISTS api_key")
|
31 |
cursor.execute("DROP TABLE IF EXISTS auth")
|
32 |
-
cursor.execute(
|
33 |
-
|
|
|
|
|
|
|
|
|
34 |
cursor.execute("ALTER TABLE auth ADD is_verified BOOLEAN NOT NULL DEFAULT(false)")
|
35 |
|
36 |
# QUERY = ('INSERT INTO {coll_name} '
|
@@ -46,9 +51,6 @@ else:
|
|
46 |
# for i in cursor.fetchall():
|
47 |
# print(i)
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
cnx.commit()
|
53 |
cursor.close()
|
54 |
cnx.close()
|
|
|
1 |
from dotenv import load_dotenv
|
2 |
+
|
3 |
load_dotenv()
|
4 |
import os
|
5 |
|
6 |
import mysql.connector
|
7 |
from mysql.connector import errorcode
|
8 |
|
9 |
+
config = {
|
10 |
+
"host": os.environ.get("HOSTNAME"),
|
11 |
+
"user": os.environ.get("UID"),
|
12 |
+
"password": os.environ.get("PASSWORD"),
|
13 |
+
"database": os.environ.get("DATABASE"),
|
14 |
}
|
15 |
|
16 |
+
print(os.environ.get("HOSTNAME"))
|
17 |
|
18 |
try:
|
19 |
cnx = mysql.connector.connect(**config)
|
|
|
30 |
|
31 |
cursor.execute("DROP TABLE IF EXISTS api_key")
|
32 |
cursor.execute("DROP TABLE IF EXISTS auth")
|
33 |
+
cursor.execute(
|
34 |
+
"CREATE TABLE IF NOT EXISTS auth(username VARCHAR(15) PRIMARY KEY, password TEXT, email VARCHAR(50))"
|
35 |
+
)
|
36 |
+
cursor.execute(
|
37 |
+
"CREATE TABLE IF NOT EXISTS api_key(username VARCHAR(15),apikey TEXT, FOREIGN KEY (username) REFERENCES auth(username))"
|
38 |
+
)
|
39 |
cursor.execute("ALTER TABLE auth ADD is_verified BOOLEAN NOT NULL DEFAULT(false)")
|
40 |
|
41 |
# QUERY = ('INSERT INTO {coll_name} '
|
|
|
51 |
# for i in cursor.fetchall():
|
52 |
# print(i)
|
53 |
|
|
|
|
|
|
|
54 |
cnx.commit()
|
55 |
cursor.close()
|
56 |
cnx.close()
|