Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

stsr1284
Copy link
Contributor

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)

🖥️ OS: Win/Mac/Linux   
✅ 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: {Write freely, 한국어 기술 가능}     

If no one reviews your PR within a few days, please @-mention one of teddylee777, musangk, BAEM1N

@stsr1284 stsr1284 self-assigned this Jan 12, 2025
@stsr1284 stsr1284 changed the title [N-3] 13-LCEL / 13-WithListeners [N-3] 13-LangChain-Expression-Language / 13-WithListeners Jan 12, 2025
PangPangGod
PangPangGod previously approved these changes Jan 16, 2025
Copy link
Contributor

@PangPangGod PangPangGod left a 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 합니다. 고생하셨습니다!

Comment on lines 161 to 221
"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!\")"
]
},
Copy link
Contributor

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과 똑같은 결과 나올 것 같습니다..!!

Copy link
Contributor Author

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로 변경하여 통일하였습니다!

Copy link
Contributor

@PangPangGod PangPangGod left a 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

Copy link
Contributor

@acho98 acho98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Review OS(Windows/Mac/Linux): Mac
  2. Template Rule 가이드를 준수 하였는가(YES/NO):Yes
  3. Table of Contents 의 링크가 원활하게 동작하는지 확인하였는가?(YES/NO): Yes
  4. 이미지가 포함되어 있다면, 이미지의 파일명이 가이드를 준수하였는가?(YES/NO): Yes
  5. import 구문이 예전 legacy 방식이 아닌 최신 버전을 따르는가?(YES/NO):Yes
  6. 모든 코드가 동작에 오류 없이 동작하는가? (만약, warning 발생시 코멘트에 적어주세요): Yes
  7. 기타 의견: 코드의 의도와 결과에 대한 설명이 자세했으면 더 좋았을 듯합니다 ~ 수고하셨습니다

@teddylee777 teddylee777 merged commit 6da6cbe into LangChain-OpenTutorial:main Jan 18, 2025
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants