fix: replace deprecated langchain_classic imports with modern LCEL - #198
fix: replace deprecated langchain_classic imports with modern LCEL#198Artibar wants to merge 1 commit into
Conversation
- Remove unused PromptTemplate import from app.py - Replace LLMChain + PromptTemplate in NewsService.py with modern LCEL syntax (prompt | llm | StrOutputParser()) - Update openai==0.27.8 to openai>=1.0.0 in requirements.txt Fixes c2siorg#197 Assisted-By: Claude (code review and suggestions)
|
Hi @Artibar, I tested this PR locally against Confirmed working:
Found while testing — not fixed by this PR:
This means even after this PR's fix, the Separately (not related to this PR): installing the full Would you like me to open a follow-up PR for the |
|
I tested this PR locally against main. The old code used deprecated langchain_classic imports that broke at runtime — this PR's LCEL fix resolves that correctly, confirmed the imports work and the chain runs. While testing, I found a separate bug in toJSON() that's still present: it always drops the last parsed news item (news_list_json.pop() at the end runs unconditionally). Tested with 2 items → only 1 returned; tested with 1 item → empty list returned. Happy to open a follow-up PR for the toJSON fix if useful, or fold it into this one — let me know what you'd prefer. |
Summary
app.pyNewsService.pywith modern LCEL syntax (prompt | llm | StrOutputParser())openai==0.27.8toopenai>=1.0.0inrequirements.txtapp.pyused invalid import, howeverNewsService.pyused deprecatedimport from langchain_classic and
requirements.txtpins openai==0.27.8 (2023).This causes runtime errors and prevents running the app locally.
Description
app.py — removed invalid PromptTemplate import
from langchain_classic with modern LCEL syntax:
chain = prompt | self.llm | StrOutputParser()
Related Issue
Fixes #197
Reference
Official LLMChain deprecation notice:
https://reference.langchain.com/python/langchain-classic/chains/llm/LLMChain
Assisted-By: Claude (syntax reference)
Motivation and Context
change is required due to deprecated import cause error and need to maintain up to date latest version
How Has This Been Tested?
pip install -r requirements.txtsuccessfully after fixpython app.py— app starts without ImportErrorlangchain_classicimports no longer present insource files using
findstr /r "langchain_classic" app.py services\NewsService.pyTest environment:
Screenshots (if appropriate):
Types of changes
Checklist: