Spaces:
Runtime error
Runtime error
Commit
·
c341d18
1
Parent(s):
21bfd6f
prompt update
Browse files
TechdocsAPI/backend/__init__.py
CHANGED
@@ -25,13 +25,13 @@ try:
|
|
25 |
test_conn = DBConnection.get_client().get_server_info()
|
26 |
|
27 |
# send prompt wizardcoderLM-70b-instruct-GGUF model
|
28 |
-
with open("backend/utils/
|
29 |
prompt = f.read()
|
30 |
|
31 |
prompt = PromptTemplate(template=prompt, input_variables=["instruction"])
|
32 |
|
33 |
llm = GoogleGenerativeAI(
|
34 |
-
model
|
35 |
google_api_key=config.GOOGLE_API_KEY,
|
36 |
)
|
37 |
|
|
|
25 |
test_conn = DBConnection.get_client().get_server_info()
|
26 |
|
27 |
# send prompt wizardcoderLM-70b-instruct-GGUF model
|
28 |
+
with open("backend/utils/Gemini_Prompt.txt", "r") as f:
|
29 |
prompt = f.read()
|
30 |
|
31 |
prompt = PromptTemplate(template=prompt, input_variables=["instruction"])
|
32 |
|
33 |
llm = GoogleGenerativeAI(
|
34 |
+
model="gemini-pro",
|
35 |
google_api_key=config.GOOGLE_API_KEY,
|
36 |
)
|
37 |
|
TechdocsAPI/backend/utils/Gemini_Prompt.txt
ADDED
@@ -0,0 +1,175 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.
|
4 |
+
2. Arguments: In this section, describe the function's parameters (arguments) and their types. Include both mandatory and optional arguments. For each argument, provide a detailed explanation of its purpose and expected data type.
|
5 |
+
3. Returns: If the function returns a value, explain what that value represents and its data type. If the function doesn't return anything (i.e., it has a None return type), mention that explicitly.
|
6 |
+
4. Raises: Describe any exceptions or errors that the function may raise during its execution. Specify the conditions under which these exceptions might occur.
|
7 |
+
However, you must generate the final docstrings in a specific format which you should be able to figure out by looking at the following examples.
|
8 |
+
|
9 |
+
Code
|
10 |
+
def insert_to_database(cls, db_name:str, coll_name:str, data:dict)->Union[InsertOneResult, InsertManyResult]:
|
11 |
+
con = DBConnection.get_client()
|
12 |
+
mydb = con[db_name]
|
13 |
+
mycol = mydb[coll_name]
|
14 |
+
|
15 |
+
if isinstance(data, list):
|
16 |
+
return mycol.insert_many(data)
|
17 |
+
else:
|
18 |
+
return mycol.insert_one(data)
|
19 |
+
|
20 |
+
"""insert a single record or iterable of records to the database.
|
21 |
+
|
22 |
+
Args:
|
23 |
+
db_name (str): name of the database
|
24 |
+
coll_name (str): name of the collection
|
25 |
+
data (dict): data to be inserted
|
26 |
+
|
27 |
+
Returns:
|
28 |
+
An instance of class: pymongo.results.InsertOneResult or
|
29 |
+
pymongo.results.InsertManyResult
|
30 |
+
"""
|
31 |
+
|
32 |
+
Code
|
33 |
+
def signup(response_result: FrontendResponseModel, data: Union[UserAuth,BulkSignup]):
|
34 |
+
if isinstance(data, UserAuth):
|
35 |
+
# querying database to check if user already exist
|
36 |
+
user = DBQueries.filtered_db_search("Auth", data.role, [], AADHAR=data.AADHAR_NO)
|
37 |
+
if len(list(user)) != 0:
|
38 |
+
# user with the entered credentials already exists
|
39 |
+
raise ExistingUserException(response_result)
|
40 |
+
|
41 |
+
DBQueries.insert_to_database("Auth", data.role, userinfo) # saving user to database
|
42 |
+
response_result['status'] = f'success'
|
43 |
+
response_result['message'] = [f'User with this AADHAR NO created successfully']
|
44 |
+
|
45 |
+
else:
|
46 |
+
AADHAR_NOS = data.AADHAR_NOS
|
47 |
+
passwords = data.passwords
|
48 |
+
village_name = data.village_name
|
49 |
+
|
50 |
+
users = DBQueries.filtered_db_search("Auth", role_manager.user, ["_id","password","village_name"], search_idxs="AADHAR":"$in":AADHAR_NOS)
|
51 |
+
users = [user["AADHAR"] for user in users]
|
52 |
+
|
53 |
+
invalid_users = []
|
54 |
+
valid_users = []
|
55 |
+
users_created = []
|
56 |
+
|
57 |
+
for user in zip(AADHAR_NOS,passwords):
|
58 |
+
if user[0] in users:
|
59 |
+
invalid_users.append(user[0])
|
60 |
+
else:
|
61 |
+
userinfo["AADHAR"] = user[0]
|
62 |
+
userinfo["password"] = Auth.get_password_hash(user[1])
|
63 |
+
valid_users.append(userinfo)
|
64 |
+
users_created.append(user[0])
|
65 |
+
|
66 |
+
if len(valid_users)!=0:
|
67 |
+
DBQueries.insert_to_database("Auth", role_manager.user, valid_users) # saving user to database
|
68 |
+
response_result['status'] = f'success'
|
69 |
+
response_result['message'] = [f'Users created successfully']
|
70 |
+
else:
|
71 |
+
response_result['status'] = f'failure'
|
72 |
+
response_result['message'] = [f'No users created']
|
73 |
+
|
74 |
+
"""Wrapper method to handle signup process.
|
75 |
+
|
76 |
+
Args:
|
77 |
+
response_result: FrontendResponseModel. A TypedDict to return the
|
78 |
+
response captured from the API to the frontend.
|
79 |
+
data: UserAuth. New user's prospective credentials from the frontend
|
80 |
+
to create their account.
|
81 |
+
|
82 |
+
Raises:
|
83 |
+
ExistingUserException: If account with entered AADHAR Number already exists.
|
84 |
+
"""
|
85 |
+
|
86 |
+
Code
|
87 |
+
def fetch_individualdata(response_result: dict, db_name: str, AADHAR_No: str)->Cursor[_DocumentType]:
|
88 |
+
exclude_fields = field_manager.get_form_fields(FormData, exclude=["fam_info"])
|
89 |
+
exclude_fields += ["_id","timestamp","volunteer_id"]
|
90 |
+
indivdata = [docs for docs in DBQueries.filtered_db_search(db_name,collection_names["fam_data"],exclude_fields,search_idxs="fam_info.AADHAR_No":AADHAR_No)]
|
91 |
+
if len(indivdata) == 0:
|
92 |
+
raise InfoNotFoundException(response_result, "person with this id does not exist in the database")
|
93 |
+
|
94 |
+
fam_members = [doc for doc in indivdata[0]["fam_info"] if doc["AADHAR_No"] == AADHAR_No]
|
95 |
+
|
96 |
+
return fam_members[0]
|
97 |
+
|
98 |
+
"""Wrapper function to fetch individual data from the database.
|
99 |
+
Args:
|
100 |
+
response_result (dict): response result to be returned in case of error.
|
101 |
+
db_name (str): name of the database.
|
102 |
+
AADHAR_No (str): id of the respondent.
|
103 |
+
|
104 |
+
Returns:
|
105 |
+
Cursor[_DocumentType]: A cursor containing the data of the individual
|
106 |
+
fetched from the database.
|
107 |
+
"""
|
108 |
+
|
109 |
+
Code
|
110 |
+
def user_login(tokens: TokenSchema, form_data: UserAuth):
|
111 |
+
user = DBQueries.filtered_db_search("Auth", form_data.role, ['_id'], AADHAR=form_data.AADHAR_NO)
|
112 |
+
data = list(user)
|
113 |
+
if len(data) == 0:
|
114 |
+
# no such users in the database
|
115 |
+
raise LoginFailedException(tokens)
|
116 |
+
|
117 |
+
if not Auth.verify_password(form_data.password, data[0]['password']) or \
|
118 |
+
not Auth.verify_village_name(data[0]['village_name'], form_data.village_name):
|
119 |
+
# incorrect credentials
|
120 |
+
raise LoginFailedException(tokens)
|
121 |
+
|
122 |
+
# successful login
|
123 |
+
sub = form_data.AADHAR_NO + "_" + form_data.role + "_" + form_data.village_name
|
124 |
+
tokens['access_token'] = Auth.create_access_token(sub)
|
125 |
+
tokens['refresh_token'] = Auth.create_refresh_token(sub)
|
126 |
+
tokens['status'] = 'login successful'
|
127 |
+
tokens['role'] = form_data.role
|
128 |
+
|
129 |
+
"""Wrapper method to handle sign-ins and generating `access_tokens`.
|
130 |
+
|
131 |
+
Args:
|
132 |
+
tokens: TokenSchema. A TypedDict to return `access_token`,
|
133 |
+
`refresh_access_tokens`, `status`, and `role`
|
134 |
+
related information to grant genuine users their
|
135 |
+
respective level of authorization according to
|
136 |
+
the maintained hierarchy.
|
137 |
+
form_data: UserAuth. Sign-in credentials entered by the users at the
|
138 |
+
time of signing in.
|
139 |
+
|
140 |
+
Raises:
|
141 |
+
LoginFailedException: If no user with entered credentials exists.
|
142 |
+
"""
|
143 |
+
|
144 |
+
Code
|
145 |
+
def token_validation(token: str) -> bool:
|
146 |
+
try:
|
147 |
+
payload = jwt.decode(
|
148 |
+
token, settings.JWT_SECRET_KEY, algorithms=[settings.ALGORITHM]
|
149 |
+
)
|
150 |
+
token_data = TokenPayload(**payload)
|
151 |
+
|
152 |
+
if datetime.fromtimestamp(token_data.exp) < datetime.now():
|
153 |
+
return False
|
154 |
+
|
155 |
+
except(jwt.JWTError, ValidationError):
|
156 |
+
return False
|
157 |
+
|
158 |
+
return True
|
159 |
+
|
160 |
+
"""Decodes JWTs to check their validity by inspecting expiry and
|
161 |
+
authorization code.
|
162 |
+
|
163 |
+
Args:
|
164 |
+
token: str. Authenticated `access_token` of the user.
|
165 |
+
|
166 |
+
Returns:
|
167 |
+
bool value to indicate validity of the access tokens.
|
168 |
+
|
169 |
+
Raises:
|
170 |
+
jwt.JWTError: If decode fails.
|
171 |
+
ValidationError: If JWTs are not in RFC 7519 standard.
|
172 |
+
"""
|
173 |
+
|
174 |
+
Code
|
175 |
+
{instruction}
|