feat: Limit Trump mentions based on previous titles
Some checks are pending
Create and publish a Docker image / build-and-push-image (push) Waiting to run
Some checks are pending
Create and publish a Docker image / build-and-push-image (push) Waiting to run
This commit is contained in:
parent
a8958c76fb
commit
2da0b90b1b
2 changed files with 21 additions and 6 deletions
|
|
@ -5,7 +5,9 @@ from prophet.domain.original import Original
|
||||||
|
|
||||||
|
|
||||||
class LLMClient(Protocol):
|
class LLMClient(Protocol):
|
||||||
def rewrite(self, original: Original) -> Improvement:
|
def rewrite(
|
||||||
|
self, original: Original, previous_titles: list[str] | None = None
|
||||||
|
) -> Improvement:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def rewrite_title(
|
def rewrite_title(
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,9 @@ class GroqClient(LLMClient):
|
||||||
self.client = client if client else Groq(api_key=self.config_ai.API_KEY)
|
self.client = client if client else Groq(api_key=self.config_ai.API_KEY)
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def rewrite(self, original: Original) -> Improvement:
|
def rewrite(
|
||||||
|
self, original: Original, previous_titles: list[str] | None = None
|
||||||
|
) -> Improvement:
|
||||||
suggestions = self.get_alternative_title_suggestions(original.title)
|
suggestions = self.get_alternative_title_suggestions(original.title)
|
||||||
new_title = self.rewrite_title(original.title, suggestions)
|
new_title = self.rewrite_title(original.title, suggestions)
|
||||||
new_summary = self.rewrite_summary(original, new_title)
|
new_summary = self.rewrite_summary(original, new_title)
|
||||||
|
|
@ -30,18 +32,22 @@ class GroqClient(LLMClient):
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def get_alternative_title_suggestions(
|
def get_alternative_title_suggestions(
|
||||||
self, original_content: str, custom_prompt: str | None = None
|
self,
|
||||||
|
original_content: str,
|
||||||
|
previous_titles: list[str] | None = None,
|
||||||
|
custom_prompt: str | None = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
prompt = (
|
prompt = (
|
||||||
custom_prompt
|
custom_prompt
|
||||||
if custom_prompt
|
if custom_prompt
|
||||||
else """
|
else f"""
|
||||||
|
|
||||||
Political context: We are in the year 2025, Donald Trump is
|
Political context: We are in the year 2025, Donald Trump is
|
||||||
President of the United States again. There has been a crackdown on
|
President of the United States again. There has been a crackdown on
|
||||||
'illegal' immigration, with controversial disappearings happening
|
'illegal' immigration, with controversial disappearings happening
|
||||||
almost every day. Many are calling the United States an
|
almost every day by masked ICE agents. Many view the United States
|
||||||
increasingly fascist state.
|
as an increasingly fascist state, and the disappearings fueled by
|
||||||
|
racism.
|
||||||
|
|
||||||
You are a comedy writer at a left-leaning satirical newspaper.
|
You are a comedy writer at a left-leaning satirical newspaper.
|
||||||
Improve on the following satirical headline. Your new headline is
|
Improve on the following satirical headline. Your new headline is
|
||||||
|
|
@ -49,6 +55,13 @@ class GroqClient(LLMClient):
|
||||||
It should be roughly the length of the original headline. Print
|
It should be roughly the length of the original headline. Print
|
||||||
only new suggestions, with one suggestion on each line.
|
only new suggestions, with one suggestion on each line.
|
||||||
|
|
||||||
|
Do not create a headline naming Trump if more than 2 of the
|
||||||
|
previous headlines already do so and he is not specifically
|
||||||
|
referenced in the original headline.
|
||||||
|
|
||||||
|
{"The previous 5 headlines you created are the following:\n- " if previous_titles else ""}
|
||||||
|
{"\n- ".join(previous_titles) if previous_titles else ""}
|
||||||
|
|
||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
suggestions = self.client.chat.completions.create(
|
suggestions = self.client.chat.completions.create(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue