in infra-as-code/modules/ingest-pipeline/cf-feedback-generator/lib.py [0:0]
def insert_feedback_to_bigquery(self, json_data):
"""Inserts the feedback generated in BigQuery
Args:
json_data (dict): dictionary with the gemini response
"""
client = bigquery.Client(project=self.project_id)
table_ref = client.dataset(self.dataset_name).table(self.table_name)
table = client.get_table(table_ref)
# Convert JSON to rows format expected by BigQuery
rows_to_insert = [{
'conversationName': json_data['conversation_id'],
'qaQuestion': json_data['question_id'],
'feedback': json_data['feedback']
}]
try:
errors = client.insert_rows(table, rows_to_insert)
if errors == []:
print('Data inserted successfully')
else:
print('Errors occurred while inserting data:', errors)
except Exception as e:
print(f'Error occurred: {str(e)}')
return