Skip to content

Commit

Permalink
Update langchain to avoid deprecated calls
Browse files Browse the repository at this point in the history
Try to modify summary lengths.
  • Loading branch information
houfu committed Sep 3, 2024
1 parent 89c1b44 commit 12fa9b4
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 11 deletions.
96 changes: 91 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ langchain = "^0.2.15"
html5lib = "^1.1"
pydantic = "^2.5.0"
langchain-openai = "^0.1.23"
langchain-community = "^0.2.15"


[build-system]
Expand Down
12 changes: 6 additions & 6 deletions sg_law_cookies/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import requests
from bs4 import BeautifulSoup
from jinja2 import Environment, PackageLoader
from langchain.chat_models import ChatOpenAI
from langchain.prompts import (
SystemMessagePromptTemplate,
HumanMessagePromptTemplate,
ChatPromptTemplate,
AIMessagePromptTemplate,
)
from langchain_openai import ChatOpenAI
from pydantic import BaseModel, AnyHttpUrl

system_template = """As an AI expert in legal affairs, your task is to provide concise, yet comprehensive
Expand All @@ -25,7 +25,7 @@
2. Outline the main legal aspects, implications, and precedents highlighted in the article.
3. End the summary with a succinct conclusion or takeaway.
Aim for summaries to be no more than five sentences, but ensure they efficiently deliver the key legal insights,
The summaries should not be longer than 100 words, but ensure they efficiently deliver the key legal insights,
making them beneficial for quick comprehension. The end goal is to help the lawyers understand the crux of the
articles without having to read them in their entirety."""

Expand Down Expand Up @@ -142,8 +142,8 @@ def get_summary(article: ScrapedArticle) -> NewsArticle:
messages = article_summary_prompt.format_prompt(
article=article_content
).to_messages()
chat = ChatOpenAI(model_name="gpt-4o-mini")
summary_response = chat(messages)
chat = ChatOpenAI(model="gpt-4o-mini")
summary_response = chat.invoke(messages)
return NewsArticle(
category=article.category,
title=article.title,
Expand Down Expand Up @@ -193,9 +193,9 @@ def get_summaries(articles: list[ScrapedArticle]):

day_messages = day_messages + day_summary_prompt.format_messages()

chat = ChatOpenAI(model_name="gpt-4", temperature=0.25)
chat = ChatOpenAI(model="gpt-4o", temperature=0.25)

day_summary = chat(day_messages)
day_summary = chat.invoke(day_messages)

return summaries, day_summary.content.splitlines()

Expand Down

0 comments on commit 12fa9b4

Please sign in to comment.