Spaces:
Running
Running
File size: 35,182 Bytes
aa98b19 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 |
import streamlit as st
import asyncio
import nest_asyncio
import json
import os
import platform
if platform.system() == "Windows":
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy())
# nest_asyncio ์ ์ฉ: ์ด๋ฏธ ์คํ ์ค์ธ ์ด๋ฒคํธ ๋ฃจํ ๋ด์์ ์ค์ฒฉ ํธ์ถ ํ์ฉ
nest_asyncio.apply()
# ์ ์ญ ์ด๋ฒคํธ ๋ฃจํ ์์ฑ ๋ฐ ์ฌ์ฌ์ฉ (ํ๋ฒ ์์ฑํ ํ ๊ณ์ ์ฌ์ฉ)
if "event_loop" not in st.session_state:
loop = asyncio.new_event_loop()
st.session_state.event_loop = loop
asyncio.set_event_loop(loop)
from langgraph.prebuilt import create_react_agent
from langchain_anthropic import ChatAnthropic
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage
from dotenv import load_dotenv
from langchain_mcp_adapters.client import MultiServerMCPClient
from utils import astream_graph, random_uuid
from langchain_core.messages.ai import AIMessageChunk
from langchain_core.messages.tool import ToolMessage
from langgraph.checkpoint.memory import MemorySaver
from langchain_core.runnables import RunnableConfig
# ํ๊ฒฝ ๋ณ์ ๋ก๋ (.env ํ์ผ์์ API ํค ๋ฑ์ ์ค์ ์ ๊ฐ์ ธ์ด)
load_dotenv(override=True)
# config.json ํ์ผ ๊ฒฝ๋ก ์ค์
CONFIG_FILE_PATH = "config.json"
# JSON ์ค์ ํ์ผ ๋ก๋ ํจ์
def load_config_from_json():
"""
config.json ํ์ผ์์ ์ค์ ์ ๋ก๋ํฉ๋๋ค.
ํ์ผ์ด ์๋ ๊ฒฝ์ฐ ๊ธฐ๋ณธ ์ค์ ์ผ๋ก ํ์ผ์ ์์ฑํฉ๋๋ค.
๋ฐํ๊ฐ:
dict: ๋ก๋๋ ์ค์
"""
default_config = {
"get_current_time": {
"command": "python",
"args": ["./mcp_server_time.py"],
"transport": "stdio"
}
}
try:
if os.path.exists(CONFIG_FILE_PATH):
with open(CONFIG_FILE_PATH, "r", encoding="utf-8") as f:
return json.load(f)
else:
# ํ์ผ์ด ์๋ ๊ฒฝ์ฐ ๊ธฐ๋ณธ ์ค์ ์ผ๋ก ํ์ผ ์์ฑ
save_config_to_json(default_config)
return default_config
except Exception as e:
st.error(f"์ค์ ํ์ผ ๋ก๋ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}")
return default_config
# JSON ์ค์ ํ์ผ ์ ์ฅ ํจ์
def save_config_to_json(config):
"""
์ค์ ์ config.json ํ์ผ์ ์ ์ฅํฉ๋๋ค.
๋งค๊ฐ๋ณ์:
config (dict): ์ ์ฅํ ์ค์
๋ฐํ๊ฐ:
bool: ์ ์ฅ ์ฑ๊ณต ์ฌ๋ถ
"""
try:
with open(CONFIG_FILE_PATH, "w", encoding="utf-8") as f:
json.dump(config, f, indent=2, ensure_ascii=False)
return True
except Exception as e:
st.error(f"์ค์ ํ์ผ ์ ์ฅ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}")
return False
# ๋ก๊ทธ์ธ ์ธ์
๋ณ์ ์ด๊ธฐํ
if "authenticated" not in st.session_state:
st.session_state.authenticated = False
# ๋ก๊ทธ์ธ ํ์ ์ฌ๋ถ ํ์ธ
use_login = os.environ.get("USE_LOGIN", "false").lower() == "true"
# ๋ก๊ทธ์ธ ์ํ์ ๋ฐ๋ผ ํ์ด์ง ์ค์ ๋ณ๊ฒฝ
if use_login and not st.session_state.authenticated:
# ๋ก๊ทธ์ธ ํ์ด์ง๋ ๊ธฐ๋ณธ(narrow) ๋ ์ด์์ ์ฌ์ฉ
st.set_page_config(page_title="Agent with MCP Tools", page_icon="๐ง ")
else:
# ๋ฉ์ธ ์ฑ์ wide ๋ ์ด์์ ์ฌ์ฉ
st.set_page_config(page_title="Agent with MCP Tools", page_icon="๐ง ", layout="wide")
# ๋ก๊ทธ์ธ ๊ธฐ๋ฅ์ด ํ์ฑํ๋์ด ์๊ณ ์์ง ์ธ์ฆ๋์ง ์์ ๊ฒฝ์ฐ ๋ก๊ทธ์ธ ํ๋ฉด ํ์
if use_login and not st.session_state.authenticated:
st.title("๐ ๋ก๊ทธ์ธ")
st.markdown("์์คํ
์ ์ฌ์ฉํ๋ ค๋ฉด ๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค.")
# ๋ก๊ทธ์ธ ํผ์ ํ๋ฉด ์ค์์ ์ข๊ฒ ๋ฐฐ์น
with st.form("login_form"):
username = st.text_input("์์ด๋")
password = st.text_input("๋น๋ฐ๋ฒํธ", type="password")
submit_button = st.form_submit_button("๋ก๊ทธ์ธ")
if submit_button:
expected_username = os.environ.get("USER_ID")
expected_password = os.environ.get("USER_PASSWORD")
if username == expected_username and password == expected_password:
st.session_state.authenticated = True
st.success("โ
๋ก๊ทธ์ธ ์ฑ๊ณต! ์ ์๋ง ๊ธฐ๋ค๋ ค์ฃผ์ธ์...")
st.rerun()
else:
st.error("โ ์์ด๋ ๋๋ ๋น๋ฐ๋ฒํธ๊ฐ ์ฌ๋ฐ๋ฅด์ง ์์ต๋๋ค.")
# ๋ก๊ทธ์ธ ํ๋ฉด์์๋ ๋ฉ์ธ ์ฑ์ ํ์ํ์ง ์์
st.stop()
# ์ฌ์ด๋๋ฐ ์ต์๋จ์ ์ ์ ์ ๋ณด ์ถ๊ฐ (๋ค๋ฅธ ์ฌ์ด๋๋ฐ ์์๋ณด๋ค ๋จผ์ ๋ฐฐ์น)
st.sidebar.markdown("### โ๏ธ Made by [ํ
๋๋
ธํธ](https://youtube.com/c/teddynote) ๐")
st.sidebar.markdown(
"### ๐ป [Project Page](https://github.com/teddynote-lab/langgraph-mcp-agents)"
)
st.sidebar.divider() # ๊ตฌ๋ถ์ ์ถ๊ฐ
# ๊ธฐ์กด ํ์ด์ง ํ์ดํ ๋ฐ ์ค๋ช
st.title("๐ฌ MCP ๋๊ตฌ ํ์ฉ ์์ด์ ํธ")
st.markdown("โจ MCP ๋๊ตฌ๋ฅผ ํ์ฉํ ReAct ์์ด์ ํธ์๊ฒ ์ง๋ฌธํด๋ณด์ธ์.")
SYSTEM_PROMPT = """<ROLE>
You are a smart agent with an ability to use tools.
You will be given a question and you will use the tools to answer the question.
Pick the most relevant tool to answer the question.
If you are failed to answer the question, try different tools to get context.
Your answer should be very polite and professional.
</ROLE>
----
<INSTRUCTIONS>
Step 1: Analyze the question
- Analyze user's question and final goal.
- If the user's question is consist of multiple sub-questions, split them into smaller sub-questions.
Step 2: Pick the most relevant tool
- Pick the most relevant tool to answer the question.
- If you are failed to answer the question, try different tools to get context.
Step 3: Answer the question
- Answer the question in the same language as the question.
- Your answer should be very polite and professional.
Step 4: Provide the source of the answer(if applicable)
- If you've used the tool, provide the source of the answer.
- Valid sources are either a website(URL) or a document(PDF, etc).
Guidelines:
- If you've used the tool, your answer should be based on the tool's output(tool's output is more important than your own knowledge).
- If you've used the tool, and the source is valid URL, provide the source(URL) of the answer.
- Skip providing the source if the source is not URL.
- Answer in the same language as the question.
- Answer should be concise and to the point.
- Avoid response your output with any other information than the answer and the source.
</INSTRUCTIONS>
----
<OUTPUT_FORMAT>
(concise answer to the question)
**Source**(if applicable)
- (source1: valid URL)
- (source2: valid URL)
- ...
</OUTPUT_FORMAT>
"""
OUTPUT_TOKEN_INFO = {
"claude-3-5-sonnet-latest": {"max_tokens": 8192},
"claude-3-5-haiku-latest": {"max_tokens": 8192},
"claude-3-7-sonnet-latest": {"max_tokens": 64000},
"gpt-4o": {"max_tokens": 16000},
"gpt-4o-mini": {"max_tokens": 16000},
}
# ์ธ์
์ํ ์ด๊ธฐํ
if "session_initialized" not in st.session_state:
st.session_state.session_initialized = False # ์ธ์
์ด๊ธฐํ ์ํ ํ๋๊ทธ
st.session_state.agent = None # ReAct ์์ด์ ํธ ๊ฐ์ฒด ์ ์ฅ ๊ณต๊ฐ
st.session_state.history = [] # ๋ํ ๊ธฐ๋ก ์ ์ฅ ๋ฆฌ์คํธ
st.session_state.mcp_client = None # MCP ํด๋ผ์ด์ธํธ ๊ฐ์ฒด ์ ์ฅ ๊ณต๊ฐ
st.session_state.timeout_seconds = 120 # ์๋ต ์์ฑ ์ ํ ์๊ฐ(์ด), ๊ธฐ๋ณธ๊ฐ 120์ด
st.session_state.selected_model = "claude-3-7-sonnet-latest" # ๊ธฐ๋ณธ ๋ชจ๋ธ ์ ํ
st.session_state.recursion_limit = 100 # ์ฌ๊ท ํธ์ถ ์ ํ, ๊ธฐ๋ณธ๊ฐ 100
if "thread_id" not in st.session_state:
st.session_state.thread_id = random_uuid()
# --- ํจ์ ์ ์ ๋ถ๋ถ ---
async def cleanup_mcp_client():
"""
๊ธฐ์กด MCP ํด๋ผ์ด์ธํธ๋ฅผ ์์ ํ๊ฒ ์ข
๋ฃํฉ๋๋ค.
๊ธฐ์กด ํด๋ผ์ด์ธํธ๊ฐ ์๋ ๊ฒฝ์ฐ ์ ์์ ์ผ๋ก ๋ฆฌ์์ค๋ฅผ ํด์ ํฉ๋๋ค.
"""
if "mcp_client" in st.session_state and st.session_state.mcp_client is not None:
try:
await st.session_state.mcp_client.__aexit__(None, None, None)
st.session_state.mcp_client = None
except Exception as e:
import traceback
# st.warning(f"MCP ํด๋ผ์ด์ธํธ ์ข
๋ฃ ์ค ์ค๋ฅ: {str(e)}")
# st.warning(traceback.format_exc())
def print_message():
"""
์ฑํ
๊ธฐ๋ก์ ํ๋ฉด์ ์ถ๋ ฅํฉ๋๋ค.
์ฌ์ฉ์์ ์ด์์คํดํธ์ ๋ฉ์์ง๋ฅผ ๊ตฌ๋ถํ์ฌ ํ๋ฉด์ ํ์ํ๊ณ ,
๋๊ตฌ ํธ์ถ ์ ๋ณด๋ ์ด์์คํดํธ ๋ฉ์์ง ์ปจํ
์ด๋ ๋ด์ ํ์ํฉ๋๋ค.
"""
i = 0
while i < len(st.session_state.history):
message = st.session_state.history[i]
if message["role"] == "user":
st.chat_message("user", avatar="๐งโ๐ป").markdown(message["content"])
i += 1
elif message["role"] == "assistant":
# ์ด์์คํดํธ ๋ฉ์์ง ์ปจํ
์ด๋ ์์ฑ
with st.chat_message("assistant", avatar="๐ค"):
# ์ด์์คํดํธ ๋ฉ์์ง ๋ด์ฉ ํ์
st.markdown(message["content"])
# ๋ค์ ๋ฉ์์ง๊ฐ ๋๊ตฌ ํธ์ถ ์ ๋ณด์ธ์ง ํ์ธ
if (
i + 1 < len(st.session_state.history)
and st.session_state.history[i + 1]["role"] == "assistant_tool"
):
# ๋๊ตฌ ํธ์ถ ์ ๋ณด๋ฅผ ๋์ผํ ์ปจํ
์ด๋ ๋ด์ expander๋ก ํ์
with st.expander("๐ง ๋๊ตฌ ํธ์ถ ์ ๋ณด", expanded=False):
st.markdown(st.session_state.history[i + 1]["content"])
i += 2 # ๋ ๋ฉ์์ง๋ฅผ ํจ๊ป ์ฒ๋ฆฌํ์ผ๋ฏ๋ก 2 ์ฆ๊ฐ
else:
i += 1 # ์ผ๋ฐ ๋ฉ์์ง๋ง ์ฒ๋ฆฌํ์ผ๋ฏ๋ก 1 ์ฆ๊ฐ
else:
# assistant_tool ๋ฉ์์ง๋ ์์์ ์ฒ๋ฆฌ๋๋ฏ๋ก ๊ฑด๋๋
i += 1
def get_streaming_callback(text_placeholder, tool_placeholder):
"""
์คํธ๋ฆฌ๋ฐ ์ฝ๋ฐฑ ํจ์๋ฅผ ์์ฑํฉ๋๋ค.
์ด ํจ์๋ LLM์์ ์์ฑ๋๋ ์๋ต์ ์ค์๊ฐ์ผ๋ก ํ๋ฉด์ ํ์ํ๊ธฐ ์ํ ์ฝ๋ฐฑ ํจ์๋ฅผ ์์ฑํฉ๋๋ค.
ํ
์คํธ ์๋ต๊ณผ ๋๊ตฌ ํธ์ถ ์ ๋ณด๋ฅผ ๊ฐ๊ฐ ๋ค๋ฅธ ์์ญ์ ํ์ํฉ๋๋ค.
๋งค๊ฐ๋ณ์:
text_placeholder: ํ
์คํธ ์๋ต์ ํ์ํ Streamlit ์ปดํฌ๋ํธ
tool_placeholder: ๋๊ตฌ ํธ์ถ ์ ๋ณด๋ฅผ ํ์ํ Streamlit ์ปดํฌ๋ํธ
๋ฐํ๊ฐ:
callback_func: ์คํธ๋ฆฌ๋ฐ ์ฝ๋ฐฑ ํจ์
accumulated_text: ๋์ ๋ ํ
์คํธ ์๋ต์ ์ ์ฅํ๋ ๋ฆฌ์คํธ
accumulated_tool: ๋์ ๋ ๋๊ตฌ ํธ์ถ ์ ๋ณด๋ฅผ ์ ์ฅํ๋ ๋ฆฌ์คํธ
"""
accumulated_text = []
accumulated_tool = []
def callback_func(message: dict):
nonlocal accumulated_text, accumulated_tool
message_content = message.get("content", None)
if isinstance(message_content, AIMessageChunk):
content = message_content.content
# ์ฝํ
์ธ ๊ฐ ๋ฆฌ์คํธ ํํ์ธ ๊ฒฝ์ฐ (Claude ๋ชจ๋ธ ๋ฑ์์ ์ฃผ๋ก ๋ฐ์)
if isinstance(content, list) and len(content) > 0:
message_chunk = content[0]
# ํ
์คํธ ํ์
์ธ ๊ฒฝ์ฐ ์ฒ๋ฆฌ
if message_chunk["type"] == "text":
accumulated_text.append(message_chunk["text"])
text_placeholder.markdown("".join(accumulated_text))
# ๋๊ตฌ ์ฌ์ฉ ํ์
์ธ ๊ฒฝ์ฐ ์ฒ๋ฆฌ
elif message_chunk["type"] == "tool_use":
if "partial_json" in message_chunk:
accumulated_tool.append(message_chunk["partial_json"])
else:
tool_call_chunks = message_content.tool_call_chunks
tool_call_chunk = tool_call_chunks[0]
accumulated_tool.append(
"\n```json\n" + str(tool_call_chunk) + "\n```\n"
)
with tool_placeholder.expander("๐ง ๋๊ตฌ ํธ์ถ ์ ๋ณด", expanded=True):
st.markdown("".join(accumulated_tool))
# tool_calls ์์ฑ์ด ์๋ ๊ฒฝ์ฐ ์ฒ๋ฆฌ (OpenAI ๋ชจ๋ธ ๋ฑ์์ ์ฃผ๋ก ๋ฐ์)
elif (
hasattr(message_content, "tool_calls")
and message_content.tool_calls
and len(message_content.tool_calls[0]["name"]) > 0
):
tool_call_info = message_content.tool_calls[0]
accumulated_tool.append("\n```json\n" + str(tool_call_info) + "\n```\n")
with tool_placeholder.expander("๐ง ๋๊ตฌ ํธ์ถ ์ ๋ณด", expanded=True):
st.markdown("".join(accumulated_tool))
# ๋จ์ ๋ฌธ์์ด์ธ ๊ฒฝ์ฐ ์ฒ๋ฆฌ
elif isinstance(content, str):
accumulated_text.append(content)
text_placeholder.markdown("".join(accumulated_text))
# ์ ํจํ์ง ์์ ๋๊ตฌ ํธ์ถ ์ ๋ณด๊ฐ ์๋ ๊ฒฝ์ฐ ์ฒ๋ฆฌ
elif (
hasattr(message_content, "invalid_tool_calls")
and message_content.invalid_tool_calls
):
tool_call_info = message_content.invalid_tool_calls[0]
accumulated_tool.append("\n```json\n" + str(tool_call_info) + "\n```\n")
with tool_placeholder.expander(
"๐ง ๋๊ตฌ ํธ์ถ ์ ๋ณด (์ ํจํ์ง ์์)", expanded=True
):
st.markdown("".join(accumulated_tool))
# tool_call_chunks ์์ฑ์ด ์๋ ๊ฒฝ์ฐ ์ฒ๋ฆฌ
elif (
hasattr(message_content, "tool_call_chunks")
and message_content.tool_call_chunks
):
tool_call_chunk = message_content.tool_call_chunks[0]
accumulated_tool.append(
"\n```json\n" + str(tool_call_chunk) + "\n```\n"
)
with tool_placeholder.expander("๐ง ๋๊ตฌ ํธ์ถ ์ ๋ณด", expanded=True):
st.markdown("".join(accumulated_tool))
# additional_kwargs์ tool_calls๊ฐ ์๋ ๊ฒฝ์ฐ ์ฒ๋ฆฌ (๋ค์ํ ๋ชจ๋ธ ํธํ์ฑ ์ง์)
elif (
hasattr(message_content, "additional_kwargs")
and "tool_calls" in message_content.additional_kwargs
):
tool_call_info = message_content.additional_kwargs["tool_calls"][0]
accumulated_tool.append("\n```json\n" + str(tool_call_info) + "\n```\n")
with tool_placeholder.expander("๐ง ๋๊ตฌ ํธ์ถ ์ ๋ณด", expanded=True):
st.markdown("".join(accumulated_tool))
# ๋๊ตฌ ๋ฉ์์ง์ธ ๊ฒฝ์ฐ ์ฒ๋ฆฌ (๋๊ตฌ์ ์๋ต)
elif isinstance(message_content, ToolMessage):
accumulated_tool.append(
"\n```json\n" + str(message_content.content) + "\n```\n"
)
with tool_placeholder.expander("๐ง ๋๊ตฌ ํธ์ถ ์ ๋ณด", expanded=True):
st.markdown("".join(accumulated_tool))
return None
return callback_func, accumulated_text, accumulated_tool
async def process_query(query, text_placeholder, tool_placeholder, timeout_seconds=60):
"""
์ฌ์ฉ์ ์ง๋ฌธ์ ์ฒ๋ฆฌํ๊ณ ์๋ต์ ์์ฑํฉ๋๋ค.
์ด ํจ์๋ ์ฌ์ฉ์์ ์ง๋ฌธ์ ์์ด์ ํธ์ ์ ๋ฌํ๊ณ , ์๋ต์ ์ค์๊ฐ์ผ๋ก ์คํธ๋ฆฌ๋ฐํ์ฌ ํ์ํฉ๋๋ค.
์ง์ ๋ ์๊ฐ ๋ด์ ์๋ต์ด ์๋ฃ๋์ง ์์ผ๋ฉด ํ์์์ ์ค๋ฅ๋ฅผ ๋ฐํํฉ๋๋ค.
๋งค๊ฐ๋ณ์:
query: ์ฌ์ฉ์๊ฐ ์
๋ ฅํ ์ง๋ฌธ ํ
์คํธ
text_placeholder: ํ
์คํธ ์๋ต์ ํ์ํ Streamlit ์ปดํฌ๋ํธ
tool_placeholder: ๋๊ตฌ ํธ์ถ ์ ๋ณด๋ฅผ ํ์ํ Streamlit ์ปดํฌ๋ํธ
timeout_seconds: ์๋ต ์์ฑ ์ ํ ์๊ฐ(์ด)
๋ฐํ๊ฐ:
response: ์์ด์ ํธ์ ์๋ต ๊ฐ์ฒด
final_text: ์ต์ข
ํ
์คํธ ์๋ต
final_tool: ์ต์ข
๋๊ตฌ ํธ์ถ ์ ๋ณด
"""
try:
if st.session_state.agent:
streaming_callback, accumulated_text_obj, accumulated_tool_obj = (
get_streaming_callback(text_placeholder, tool_placeholder)
)
try:
response = await asyncio.wait_for(
astream_graph(
st.session_state.agent,
{"messages": [HumanMessage(content=query)]},
callback=streaming_callback,
config=RunnableConfig(
recursion_limit=st.session_state.recursion_limit,
thread_id=st.session_state.thread_id,
),
),
timeout=timeout_seconds,
)
except asyncio.TimeoutError:
error_msg = f"โฑ๏ธ ์์ฒญ ์๊ฐ์ด {timeout_seconds}์ด๋ฅผ ์ด๊ณผํ์ต๋๋ค. ๋์ค์ ๋ค์ ์๋ํด ์ฃผ์ธ์."
return {"error": error_msg}, error_msg, ""
final_text = "".join(accumulated_text_obj)
final_tool = "".join(accumulated_tool_obj)
return response, final_text, final_tool
else:
return (
{"error": "๐ซ ์์ด์ ํธ๊ฐ ์ด๊ธฐํ๋์ง ์์์ต๋๋ค."},
"๐ซ ์์ด์ ํธ๊ฐ ์ด๊ธฐํ๋์ง ์์์ต๋๋ค.",
"",
)
except Exception as e:
import traceback
error_msg = f"โ ์ฟผ๋ฆฌ ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}\n{traceback.format_exc()}"
return {"error": error_msg}, error_msg, ""
async def initialize_session(mcp_config=None):
"""
MCP ์ธ์
๊ณผ ์์ด์ ํธ๋ฅผ ์ด๊ธฐํํฉ๋๋ค.
๋งค๊ฐ๋ณ์:
mcp_config: MCP ๋๊ตฌ ์ค์ ์ ๋ณด(JSON). None์ธ ๊ฒฝ์ฐ ๊ธฐ๋ณธ ์ค์ ์ฌ์ฉ
๋ฐํ๊ฐ:
bool: ์ด๊ธฐํ ์ฑ๊ณต ์ฌ๋ถ
"""
with st.spinner("๐ MCP ์๋ฒ์ ์ฐ๊ฒฐ ์ค..."):
# ๋จผ์ ๊ธฐ์กด ํด๋ผ์ด์ธํธ๋ฅผ ์์ ํ๊ฒ ์ ๋ฆฌ
await cleanup_mcp_client()
if mcp_config is None:
# config.json ํ์ผ์์ ์ค์ ๋ก๋
mcp_config = load_config_from_json()
client = MultiServerMCPClient(mcp_config)
await client.__aenter__()
tools = client.get_tools()
st.session_state.tool_count = len(tools)
st.session_state.mcp_client = client
# ์ ํ๋ ๋ชจ๋ธ์ ๋ฐ๋ผ ์ ์ ํ ๋ชจ๋ธ ์ด๊ธฐํ
selected_model = st.session_state.selected_model
if selected_model in [
"claude-3-7-sonnet-latest",
"claude-3-5-sonnet-latest",
"claude-3-5-haiku-latest",
]:
model = ChatAnthropic(
model=selected_model,
temperature=0.1,
max_tokens=OUTPUT_TOKEN_INFO[selected_model]["max_tokens"],
)
else: # OpenAI ๋ชจ๋ธ ์ฌ์ฉ
model = ChatOpenAI(
model=selected_model,
temperature=0.1,
max_tokens=OUTPUT_TOKEN_INFO[selected_model]["max_tokens"],
)
agent = create_react_agent(
model,
tools,
checkpointer=MemorySaver(),
prompt=SYSTEM_PROMPT,
)
st.session_state.agent = agent
st.session_state.session_initialized = True
return True
# --- ์ฌ์ด๋๋ฐ: ์์คํ
์ค์ ์น์
---
with st.sidebar:
st.subheader("โ๏ธ ์์คํ
์ค์ ")
# ๋ชจ๋ธ ์ ํ ๊ธฐ๋ฅ
# ์ฌ์ฉ ๊ฐ๋ฅํ ๋ชจ๋ธ ๋ชฉ๋ก ์์ฑ
available_models = []
# Anthropic API ํค ํ์ธ
has_anthropic_key = os.environ.get("ANTHROPIC_API_KEY") is not None
if has_anthropic_key:
available_models.extend(
[
"claude-3-7-sonnet-latest",
"claude-3-5-sonnet-latest",
"claude-3-5-haiku-latest",
]
)
# OpenAI API ํค ํ์ธ
has_openai_key = os.environ.get("OPENAI_API_KEY") is not None
if has_openai_key:
available_models.extend(["gpt-4o", "gpt-4o-mini"])
# ์ฌ์ฉ ๊ฐ๋ฅํ ๋ชจ๋ธ์ด ์๋ ๊ฒฝ์ฐ ๋ฉ์์ง ํ์
if not available_models:
st.warning(
"โ ๏ธ API ํค๊ฐ ์ค์ ๋์ง ์์์ต๋๋ค. .env ํ์ผ์ ANTHROPIC_API_KEY ๋๋ OPENAI_API_KEY๋ฅผ ์ถ๊ฐํด์ฃผ์ธ์."
)
# ๊ธฐ๋ณธ๊ฐ์ผ๋ก Claude ๋ชจ๋ธ ์ถ๊ฐ (ํค๊ฐ ์์ด๋ UI๋ฅผ ๋ณด์ฌ์ฃผ๊ธฐ ์ํจ)
available_models = ["claude-3-7-sonnet-latest"]
# ๋ชจ๋ธ ์ ํ ๋๋กญ๋ค์ด
previous_model = st.session_state.selected_model
st.session_state.selected_model = st.selectbox(
"๐ค ์ฌ์ฉํ ๋ชจ๋ธ ์ ํ",
options=available_models,
index=(
available_models.index(st.session_state.selected_model)
if st.session_state.selected_model in available_models
else 0
),
help="Anthropic ๋ชจ๋ธ์ ANTHROPIC_API_KEY๊ฐ, OpenAI ๋ชจ๋ธ์ OPENAI_API_KEY๊ฐ ํ๊ฒฝ๋ณ์๋ก ์ค์ ๋์ด์ผ ํฉ๋๋ค.",
)
# ๋ชจ๋ธ์ด ๋ณ๊ฒฝ๋์์ ๋ ์ธ์
์ด๊ธฐํ ํ์ ์๋ฆผ
if (
previous_model != st.session_state.selected_model
and st.session_state.session_initialized
):
st.warning(
"โ ๏ธ ๋ชจ๋ธ์ด ๋ณ๊ฒฝ๋์์ต๋๋ค. '์ค์ ์ ์ฉํ๊ธฐ' ๋ฒํผ์ ๋๋ฌ ๋ณ๊ฒฝ์ฌํญ์ ์ ์ฉํ์ธ์."
)
# ํ์์์ ์ค์ ์ฌ๋ผ์ด๋ ์ถ๊ฐ
st.session_state.timeout_seconds = st.slider(
"โฑ๏ธ ์๋ต ์์ฑ ์ ํ ์๊ฐ(์ด)",
min_value=60,
max_value=300,
value=st.session_state.timeout_seconds,
step=10,
help="์์ด์ ํธ๊ฐ ์๋ต์ ์์ฑํ๋ ์ต๋ ์๊ฐ์ ์ค์ ํฉ๋๋ค. ๋ณต์กํ ์์
์ ๋ ๊ธด ์๊ฐ์ด ํ์ํ ์ ์์ต๋๋ค.",
)
st.session_state.recursion_limit = st.slider(
"โฑ๏ธ ์ฌ๊ท ํธ์ถ ์ ํ(ํ์)",
min_value=10,
max_value=200,
value=st.session_state.recursion_limit,
step=10,
help="์ฌ๊ท ํธ์ถ ์ ํ ํ์๋ฅผ ์ค์ ํฉ๋๋ค. ๋๋ฌด ๋์ ๊ฐ์ ์ค์ ํ๋ฉด ๋ฉ๋ชจ๋ฆฌ ๋ถ์กฑ ๋ฌธ์ ๊ฐ ๋ฐ์ํ ์ ์์ต๋๋ค.",
)
st.divider() # ๊ตฌ๋ถ์ ์ถ๊ฐ
# ๋๊ตฌ ์ค์ ์น์
์ถ๊ฐ
st.subheader("๐ง ๋๊ตฌ ์ค์ ")
# expander ์ํ๋ฅผ ์ธ์
์ํ๋ก ๊ด๋ฆฌ
if "mcp_tools_expander" not in st.session_state:
st.session_state.mcp_tools_expander = False
# MCP ๋๊ตฌ ์ถ๊ฐ ์ธํฐํ์ด์ค
with st.expander("๐งฐ MCP ๋๊ตฌ ์ถ๊ฐ", expanded=st.session_state.mcp_tools_expander):
# config.json ํ์ผ์์ ์ค์ ๋ก๋ํ์ฌ ํ์
loaded_config = load_config_from_json()
default_config_text = json.dumps(loaded_config, indent=2, ensure_ascii=False)
# pending config๊ฐ ์์ผ๋ฉด ๊ธฐ์กด mcp_config_text ๊ธฐ๋ฐ์ผ๋ก ์์ฑ
if "pending_mcp_config" not in st.session_state:
try:
st.session_state.pending_mcp_config = loaded_config
except Exception as e:
st.error(f"์ด๊ธฐ pending config ์ค์ ์คํจ: {e}")
# ๊ฐ๋ณ ๋๊ตฌ ์ถ๊ฐ๋ฅผ ์ํ UI
st.subheader("๋๊ตฌ ์ถ๊ฐ")
st.markdown(
"""
[์ด๋ป๊ฒ ์ค์ ํ๋์?](https://teddylee777.notion.site/MCP-1d324f35d12980c8b018e12afdf545a1?pvs=4)
โ ๏ธ **์ค์**: JSON์ ๋ฐ๋์ ์ค๊ดํธ(`{}`)๋ก ๊ฐ์ธ์ผ ํฉ๋๋ค."""
)
# ๋ณด๋ค ๋ช
ํํ ์์ ์ ๊ณต
example_json = {
"github": {
"command": "npx",
"args": [
"-y",
"@smithery/cli@latest",
"run",
"@smithery-ai/github",
"--config",
'{"githubPersonalAccessToken":"your_token_here"}',
],
"transport": "stdio",
}
}
default_text = json.dumps(example_json, indent=2, ensure_ascii=False)
new_tool_json = st.text_area(
"๋๊ตฌ JSON",
default_text,
height=250,
)
# ์ถ๊ฐํ๊ธฐ ๋ฒํผ
if st.button(
"๋๊ตฌ ์ถ๊ฐ",
type="primary",
key="add_tool_button",
use_container_width=True,
):
try:
# ์
๋ ฅ๊ฐ ๊ฒ์ฆ
if not new_tool_json.strip().startswith(
"{"
) or not new_tool_json.strip().endswith("}"):
st.error("JSON์ ์ค๊ดํธ({})๋ก ์์ํ๊ณ ๋๋์ผ ํฉ๋๋ค.")
st.markdown('์ฌ๋ฐ๋ฅธ ํ์: `{ "๋๊ตฌ์ด๋ฆ": { ... } }`')
else:
# JSON ํ์ฑ
parsed_tool = json.loads(new_tool_json)
# mcpServers ํ์์ธ์ง ํ์ธํ๊ณ ์ฒ๋ฆฌ
if "mcpServers" in parsed_tool:
# mcpServers ์์ ๋ด์ฉ์ ์ต์์๋ก ์ด๋
parsed_tool = parsed_tool["mcpServers"]
st.info(
"'mcpServers' ํ์์ด ๊ฐ์ง๋์์ต๋๋ค. ์๋์ผ๋ก ๋ณํํฉ๋๋ค."
)
# ์
๋ ฅ๋ ๋๊ตฌ ์ ํ์ธ
if len(parsed_tool) == 0:
st.error("์ต์ ํ๋ ์ด์์ ๋๊ตฌ๋ฅผ ์
๋ ฅํด์ฃผ์ธ์.")
else:
# ๋ชจ๋ ๋๊ตฌ์ ๋ํด ์ฒ๋ฆฌ
success_tools = []
for tool_name, tool_config in parsed_tool.items():
# URL ํ๋ ํ์ธ ๋ฐ transport ์ค์
if "url" in tool_config:
# URL์ด ์๋ ๊ฒฝ์ฐ transport๋ฅผ "sse"๋ก ์ค์
tool_config["transport"] = "sse"
st.info(
f"'{tool_name}' ๋๊ตฌ์ URL์ด ๊ฐ์ง๋์ด transport๋ฅผ 'sse'๋ก ์ค์ ํ์ต๋๋ค."
)
elif "transport" not in tool_config:
# URL์ด ์๊ณ transport๋ ์๋ ๊ฒฝ์ฐ ๊ธฐ๋ณธ๊ฐ "stdio" ์ค์
tool_config["transport"] = "stdio"
# ํ์ ํ๋ ํ์ธ
if (
"command" not in tool_config
and "url" not in tool_config
):
st.error(
f"'{tool_name}' ๋๊ตฌ ์ค์ ์๋ 'command' ๋๋ 'url' ํ๋๊ฐ ํ์ํฉ๋๋ค."
)
elif "command" in tool_config and "args" not in tool_config:
st.error(
f"'{tool_name}' ๋๊ตฌ ์ค์ ์๋ 'args' ํ๋๊ฐ ํ์ํฉ๋๋ค."
)
elif "command" in tool_config and not isinstance(
tool_config["args"], list
):
st.error(
f"'{tool_name}' ๋๊ตฌ์ 'args' ํ๋๋ ๋ฐ๋์ ๋ฐฐ์ด([]) ํ์์ด์ด์ผ ํฉ๋๋ค."
)
else:
# pending_mcp_config์ ๋๊ตฌ ์ถ๊ฐ
st.session_state.pending_mcp_config[tool_name] = (
tool_config
)
success_tools.append(tool_name)
# ์ฑ๊ณต ๋ฉ์์ง
if success_tools:
if len(success_tools) == 1:
st.success(
f"{success_tools[0]} ๋๊ตฌ๊ฐ ์ถ๊ฐ๋์์ต๋๋ค. ์ ์ฉํ๋ ค๋ฉด '์ค์ ์ ์ฉํ๊ธฐ' ๋ฒํผ์ ๋๋ฌ์ฃผ์ธ์."
)
else:
tool_names = ", ".join(success_tools)
st.success(
f"์ด {len(success_tools)}๊ฐ ๋๊ตฌ({tool_names})๊ฐ ์ถ๊ฐ๋์์ต๋๋ค. ์ ์ฉํ๋ ค๋ฉด '์ค์ ์ ์ฉํ๊ธฐ' ๋ฒํผ์ ๋๋ฌ์ฃผ์ธ์."
)
# ์ถ๊ฐ๋๋ฉด expander๋ฅผ ์ ์ด์ค
st.session_state.mcp_tools_expander = False
st.rerun()
except json.JSONDecodeError as e:
st.error(f"JSON ํ์ฑ ์๋ฌ: {e}")
st.markdown(
f"""
**์์ ๋ฐฉ๋ฒ**:
1. JSON ํ์์ด ์ฌ๋ฐ๋ฅธ์ง ํ์ธํ์ธ์.
2. ๋ชจ๋ ํค๋ ํฐ๋ฐ์ดํ(")๋ก ๊ฐ์ธ์ผ ํฉ๋๋ค.
3. ๋ฌธ์์ด ๊ฐ๋ ํฐ๋ฐ์ดํ(")๋ก ๊ฐ์ธ์ผ ํฉ๋๋ค.
4. ๋ฌธ์์ด ๋ด์์ ํฐ๋ฐ์ดํ๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ ์ด์ค์ผ์ดํ(\\")ํด์ผ ํฉ๋๋ค.
"""
)
except Exception as e:
st.error(f"์ค๋ฅ ๋ฐ์: {e}")
# ๋ฑ๋ก๋ ๋๊ตฌ ๋ชฉ๋ก ํ์ ๋ฐ ์ญ์ ๋ฒํผ ์ถ๊ฐ
with st.expander("๐ ๋ฑ๋ก๋ ๋๊ตฌ ๋ชฉ๋ก", expanded=True):
try:
pending_config = st.session_state.pending_mcp_config
except Exception as e:
st.error("์ ํจํ MCP ๋๊ตฌ ์ค์ ์ด ์๋๋๋ค.")
else:
# pending config์ ํค(๋๊ตฌ ์ด๋ฆ) ๋ชฉ๋ก์ ์ํํ๋ฉฐ ํ์
for tool_name in list(pending_config.keys()):
col1, col2 = st.columns([8, 2])
col1.markdown(f"- **{tool_name}**")
if col2.button("์ญ์ ", key=f"delete_{tool_name}"):
# pending config์์ ํด๋น ๋๊ตฌ ์ญ์ (์ฆ์ ์ ์ฉ๋์ง๋ ์์)
del st.session_state.pending_mcp_config[tool_name]
st.success(
f"{tool_name} ๋๊ตฌ๊ฐ ์ญ์ ๋์์ต๋๋ค. ์ ์ฉํ๋ ค๋ฉด '์ค์ ์ ์ฉํ๊ธฐ' ๋ฒํผ์ ๋๋ฌ์ฃผ์ธ์."
)
st.divider() # ๊ตฌ๋ถ์ ์ถ๊ฐ
# --- ์ฌ์ด๋๋ฐ: ์์คํ
์ ๋ณด ๋ฐ ์์
๋ฒํผ ์น์
---
with st.sidebar:
st.subheader("๐ ์์คํ
์ ๋ณด")
st.write(f"๐ ๏ธ MCP ๋๊ตฌ ์: {st.session_state.get('tool_count', '์ด๊ธฐํ ์ค...')}")
selected_model_name = st.session_state.selected_model
st.write(f"๐ง ํ์ฌ ๋ชจ๋ธ: {selected_model_name}")
# ์ค์ ์ ์ฉํ๊ธฐ ๋ฒํผ์ ์ฌ๊ธฐ๋ก ์ด๋
if st.button(
"์ค์ ์ ์ฉํ๊ธฐ",
key="apply_button",
type="primary",
use_container_width=True,
):
# ์ ์ฉ ์ค ๋ฉ์์ง ํ์
apply_status = st.empty()
with apply_status.container():
st.warning("๐ ๋ณ๊ฒฝ์ฌํญ์ ์ ์ฉํ๊ณ ์์ต๋๋ค. ์ ์๋ง ๊ธฐ๋ค๋ ค์ฃผ์ธ์...")
progress_bar = st.progress(0)
# ์ค์ ์ ์ฅ
st.session_state.mcp_config_text = json.dumps(
st.session_state.pending_mcp_config, indent=2, ensure_ascii=False
)
# config.json ํ์ผ์ ์ค์ ์ ์ฅ
save_result = save_config_to_json(st.session_state.pending_mcp_config)
if not save_result:
st.error("โ ์ค์ ํ์ผ ์ ์ฅ์ ์คํจํ์ต๋๋ค.")
progress_bar.progress(15)
# ์ธ์
์ด๊ธฐํ ์ค๋น
st.session_state.session_initialized = False
st.session_state.agent = None
# ์งํ ์ํ ์
๋ฐ์ดํธ
progress_bar.progress(30)
# ์ด๊ธฐํ ์คํ
success = st.session_state.event_loop.run_until_complete(
initialize_session(st.session_state.pending_mcp_config)
)
# ์งํ ์ํ ์
๋ฐ์ดํธ
progress_bar.progress(100)
if success:
st.success("โ
์๋ก์ด ์ค์ ์ด ์ ์ฉ๋์์ต๋๋ค.")
# ๋๊ตฌ ์ถ๊ฐ expander ์ ๊ธฐ
if "mcp_tools_expander" in st.session_state:
st.session_state.mcp_tools_expander = False
else:
st.error("โ ์ค์ ์ ์ฉ์ ์คํจํ์์ต๋๋ค.")
# ํ์ด์ง ์๋ก๊ณ ์นจ
st.rerun()
st.divider() # ๊ตฌ๋ถ์ ์ถ๊ฐ
# ์์
๋ฒํผ ์น์
st.subheader("๐ ์์
")
# ๋ํ ์ด๊ธฐํ ๋ฒํผ
if st.button("๋ํ ์ด๊ธฐํ", use_container_width=True, type="primary"):
# thread_id ์ด๊ธฐํ
st.session_state.thread_id = random_uuid()
# ๋ํ ํ์คํ ๋ฆฌ ์ด๊ธฐํ
st.session_state.history = []
# ์๋ฆผ ๋ฉ์์ง
st.success("โ
๋ํ๊ฐ ์ด๊ธฐํ๋์์ต๋๋ค.")
# ํ์ด์ง ์๋ก๊ณ ์นจ
st.rerun()
# ๋ก๊ทธ์ธ ๊ธฐ๋ฅ์ด ํ์ฑํ๋ ๊ฒฝ์ฐ์๋ง ๋ก๊ทธ์์ ๋ฒํผ ํ์
if use_login and st.session_state.authenticated:
st.divider() # ๊ตฌ๋ถ์ ์ถ๊ฐ
if st.button("๋ก๊ทธ์์", use_container_width=True, type="secondary"):
st.session_state.authenticated = False
st.success("โ
๋ก๊ทธ์์ ๋์์ต๋๋ค.")
st.rerun()
# --- ๊ธฐ๋ณธ ์ธ์
์ด๊ธฐํ (์ด๊ธฐํ๋์ง ์์ ๊ฒฝ์ฐ) ---
if not st.session_state.session_initialized:
st.info(
"MCP ์๋ฒ์ ์์ด์ ํธ๊ฐ ์ด๊ธฐํ๋์ง ์์์ต๋๋ค. ์ผ์ชฝ ์ฌ์ด๋๋ฐ์ '์ค์ ์ ์ฉํ๊ธฐ' ๋ฒํผ์ ํด๋ฆญํ์ฌ ์ด๊ธฐํํด์ฃผ์ธ์."
)
# --- ๋ํ ๊ธฐ๋ก ์ถ๋ ฅ ---
print_message()
# --- ์ฌ์ฉ์ ์
๋ ฅ ๋ฐ ์ฒ๋ฆฌ ---
user_query = st.chat_input("๐ฌ ์ง๋ฌธ์ ์
๋ ฅํ์ธ์")
if user_query:
if st.session_state.session_initialized:
st.chat_message("user", avatar="๐งโ๐ป").markdown(user_query)
with st.chat_message("assistant", avatar="๐ค"):
tool_placeholder = st.empty()
text_placeholder = st.empty()
resp, final_text, final_tool = (
st.session_state.event_loop.run_until_complete(
process_query(
user_query,
text_placeholder,
tool_placeholder,
st.session_state.timeout_seconds,
)
)
)
if "error" in resp:
st.error(resp["error"])
else:
st.session_state.history.append({"role": "user", "content": user_query})
st.session_state.history.append(
{"role": "assistant", "content": final_text}
)
if final_tool.strip():
st.session_state.history.append(
{"role": "assistant_tool", "content": final_tool}
)
st.rerun()
else:
st.warning(
"โ ๏ธ MCP ์๋ฒ์ ์์ด์ ํธ๊ฐ ์ด๊ธฐํ๋์ง ์์์ต๋๋ค. ์ผ์ชฝ ์ฌ์ด๋๋ฐ์ '์ค์ ์ ์ฉํ๊ธฐ' ๋ฒํผ์ ํด๋ฆญํ์ฌ ์ด๊ธฐํํด์ฃผ์ธ์."
)
|