Skip to content

Commit

Permalink
created get_enabled_doc_groups function and endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxwell-Lindsey committed Feb 27, 2024
1 parent 11538f6 commit 32c78ac
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ai_ta_backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,5 +823,22 @@ def enableDocumentGroup():
response.headers.add('Access-Control-Allow-Origin', '*')
return response

@app.route('/getEnabledDocGroups', methods=['GET'])
def getEnabledDocGroups():
course_name = request.args.get('course_name')

if course_name is None:
abort(
400,
description=
f"Missing required parameter: 'course_name' must be provided. Course name: `{course_name}`"
)

ingester = Ingest()
enabled_doc_groups = ingester.get_enabled_doc_groups(course_name=course_name)
response = jsonify({'enabled_doc_groups': enabled_doc_groups})
response.headers.add('Access-Control-Allow-Origin', '*')
return response

if __name__ == '__main__':
app.run(debug=True, port=int(os.getenv("PORT", default=8000))) # nosec -- reasonable bandit error suppression
14 changes: 14 additions & 0 deletions ai_ta_backend/vector_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -1698,6 +1698,20 @@ def enable_doc_group(self, course_name: str, doc_group_name: str):
"""
self.set_enabled_doc_group(course_name, doc_group_name, True)

def get_enabled_doc_groups(self, course_name: str) -> List[str]:
"""
Get the enabled document groups for a given course.
"""
try:
# Fetch the current list of enabled doc groups
response = self.supabase_client.table('projects').select('enabled_doc_groups').eq('course_name', course_name).execute()
enabled_doc_groups = response.data[0]['enabled_doc_groups'] if response.data else []
return enabled_doc_groups
except Exception as e:
print("Error in getting enabled document groups:", e)
sentry_sdk.capture_exception(e)
return []

def add_documents_to_doc_group(self, course_name: str, docs: MaterialDocument | list[MaterialDocument]):
"""
Add document group name to documents (in both supabase and qdrant).
Expand Down

0 comments on commit 32c78ac

Please sign in to comment.