Compare commits
No commits in common. "2da0b90b1b835ac414abc73f78a35d7b657a2ecd" and "434773025b1d3d4a42086f008fdfc796a1d8edde" have entirely different histories.
2da0b90b1b
...
434773025b
4 changed files with 16 additions and 39 deletions
|
|
@ -17,7 +17,7 @@ class IImprovementRepo(Protocol):
|
||||||
def get(self, id: str) -> Improvement:
|
def get(self, id: str) -> Improvement:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def get_all(self, last_n: int | None = None) -> list[Improvement]:
|
def get_all(self) -> list[Improvement]:
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def remove(self, id: str) -> Improvement:
|
def remove(self, id: str) -> Improvement:
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,7 @@ from prophet.domain.original import Original
|
||||||
|
|
||||||
|
|
||||||
class LLMClient(Protocol):
|
class LLMClient(Protocol):
|
||||||
def rewrite(
|
def rewrite(self, original: Original) -> Improvement:
|
||||||
self, original: Original, previous_titles: list[str] | None = None
|
|
||||||
) -> Improvement:
|
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def rewrite_title(
|
def rewrite_title(
|
||||||
|
|
|
||||||
|
|
@ -48,22 +48,15 @@ class ImprovementSupaRepo(IImprovementRepo):
|
||||||
)
|
)
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def get_all(self, last_n: int | None = None) -> list[Improvement]:
|
def get_all(self) -> list[Improvement]:
|
||||||
if not last_n:
|
return [
|
||||||
sql = (
|
self._from_tbl_row(row)
|
||||||
self.client.table(self.config.TABLE)
|
for row in self.client.table(self.config.TABLE)
|
||||||
.select("*")
|
.select("*")
|
||||||
.order("date_orig_ts", desc=True)
|
.order("date_orig_ts", desc=True)
|
||||||
)
|
.execute()
|
||||||
else:
|
.data
|
||||||
sql = (
|
]
|
||||||
self.client.table(self.config.TABLE)
|
|
||||||
.select("*")
|
|
||||||
.order("date_orig_ts", desc=True)
|
|
||||||
.limit(last_n)
|
|
||||||
)
|
|
||||||
|
|
||||||
return [self._from_tbl_row(row) for row in sql.execute().data]
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def remove(self, id: str) -> Improvement:
|
def remove(self, id: str) -> Improvement:
|
||||||
|
|
@ -117,7 +110,6 @@ class ImprovementSupaRepo(IImprovementRepo):
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# response = supabase.table("improvements").select("*").execute()
|
# response = supabase.table("improvements").select("*").execute()
|
||||||
repo = ImprovementSupaRepo()
|
repo = ImprovementSupaRepo()
|
||||||
print("latest entries:\n- ", "\n- ".join([imp.title for imp in repo.get_all(3)]))
|
|
||||||
|
|
||||||
# from prophet.app import grab_latest_originals
|
# from prophet.app import grab_latest_originals
|
||||||
# latest = grab_latest_originals()
|
# latest = grab_latest_originals()
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,7 @@ 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(
|
def rewrite(self, original: Original) -> Improvement:
|
||||||
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)
|
||||||
|
|
@ -32,22 +30,18 @@ class GroqClient(LLMClient):
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def get_alternative_title_suggestions(
|
def get_alternative_title_suggestions(
|
||||||
self,
|
self, original_content: str, custom_prompt: str | None = None
|
||||||
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 f"""
|
else """
|
||||||
|
|
||||||
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 by masked ICE agents. Many view the United States
|
almost every day. Many are calling the United States an
|
||||||
as an increasingly fascist state, and the disappearings fueled by
|
increasingly fascist state.
|
||||||
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
|
||||||
|
|
@ -55,13 +49,6 @@ 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