Spaces:
Runtime error
Runtime error
workflows(suggest_headlines): Randomize and return 3 headlines.
Browse files
workflows/til/suggest_headlines_v2.py
CHANGED
|
@@ -1,12 +1,10 @@
|
|
| 1 |
from langchain import callbacks, hub
|
| 2 |
-
from langchain_core.messages import SystemMessage
|
| 3 |
from langchain_core.output_parsers import JsonOutputParser
|
| 4 |
-
from langchain_core.prompts import ChatPromptTemplate, HumanMessagePromptTemplate
|
| 5 |
from langchain_openai import ChatOpenAI
|
| 6 |
from pydantic import BaseModel, Field, UUID4
|
| 7 |
-
from typing import List
|
| 8 |
import os
|
| 9 |
-
import
|
| 10 |
|
| 11 |
class HeadlineInfo(BaseModel):
|
| 12 |
headline: str
|
|
@@ -24,12 +22,12 @@ class HeadlineInfoLLM(BaseModel):
|
|
| 24 |
tone: str = Field(
|
| 25 |
description="The tone of the suggested headline.",
|
| 26 |
)
|
|
|
|
|
|
|
|
|
|
| 27 |
reason: str = Field(
|
| 28 |
description="Reason for the clickability_score in one sentence",
|
| 29 |
)
|
| 30 |
-
clickability_score: int = Field(
|
| 31 |
-
description="A score out of 10 on how likely the user is going to click on the headline and read the TIL.",
|
| 32 |
-
)
|
| 33 |
|
| 34 |
class HeadlineResults(BaseModel):
|
| 35 |
headlines_details: List[HeadlineInfoLLM]
|
|
@@ -71,7 +69,8 @@ class SuggestHeadlinesV2():
|
|
| 71 |
)
|
| 72 |
|
| 73 |
headlines_data = self.llm_response["headlines_details"]
|
| 74 |
-
|
|
|
|
| 75 |
response.headlines_details.append(
|
| 76 |
HeadlineInfo(
|
| 77 |
headline=headline_datum["headline"],
|
|
|
|
| 1 |
from langchain import callbacks, hub
|
|
|
|
| 2 |
from langchain_core.output_parsers import JsonOutputParser
|
|
|
|
| 3 |
from langchain_openai import ChatOpenAI
|
| 4 |
from pydantic import BaseModel, Field, UUID4
|
| 5 |
+
from typing import List
|
| 6 |
import os
|
| 7 |
+
import random
|
| 8 |
|
| 9 |
class HeadlineInfo(BaseModel):
|
| 10 |
headline: str
|
|
|
|
| 22 |
tone: str = Field(
|
| 23 |
description="The tone of the suggested headline.",
|
| 24 |
)
|
| 25 |
+
clickability_score: int = Field(
|
| 26 |
+
description="Evaluate the headline's quality on a scale of 1 to 10 w.r.t the tone.",
|
| 27 |
+
)
|
| 28 |
reason: str = Field(
|
| 29 |
description="Reason for the clickability_score in one sentence",
|
| 30 |
)
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
class HeadlineResults(BaseModel):
|
| 33 |
headlines_details: List[HeadlineInfoLLM]
|
|
|
|
| 69 |
)
|
| 70 |
|
| 71 |
headlines_data = self.llm_response["headlines_details"]
|
| 72 |
+
random.shuffle(headlines_data)
|
| 73 |
+
for headline_datum in headlines_data[:3]:
|
| 74 |
response.headlines_details.append(
|
| 75 |
HeadlineInfo(
|
| 76 |
headline=headline_datum["headline"],
|