-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
482 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
.env | ||
__pycache__/ | ||
app/notebook.ipynb | ||
app/feed_cache | ||
gmail/ | ||
*-spike/ | ||
|
Empty file.
This file contains 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 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 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,149 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"from langchain_community.llms import Ollama\n", | ||
"from langchain.prompts import ChatPromptTemplate, PromptTemplate, HumanMessagePromptTemplate\n", | ||
"from langchain_core.messages import SystemMessage, HumanMessage\n", | ||
"from langchain.output_parsers import ResponseSchema, StructuredOutputParser" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 12, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"ollama_url = os.getenv('OLLAMA_URL')\n", | ||
"model = Ollama(base_url=ollama_url, model=\"dolphin-mistral\", keep_alive=5, temperature=0.0)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 21, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"title_schema = [ResponseSchema(name=\"title\", description=\"Title for new story\")]\n", | ||
" \n", | ||
"output_parser = StructuredOutputParser.from_response_schemas(title_schema)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 22, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"prompt = PromptTemplate(\n", | ||
"\ttemplate=\"Title: {title}\\nSummary: {summary}\\n{format_instructions}\\n\",\n", | ||
"\tinput_variables=[\"title\", \"summary\"],\n", | ||
"\tpartial_variables={\"format_instructions\": output_parser.get_format_instructions()},\n", | ||
")\n", | ||
"\n", | ||
"# format chat prompt\n", | ||
"system_prompt = SystemMessage(content=(\"\"\"\n", | ||
"\t\tYou are and news article title editor that reviews and provides a concise and accurate title when given an existing Title and article Summary. \n", | ||
"\t\tRemove all links from the title.\n", | ||
"\t\tTitle should be as short as possible, aim to be less that 70 characters long.\n", | ||
"\t\tTitle should have an absolute minimum of punctuation.\n", | ||
"\t\tDo your best to keep the existing title if possible.\n", | ||
"\t\t\"\"\"))\n", | ||
"user_prompt = HumanMessagePromptTemplate(prompt=prompt)\n", | ||
"\n", | ||
"chat_prompt = ChatPromptTemplate.from_messages([system_prompt, user_prompt])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 23, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"chain = chat_prompt | model" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 24, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"items = [\n", | ||
"{'title': 'OPEN THREAD: Just do it.', 'summary': 'OPEN THREAD: Just do it.'},\n", | ||
"{'title': 'THIS PARAGRAPH CAPTURES THE ESSENCE OF THE ATLANTIC’S SAD PIECE ON THE WORLD’S BIGGEST CRUISE SHIP:', 'summary': 'THIS PARAGRAPH CAPTURES THE ESSENCE OF THE ATLANTIC’S SAD PIECE ON THE WORLD’S BIGGEST CRUISE SHIP: “A real journalist or a more intrepid conversationalist would have gone up to the couple and asked them to explain the longevity of their marriage vis-à-vis their love of cruising. But instead I head to my mall suite, take […]'},\n", | ||
"{'title': 'THE NEW SPACE RACE: China launches first of a new series of Yaogan reconnaissance satellites.', 'summary': 'THE NEW SPACE RACE: China launches first of a new series of Yaogan reconnaissance satellites.'},\n", | ||
"{'title': 'WHY IS THE BIDEN ADMINISTRATION TRYING SO HARD TO KEEP HAMAS FROM LOSING? Biden Calls for Ceasefire', 'summary': 'WHY IS THE BIDEN ADMINISTRATION TRYING SO HARD TO KEEP HAMAS FROM LOSING? Biden Calls for Ceasefire During Phone Call with Netanyahu.'},\n", | ||
"{'title': 'BOOK RECOMMENDATION: So I just finished up The Naval Odyssey of Prof. James Brand, so far as it goe', 'summary': 'BOOK RECOMMENDATION: So I just finished up The Naval Odyssey of Prof. James Brand, so far as it goes to date, and quite enjoyed it. It’s a World War II series with plenty of action, but its central character is Prof. James Brand, a wunderkind physicist/operations analyst who zips around solving problems with everything from […]'},\n", | ||
"{'title': 'TUNED MASS DAMPERS FOR THE WIN: How a steel ball protected Taiwan’s tallest skyscraper in an eart', 'summary': 'TUNED MASS DAMPERS FOR THE WIN: How a steel ball protected Taiwan’s tallest skyscraper in an earthquake.'},\n", | ||
"{'title': 'SCIENCE: Thinking You Look Younger Has A Curious Link to How You Age.', 'summary': 'SCIENCE: Thinking You Look Younger Has A Curious Link to How You Age.'},\n", | ||
"{'title': 'ATTEMPT NO LANDINGS THERE: Jupiter’s Moon Europa Beckons As NASA’s Clipper Prepares for the Unk', 'summary': 'ATTEMPT NO LANDINGS THERE: Jupiter’s Moon Europa Beckons As NASA’s Clipper Prepares for the Unknown.'},\n", | ||
"{'title': 'FLASHBACK: Time for Consequences: The “Cabal” who bragged about rigging the 2020 election stuck us', 'summary': 'FLASHBACK: Time for Consequences: The “Cabal” who bragged about rigging the 2020 election stuck us with an incapable president at a time of crisis. Examples need to be made.'},\n", | ||
"{'title': 'MICROBIOME NEWS: Gut microbes may influence odds for obesity.', 'summary': 'MICROBIOME NEWS: Gut microbes may influence odds for obesity.'},\n", | ||
"]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 25, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Just Do It: Open Thread\n", | ||
"World's Biggest Cruise Ship: Couple's Long Marriage and Love of Cruising\n", | ||
"China Launches First Yaogan Recon Satellite in New Series\n", | ||
"Biden Calls for Ceasefire, Biden Admin Supports Hamas\n", | ||
"Naval Odyssey: Enjoyed WWII Series with Prof. James Brand\n", | ||
"Taiwan's Tallest Skyscraper Protected by Tuned Mass Dampers in Earthquake\n", | ||
"Thinking Younger Linked to Aging Process\n", | ||
"NASA's Clipper to Explore Europa\n", | ||
"Cabal Rigged 2020 Election, Led to Incapable President in Crisis\n", | ||
"Gut Microbes Influence Odds For Obesity\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"for item in items:\n", | ||
" output = output_parser.parse(chain.invoke({\"title\": item['title'], \"summary\": item['summary']}))\n", | ||
" print(output['title'])\n", | ||
"\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.