Arthur는 모델 모니터링 및 관찰성 플랫폼입니다.
다음 가이드는 Arthur callback handler와 함께 등록된 chat LLM을 실행하여 모델 추론을 Arthur에 자동으로 로깅하는 방법을 보여줍니다. 현재 Arthur에 온보딩된 모델이 없다면, 생성형 텍스트 모델을 위한 온보딩 가이드를 참조하세요. Arthur SDK 사용 방법에 대한 자세한 내용은 문서를 참조하세요.

Installation and Setup

Arthur 자격 증명을 여기에 입력하세요
arthur_url = "https://app.arthur.ai"
arthur_login = "your-arthur-login-username-here"
arthur_model_id = "your-arthur-model-id-here"

Callback handler

from langchain_community.callbacks import ArthurCallbackHandler
from langchain_core.callbacks import StreamingStdOutCallbackHandler
from langchain.messages import HumanMessage
from langchain_openai import ChatOpenAI
Arthur callback handler와 함께 LangChain LLM 생성
def make_langchain_chat_llm():
    return ChatOpenAI(
        streaming=True,
        temperature=0.1,
        callbacks=[
            StreamingStdOutCallbackHandler(),
            ArthurCallbackHandler.from_credentials(
                arthur_model_id, arthur_url=arthur_url, arthur_login=arthur_login
            ),
        ],
    )
chatgpt = make_langchain_chat_llm()
Please enter password for admin: ········
run function으로 chat LLM을 실행하면 대화 기록이 진행 중인 목록에 저장되어 대화가 이전 메시지를 참조할 수 있으며 각 응답이 Arthur 플랫폼에 로깅됩니다. 이 모델의 추론 기록은 모델 대시보드 페이지에서 확인할 수 있습니다. run loop를 종료하려면 q를 입력하세요
def run(llm):
    history = []
    while True:
        user_input = input("\n>>> input >>>\n>>>: ")
        if user_input == "q":
            break
        history.append(HumanMessage(content=user_input))
        history.append(llm(history))
run(chatgpt)
>>> input >>>
>>>: What is a callback handler?
A callback handler, also known as a callback function or callback method, is a piece of code that is executed in response to a specific event or condition. It is commonly used in programming languages that support event-driven or asynchronous programming paradigms.

The purpose of a callback handler is to provide a way for developers to define custom behavior that should be executed when a certain event occurs. Instead of waiting for a result or blocking the execution, the program registers a callback function and continues with other tasks. When the event is triggered, the callback function is invoked, allowing the program to respond accordingly.

Callback handlers are commonly used in various scenarios, such as handling user input, responding to network requests, processing asynchronous operations, and implementing event-driven architectures. They provide a flexible and modular way to handle events and decouple different components of a system.
>>> input >>>
>>>: What do I need to do to get the full benefits of this
To get the full benefits of using a callback handler, you should consider the following:

1. Understand the event or condition: Identify the specific event or condition that you want to respond to with a callback handler. This could be user input, network requests, or any other asynchronous operation.

2. Define the callback function: Create a function that will be executed when the event or condition occurs. This function should contain the desired behavior or actions you want to take in response to the event.

3. Register the callback function: Depending on the programming language or framework you are using, you may need to register or attach the callback function to the appropriate event or condition. This ensures that the callback function is invoked when the event occurs.

4. Handle the callback: Implement the necessary logic within the callback function to handle the event or condition. This could involve updating the user interface, processing data, making further requests, or triggering other actions.

5. Consider error handling: It's important to handle any potential errors or exceptions that may occur within the callback function. This ensures that your program can gracefully handle unexpected situations and prevent crashes or undesired behavior.

6. Maintain code readability and modularity: As your codebase grows, it's crucial to keep your callback handlers organized and maintainable. Consider using design patterns or architectural principles to structure your code in a modular and scalable way.

By following these steps, you can leverage the benefits of callback handlers, such as asynchronous and event-driven programming, improved responsiveness, and modular code design.
>>> input >>>
>>>: q

Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I