Skip to content

Commit

Permalink
gpt-4o-mini and other model
Browse files Browse the repository at this point in the history
  • Loading branch information
yinan-c committed Jul 21, 2024
1 parent 6333191 commit 96a7e0b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion FeedManager/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def original_feed_count(self, obj):
'fields': ('name', 'feeds', 'feed_group_relational_operator'),
}),
('Summarization Options', {
'fields': ('articles_to_summarize_per_interval', 'summary_language', 'model', 'summary_group_relational_operator', 'additional_prompt'),
'fields': ('articles_to_summarize_per_interval', 'summary_language', 'model', 'other_model', 'summary_group_relational_operator', 'additional_prompt'),
}),
('Digest Options', {
'fields': ('toggle_entries', 'toggle_digest', 'digest_frequency', 'last_digest'),#, 'include_one_line_summary', 'include_summary', 'include_content', 'use_ai_digest', 'digest_model', 'additional_prompt_for_digest','send_full_article'),
Expand Down
2 changes: 1 addition & 1 deletion FeedManager/management/commands/generate_digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def gen_digest(self, feed, force):
if feed.additional_prompt_for_digest:
prompt = feed.additional_prompt_for_digest
logger.info(f" Using AI model {feed.digest_model} to generate digest.")
digest_ai_result = generate_summary(digest_article, feed.digest_model, output_mode='HTML', prompt=prompt)
digest_ai_result = generate_summary(digest_article, feed.digest_model, output_mode='HTML', prompt=prompt, other_model=feed.other_digest_model)
logger.debug(f" AI digest result: {digest_ai_result}")
# prepend the AI digest result to the digest content
if digest_ai_result:
Expand Down
2 changes: 1 addition & 1 deletion FeedManager/management/commands/update_feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def process_entry(self, entry, feed, original_feed):
if feed.additional_prompt:
prompt = f"{feed.additional_prompt}"
output_mode = 'HTML'
summary_results = generate_summary(article, feed.model, output_mode, prompt)
summary_results = generate_summary(article, feed.model, output_mode, prompt, feed.other_model)
# TODO the JSON mode parse is hard-coded as is the default prompt, maybe support automatic json parsing in the future
try:
json_result = json.loads(summary_results)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 5.0.6 on 2024-07-21 00:25

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('FeedManager', '0021_tag_remove_originalfeed_tag_originalfeed_tags'),
]

operations = [
migrations.AddField(
model_name='processedfeed',
name='other_digest_model',
field=models.CharField(blank=True, default='', help_text="AI Model for digest generation, only used if 'Other' is selected.", max_length=255),
),
migrations.AddField(
model_name='processedfeed',
name='other_model',
field=models.CharField(blank=True, default='', help_text="AI Model for summarization, only used if 'Other' is selected.", max_length=255),
),
migrations.AlterField(
model_name='processedfeed',
name='digest_model',
field=models.CharField(choices=[('gpt-3.5-turbo', 'GPT-3.5 Turbo'), ('gpt-4-turbo', 'GPT-4 Turbo'), ('gpt-4o', 'GPT-4o'), ('gpt-4o-mini', 'GPT-4o Mini'), ('other', 'Other')], default='gpt-3.5-turbo', help_text='Model for digest generation.', max_length=20),
),
migrations.AlterField(
model_name='processedfeed',
name='model',
field=models.CharField(choices=[('gpt-3.5-turbo', 'GPT-3.5 Turbo'), ('gpt-4-turbo', 'GPT-4 Turbo'), ('gpt-4o', 'GPT-4o'), ('gpt-4o-mini', 'GPT-4o Mini'), ('other', 'Other')], default='gpt-3.5-turbo', max_length=20),
),
]
4 changes: 4 additions & 0 deletions FeedManager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ class ProcessedFeed(models.Model):
('gpt-3.5-turbo', 'GPT-3.5 Turbo'),
('gpt-4-turbo', 'GPT-4 Turbo'),
('gpt-4o', 'GPT-4o'),
('gpt-4o-mini', 'GPT-4o Mini'),
('other', 'Other'),
]
model = models.CharField(max_length=20, default='gpt-3.5-turbo', choices=choices)
other_model = models.CharField(max_length=255, blank=True, default='', help_text="AI Model for summarization, only used if 'Other' is selected.")

# Digest related fields
toggle_digest = models.BooleanField(default=False, help_text="Send a digest of the feed regularly.")
Expand All @@ -67,6 +70,7 @@ class ProcessedFeed(models.Model):
use_ai_digest = models.BooleanField(default=False, help_text="Use AI to process digest content.")
send_full_article = models.BooleanField(default=False, help_text="(Ignored without prompt) Send full article content for AI digest, by default only link, title, and summary are sent.")
digest_model = models.CharField(max_length=20, default='gpt-3.5-turbo', choices=choices, help_text="Model for digest generation.")
other_digest_model = models.CharField(max_length=255, blank=True, default='', help_text="AI Model for digest generation, only used if 'Other' is selected.")
additional_prompt_for_digest = models.TextField(blank=True, default='', verbose_name='(Optional) Prompt for Digest', help_text="Using AI to generate digest, otherwise only the title, link and summary from the database will be included in the digest.")

# Filter related fields
Expand Down
6 changes: 5 additions & 1 deletion FeedManager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ def clean_txt_and_truncate(query, model, clean_bool=True):
'gpt-3.5-turbo': 16200,
'gpt-4o': 127800,
'gpt-4-turbo': 127800,
'gpt-4o-mini': 127800,
'other': 127800 #! User-defined models
}

# Truncate the text if it exceeds the model's token limit
Expand Down Expand Up @@ -137,7 +139,9 @@ def match_content(entry, filter):
return len(content) > int(filter.value)


def generate_summary(article, model, output_mode='HTML', prompt=None):
def generate_summary(article, model, output_mode='HTML', prompt=None, other_model=''):
if model == 'other':
model = other_model
if not model or not OPENAI_API_KEY:
logger.info(' OpenAI API key or model not set, skipping summary generation')
return
Expand Down

0 comments on commit 96a7e0b

Please sign in to comment.