-
Notifications
You must be signed in to change notification settings - Fork 282
[N-3] 13-LangChain-Expression-Language / 13-WithListeners #309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
[Title] WithListeners [Version] initial [Language] ENG [Packages] langchain_core, asyncio, time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🖥️ OS: Windows
✅ Checklist
- [ ✅ ] Template: Tutorials follows the required template.
- [ ✅ ] Table of Contents(TOC) Links: All Table of Contents links work. ((Yes/No))
- [ ✅ ] Image: Image filenames follow guidelines.
- [ ✅ ] *Imports: All import statements use the latest versions. Ensure "langchain-teddynote" is not used.
- [ ✅ ] Code Execution: Code runs without errors.
- Comments: 오류 없이 실행 확인했고, 형식 어긴것 없이 내용도 잘 적었다고 생각해 Approve 합니다. 고생하셨습니다!
"cell_type": "code", | ||
"execution_count": 6, | ||
"id": "fed852d1", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Start: {'input': 'Hello, World!'}\n", | ||
"End: {'input': 'Hello, World!'}\n", | ||
"Start: {'input': 'Step 1 completed with message Hello, World!'}\n", | ||
"End: {'input': 'Step 1 completed with message Hello, World!'}\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from langchain_core.runnables import RunnableLambda\n", | ||
"import time\n", | ||
"\n", | ||
"\n", | ||
"# Define tasks for each Runnable\n", | ||
"def stepOne(message):\n", | ||
" time.sleep(1) # Wait for 1 second\n", | ||
" return f\"Step 1 completed with message {message}\"\n", | ||
"\n", | ||
"\n", | ||
"def stepTwo(message):\n", | ||
" time.sleep(2) # Wait for 2 seconds\n", | ||
" return f\"Step 2 completed with message {message}\"\n", | ||
"\n", | ||
"\n", | ||
"# Define listener functions\n", | ||
"def fnStart(runObj):\n", | ||
" print(f\"Start: {runObj.inputs}\")\n", | ||
"\n", | ||
"\n", | ||
"def fnEnd(runObj):\n", | ||
" print(f\"End: {runObj.inputs}\")\n", | ||
"\n", | ||
"\n", | ||
"def fnError(runObj):\n", | ||
" print(f\"Error: {runObj.error}\")\n", | ||
"\n", | ||
"\n", | ||
"# Define each Runnable\n", | ||
"runnable1 = RunnableLambda(stepOne).with_listeners(\n", | ||
" on_start=fnStart, on_end=fnEnd, on_error=fnError\n", | ||
")\n", | ||
"\n", | ||
"runnable2 = RunnableLambda(stepTwo).with_listeners(\n", | ||
" on_start=fnStart, on_end=fnEnd, on_error=fnError\n", | ||
")\n", | ||
"\n", | ||
"# Chain connection\n", | ||
"chain = runnable1 | runnable2\n", | ||
"\n", | ||
"# Execute\n", | ||
"output = chain.invoke(\"Hello, World!\")" | ||
] | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분 실행 여러번 해 봤는데,
하단에 .with_listeners()로 구현한 것과는 결과가 다르게 나오는데 어떻게 생각하시나요?
그냥 맨 밑에 있는
output = chain.invoke("Hello, World!")
이 부분 변수 빼주시거나 print(output)으로 출력 해주시면 아마 정상적으로 밑 block과 똑같은 결과 나올 것 같습니다..!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
피드백 감사합니다! 확인해서 수정하였습니다.
말씀하신 output
변수는 빼주고
fnEnd()
함수의 출력을 runObj.inputs
->runObj.outputs
로 변경하여 통일하였습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🖥️ OS: Windows
✅ Checklist
[ ✅ ] Template: Tutorials follows the required template.
[ ✅ ] Table of Contents(TOC) Links: All Table of Contents links work. ((Yes/No))
[ ✅ ] Image: Image filenames follow guidelines.
[ ✅ ] *Imports: All import statements use the latest versions. Ensure "langchain-teddynote" is not used.
[ ✅ ] Code Execution: Code runs without errors.
Comments: None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Review OS(Windows/Mac/Linux): Mac
- Template Rule 가이드를 준수 하였는가(YES/NO):Yes
- Table of Contents 의 링크가 원활하게 동작하는지 확인하였는가?(YES/NO): Yes
- 이미지가 포함되어 있다면, 이미지의 파일명이 가이드를 준수하였는가?(YES/NO): Yes
- import 구문이 예전 legacy 방식이 아닌 최신 버전을 따르는가?(YES/NO):Yes
- 모든 코드가 동작에 오류 없이 동작하는가? (만약, warning 발생시 코멘트에 적어주세요): Yes
- 기타 의견: 코드의 의도와 결과에 대한 설명이 자세했으면 더 좋았을 듯합니다 ~ 수고하셨습니다
6da6cbe
into
LangChain-OpenTutorial:main
add 13-WithListeners
Author Checklist
[ ✅ ] PR Title Format: I have confirmed that the PR title follows the correct format. (e.g., [N-2] 07-Text Splitter / 07-RecursiveCharacterTextSplitter)
[ ✅ ] Committed Files: I have ensured that no unnecessary files (e.g., .bin, .gitignore, poetry.lock, pyproject.toml) are included. These files are not allowed.
[ ] (Optional) Related Issue: If this PR is linked to an issue, I have referenced the issue number in the PR message. (e.g., Fixes Update 01-PromptTemplate.ipynb #123)
❌ Do not include unnecessary files (e.g., .bin, .gitignore, poetry.lock, pyproject.toml) or other people's code. If included, close the PR and create a new PR.
Review Template (Intial PR)
If no one reviews your PR within a few days, please @-mention one of teddylee777, musangk, BAEM1N