Skip to content

Commit

Permalink
gitattributes rebase for .mp4 filesw to allow spaces to sync with git…
Browse files Browse the repository at this point in the history
…hub. (rerooted branch) (#48)
  • Loading branch information
mayureshagashe2105 authored Nov 5, 2023
1 parent 7b80f1b commit f027f2c
Show file tree
Hide file tree
Showing 15 changed files with 91 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ build
dist
techdocs.egg-info

test.py
test.py
temp.py
20 changes: 1 addition & 19 deletions TechdocsAPI/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@

from langchain.llms import Clarifai
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
from langchain.prompts import PromptTemplate

from fastapi_mail import ConnectionConfig, FastMail

app = FastAPI(title="Techdocs",
version="V0.0.1",
Expand Down Expand Up @@ -46,23 +45,6 @@
app.state.llmchain = llmchain


conf = ConnectionConfig(
MAIL_USERNAME=config.MAIL_USERNAME,
MAIL_PASSWORD=config.MAIL_PASSWORD,
MAIL_FROM=config.MAIL_FROM,
MAIL_PORT=587,
MAIL_SERVER="smtp.gmail.com",
MAIL_STARTTLS=True,
MAIL_SSL_TLS=False,
TEMPLATE_FOLDER="backend/templates",
USE_CREDENTIALS = True,
VALIDATE_CERTS = True

# MAIL_TLS=True,
# MAIL_SSL=False
)

app.state.mail_client = FastMail(conf)
app.state.templates = Jinja2Templates(directory="./backend/templates")


Expand Down
2 changes: 2 additions & 0 deletions TechdocsAPI/backend/core/ConfigEnv.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Settings(BaseSettings):
CLARIFAI_PAT:str
MODEL_VERSION_ID:str

MAIL_SERVER_URL:str

MAIL_USERNAME:str
MAIL_PASSWORD:str
MAIL_FROM:str
Expand Down
6 changes: 6 additions & 0 deletions TechdocsAPI/backend/core/ExceptionHandlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ async def email_not_verified(request: Request, exec: EmailNotVerifiedException):
content=repr(exec)
)

@app.exception_handler(EmailNotSentException)
async def email_not_sent(request: Request, exec: EmailNotSentException):
return JSONResponse(status_code=status.HTTP_403_FORBIDDEN,
content=repr(exec)
)

@app.exception_handler(InvalidCredentialsException)
async def handle_login_failed(request: Request, exec: InvalidCredentialsException):
return JSONResponse(status_code=status.HTTP_403_FORBIDDEN,
Expand Down
13 changes: 12 additions & 1 deletion TechdocsAPI/backend/core/Exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def set_statuses(self):

def __repr__(self):
return "exception.InfoNotFoundException()"


class EmailNotVerifiedException(Exception):
def __init__(self):
Expand All @@ -55,3 +54,15 @@ def set_statuses(self):

def __repr__(self):
return "exception.EmailNotVerifiedException()"


class EmailNotSentException(Exception):
def __init__(self):
self.set_statuses()
super(EmailNotSentException, self).__init__()

def set_statuses(self):
self.status = 'EmailNotSentException'

def __repr__(self):
return "exception.EmailNotSentException()"
1 change: 0 additions & 1 deletion TechdocsAPI/backend/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ async def inference(generate: Generate, access_token:str=Depends(JWTBearer())):

return ops_inference(generate.code_block,generate.api_key,user_sub)


@app.get("/auth/verify/{token}", summary="Verify Email", response_model=GeneralResponse, tags=["Auth Server"])
async def verify_email(request: Request, token:str):
response_result = GeneralResponse.get_instance(data={},
Expand Down
3 changes: 2 additions & 1 deletion TechdocsAPI/backend/services/auth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .ops import *
from .utils.JWTBearer import *
from .utils.JWTBearer import *
from .utils.functools import *
29 changes: 14 additions & 15 deletions TechdocsAPI/backend/services/auth/ops.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .utils.auth_funcs import *
from .utils.functools import *
from .utils.JWTBearer import *
from backend.models import *
from backend.services.db.utils.DBQueries import DBQueries
Expand All @@ -11,11 +12,6 @@
from pydantic import ValidationError
from jose import jwt

from fastapi_mail import MessageSchema, MessageType

# import openai
# from transformers import RobertaTokenizer, T5ForConditionalGeneration

async def ops_signup(bgtasks: BackgroundTasks, response_result: GeneralResponse, data: UserAuth):
"""Wrapper method to handle signup process.
Expand All @@ -34,22 +30,25 @@ async def ops_signup(bgtasks: BackgroundTasks, response_result: GeneralResponse,
# user with the entered credentials already exists
raise ExistingUserException(response_result)
verifiction_token = Auth.create_access_token(f"{data.username} {data.email}", secret_name='VERIFICATION')
verification_link = f"http://localhost:8000/auth/verify/{verifiction_token}"
verification_link = f"https://caffeinecrew-techdocs.hf.space/auth/verify/{verifiction_token}"

email_body_params = {
"username": data.username,
"verify_link": verification_link
}

message = MessageSchema(
subject="Welcome to Techdocs:[Account Verification]",
recipients=[data.email], # List of recipients, as many as you can pass
template_body=email_body_params,
subtype=MessageType.html
)
details = {
"recipients": [data.email],
"subject": "Welcome to Techdocs:[Account Verification]",
"template_name": "email_verification.html",
"template_kwargs": email_body_params
}

status = post_request(url=config.MAIL_SERVER_URL, data=details, headers=None)
if status != 200:
raise EmailNotSentException()


bgtasks.add_task(app.state.mail_client.send_message, message=message, template_name="email_verification.html")
# await app.state.mail_client.send_message(message=message, template_name="email_verification.html")

DBQueries.insert_to_database('auth', (data.username, Auth.get_password_hash(data.password), "", 0),
['username', 'password', 'email', 'is_verified'])
Expand Down Expand Up @@ -143,6 +142,7 @@ def ops_verify_email(request: Request, response_result: GeneralResponse, token:s
payload = jwt.decode(
token, config.JWT_VERIFICATION_SECRET_KEY, algorithms=[config.ALGORITHM]
)

token_data = TokenPayload(**payload)
if datetime.fromtimestamp(token_data.exp)< datetime.now():
return app.state.templates.TemplateResponse("verification_failure.html", context={"request": request})
Expand All @@ -155,7 +155,6 @@ def ops_verify_email(request: Request, response_result: GeneralResponse, token:s
print(registered_email[0][0])
if registered_email[0][0]:
return app.state.templates.TemplateResponse("verification_failure.html", context={"request": request})


DBQueries.update_data_in_database('auth','is_verified',f"username='{username}'", (True,))
DBQueries.update_data_in_database('auth','email',f"username='{username}'", email)
Expand Down
9 changes: 9 additions & 0 deletions TechdocsAPI/backend/services/auth/utils/functools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import requests
from typing import Any, Dict
import json

def post_request(url: str, data: Dict[str, Any], headers: Dict[str, str]=None):
json_data = json.dumps(data)
headers = {'Content-type': 'application/json', 'Accept': 'application/json'}
response = requests.post(url, data=json_data, headers=headers)
return response.status_code
2 changes: 1 addition & 1 deletion TechdocsAPI/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ pydantic[email]
langchain
clarifai
Pillow
fastapi_mail==1.3.1
jinja2
8 changes: 8 additions & 0 deletions techdocs/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@ build-backend = "setuptools.build_meta"

[project]
name = "techdocs"
<<<<<<< HEAD
version = "0.2.0"
=======
version = "0.2.1"
>>>>>>> 7b80f1bcac446d89a72c4146689db74f434ec4c6
description = "Code documentation generation CLI App"
readme = "README.md"
requires-python = ">=3.10"
authors = [
<<<<<<< HEAD
{"name" = "test", "email" = "[email protected]"},
=======
{"name" = "Caffiene Crew", "email" = "[email protected]"},
>>>>>>> 7b80f1bcac446d89a72c4146689db74f434ec4c6
]
dependencies = [
"requests",
Expand Down
4 changes: 4 additions & 0 deletions techdocs/setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
[metadata]
name = techdocs
<<<<<<< HEAD:techdocs/setup.cfg
version = 0.2.0
=======
version = 0.2.1
>>>>>>> 7b80f1bcac446d89a72c4146689db74f434ec4c6:setup.cfg

[options]
packages = techdocs
Expand Down
4 changes: 4 additions & 0 deletions techdocs/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

setup(
name='techdocs',
<<<<<<< HEAD:techdocs/setup.py
version='0.2.0',
=======
version='0.2.1',
>>>>>>> 7b80f1bcac446d89a72c4146689db74f434ec4c6:setup.py
# To provide executable scripts, use entry points in preference to the
# "scripts" keyword. Entry points provide cross-platform support and allow
# pip to create the appropriate form of executable for the target platform.
Expand Down
6 changes: 5 additions & 1 deletion techdocs/techdocs/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
__version__ = "0.2.1"
<<<<<<< HEAD
__version__ = "0.2.0"
=======
__version__ = "0.2.1"
>>>>>>> 7b80f1bcac446d89a72c4146689db74f434ec4c6
21 changes: 21 additions & 0 deletions techdocs/techdocs/utils/functools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
# BASE_URL = "http://127.0.0.1:8000"


<<<<<<< HEAD

=======
>>>>>>> 7b80f1bcac446d89a72c4146689db74f434ec4c6
def get_access_token(data, return_refresh_token=False):
try:
url = BASE_URL + "/auth/login"
Expand All @@ -19,13 +23,22 @@ def get_access_token(data, return_refresh_token=False):
return access_token, refresh_token
return access_token
except Exception as e:
<<<<<<< HEAD
print("Invlaid Credentials")
return None




=======
if response.json() == "exception.InvalidCredentialsException()":
print("Please check your credentials")
else:
print("Please verify your email before logging in")
return None


>>>>>>> 7b80f1bcac446d89a72c4146689db74f434ec4c6
def request_inference(config, code_block, max_retries=1):

if max_retries == 0:
Expand Down Expand Up @@ -53,6 +66,10 @@ def update_file(file_path, docstr_code):
file.write(docstr_code)


<<<<<<< HEAD

=======
>>>>>>> 7b80f1bcac446d89a72c4146689db74f434ec4c6
def issue_api_key(config):
try:
headers={"accept":"application/json", "Authorization": f"Bearer {config['access_token']}"}
Expand All @@ -75,7 +92,11 @@ def signup(config):
elif (response.status_code!=200):
raise Exception("Something went wrong, please try again later")

<<<<<<< HEAD
print("Signed up successfully, please issue a new `API_KEY` to continue")
=======
print(response.json()["message"][0].replace('\\n','\n'), "Then issue a new `API_KEY` to continue")
>>>>>>> 7b80f1bcac446d89a72c4146689db74f434ec4c6

except Exception as e:
print(e)

0 comments on commit f027f2c

Please sign in to comment.