-
-
Notifications
You must be signed in to change notification settings - Fork 294
Added AI processing to events #1066
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0e909cd
Added AI processing to events
samyak003 6627f6d
Merge branch 'main' into feature/addEventSummary
samyak003 6b528a6
Fix formatting error caused by merge conflict.
samyak003 a399d50
Fixed permissions
samyak003 93a577d
Update code
arkid15r 046c059
Merge branch 'OWASP:main' into feature/addEventSummary
samyak003 a14d0a3
Added few changes
samyak003 05f9c57
Merge branch 'main' into pr/samyak003/1066
arkid15r 4eb7b29
Update code
arkid15r File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,5 +16,7 @@ class Meta: | |
| "key", | ||
| "name", | ||
| "start_date", | ||
| "suggested_location", | ||
| "summary", | ||
| "url", | ||
| ) | ||
53 changes: 53 additions & 0 deletions
53
backend/apps/owasp/management/commands/owasp_enrich_events.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| """A command to enrich events with extra data.""" | ||
|
|
||
| import logging | ||
| import time | ||
|
|
||
| from django.core.management.base import BaseCommand | ||
|
|
||
| from apps.core.models.prompt import Prompt | ||
| from apps.owasp.models.event import Event | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| help = "Enrich events with extra data." | ||
|
|
||
| def add_arguments(self, parser): | ||
| parser.add_argument("--offset", default=0, required=False, type=int) | ||
|
|
||
| def handle(self, *args, **options): | ||
| events = Event.objects.order_by("id") | ||
| all_events = [] | ||
| offset = options["offset"] | ||
|
|
||
| for idx, event in enumerate(events[offset:]): | ||
| prefix = f"{idx + offset + 1} of {events.count()}" | ||
| print(f"{prefix:<10} {event.url}") | ||
| # Summary. | ||
| if not event.summary and (prompt := Prompt.get_owasp_event_summary()): | ||
| event.generate_summary(prompt) | ||
|
|
||
| # Suggested location. | ||
| if not event.suggested_location and ( | ||
| prompt := Prompt.get_owasp_event_suggested_location() | ||
| ): | ||
| event.generate_suggested_location(prompt) | ||
|
|
||
| # Geo location. | ||
| if not event.latitude or not event.longitude: | ||
| try: | ||
| event.generate_geo_location() | ||
| time.sleep(5) | ||
| except Exception: | ||
| logger.exception( | ||
| "Could not get geo data for event", | ||
| extra={"url": event.url}, | ||
| ) | ||
| all_events.append(event) | ||
|
|
||
| Event.bulk_save( | ||
| all_events, | ||
| fields=("latitude", "longitude", "suggested_location", "summary"), | ||
| ) |
34 changes: 34 additions & 0 deletions
34
backend/apps/owasp/migrations/0023_event_latitude_event_longitude_and_more.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # Generated by Django 5.1.7 on 2025-03-08 20:29 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("owasp", "0022_sponsor"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="event", | ||
| name="latitude", | ||
| field=models.FloatField(blank=True, null=True, verbose_name="Latitude"), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="event", | ||
| name="longitude", | ||
| field=models.FloatField(blank=True, null=True, verbose_name="Longitude"), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="event", | ||
| name="suggested_location", | ||
| field=models.CharField( | ||
| blank=True, default="", max_length=255, verbose_name="Suggested Location" | ||
| ), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="event", | ||
| name="summary", | ||
| field=models.TextField(blank=True, default="", verbose_name="Summary"), | ||
| ), | ||
| ] |
29 changes: 29 additions & 0 deletions
29
backend/apps/owasp/migrations/0024_event_country_event_postal_code_event_region.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Generated by Django 5.1.7 on 2025-03-09 09:12 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("owasp", "0023_event_latitude_event_longitude_and_more"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="event", | ||
| name="country", | ||
| field=models.CharField(default="", max_length=50, verbose_name="Country"), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="event", | ||
| name="postal_code", | ||
| field=models.CharField( | ||
| blank=True, default="", max_length=15, verbose_name="Postal code" | ||
| ), | ||
| ), | ||
| migrations.AddField( | ||
| model_name="event", | ||
| name="region", | ||
| field=models.CharField(default="", max_length=50, verbose_name="Region"), | ||
| ), | ||
| ] |
24 changes: 24 additions & 0 deletions
24
backend/apps/owasp/migrations/0025_remove_event_country_remove_event_postal_code_and_more.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Generated by Django 5.1.7 on 2025-03-10 02:28 | ||
|
|
||
| from django.db import migrations | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("owasp", "0024_event_country_event_postal_code_event_region"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RemoveField( | ||
| model_name="event", | ||
| name="country", | ||
| ), | ||
| migrations.RemoveField( | ||
| model_name="event", | ||
| name="postal_code", | ||
| ), | ||
| migrations.RemoveField( | ||
| model_name="event", | ||
| name="region", | ||
| ), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.