Skip to content

Commit

Permalink
corrected function calling in ingest
Browse files Browse the repository at this point in the history
  • Loading branch information
star-nox committed Mar 28, 2024
1 parent bafb8d5 commit 9c0c031
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ai_ta_backend/beam/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,8 +1029,8 @@ def split_and_upload(self, texts: List[str], metadatas: List[Dict[str, Any]]):

# add to Nomic document map
if len(response.data) > 0:
inserted_data = response.data[0]
log_to_document_map(inserted_data)
course_name = contexts[0].metadata.get('course_name')
log_to_document_map(course_name)

self.posthog.capture('distinct_id_of_the_user',
event='split_and_upload_succeeded',
Expand Down
29 changes: 22 additions & 7 deletions ai_ta_backend/beam/nomic_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,14 @@ def create_document_map(course_name: str):
project_id = project.id
last_id = int(final_df['id'].iloc[-1])
project_info = {'course_name': course_name, 'doc_map_id': project_id, 'last_uploaded_doc_id': last_id}
update_response = SUPABASE_CLIENT.table("projects").insert(project_info).execute()
print("Response from supabase: ", update_response)
project_response = SUPABASE_CLIENT.table("projects").select("*").eq("course_name", course_name).execute()
if project_response.data:
update_response = SUPABASE_CLIENT.table("projects").update(project_info).eq("course_name", course_name).execute()
print("Response from supabase: ", update_response)
else:
insert_response = SUPABASE_CLIENT.table("projects").insert(project_info).execute()
print("Insert Response from supabase: ", insert_response)


else:
# append to existing map
Expand Down Expand Up @@ -143,12 +149,19 @@ def create_document_map(course_name: str):
if result == "success":
# update the last uploaded id in supabase
last_id = int(final_df['id'].iloc[-1])
project_info = {'last_uploaded_doc_id': last_id}
project = AtlasProject(name=project_name, add_datums_if_exists=True)
project_id = project.id
project_info = {'course_name': course_name, 'doc_map_id': project_id, 'last_uploaded_doc_id': last_id}
print("project_info: ", project_info)
update_response = SUPABASE_CLIENT.table("projects").update(project_info).eq("course_name", course_name).execute()
print("Response from supabase: ", update_response)


project_response = SUPABASE_CLIENT.table("projects").select("*").eq("course_name", course_name).execute()
if project_response.data:
update_response = SUPABASE_CLIENT.table("projects").update(project_info).eq("course_name", course_name).execute()
print("Response from supabase: ", update_response)
else:
insert_response = SUPABASE_CLIENT.table("projects").insert(project_info).execute()
print("Insert Response from supabase: ", insert_response)


# rebuild the map
rebuild_map(course_name, "document")

Expand Down Expand Up @@ -352,6 +365,8 @@ def data_prep_for_doc_map(df: pd.DataFrame):
created_at = datetime.datetime.strptime(row['created_at'], "%Y-%m-%dT%H:%M:%S.%f%z").strftime("%Y-%m-%d %H:%M:%S")
if row['url'] == None:
row['url'] = ""
if row['base_url'] == None:
row['base_url'] = ""
# iterate through all contexts and create separate entries for each
context_count = 0
for context in row['contexts']:
Expand Down

0 comments on commit 9c0c031

Please sign in to comment.