'+,-,*,/'}},                    'required': ['num1', 'num2', 'operation'],                    'title': 'Calculator',                    'type': 'object'}}from langchain.prompts import ChatPromptTemplatefrom langchain.chat_models import ChatOpenAIfrom langchain.output_parsers.openai_functions import PydanticOutputFunctionsParserprompt = ChatPromptTemplate.from_messages(    [        ("system", "You are an accounting assistant."),        ("user", "{input}"),    ])chain = (    prompt    | ChatOpenAI().bind(functions=[openai_function_def])    | PydanticOutputFunctionsParser(pydantic_schema=Calculator)    | (lambda x: x.calculate()))math_questions = [    "What's 45/9?",    "What's 81/9?",    "What's 72/8?",    "What's 56/7?",    "What's 36/6?",    "What's 64/8?",    "What's 12*6?",    "What's 8*8?",    "What's 10*10?",    "What's 11*11?",    "What's 13*13?",    "What's 45+30?",    "What's 72+28?",    "What's 56+44?",    "What's 63+37?",    "What's 70-35?",    "What's 60-30?",    "What's 50-25?",    "What's 40-20?",    "What's 30-15?"]results = chain.batch([{"input": q} for q in math_questions], return_exceptions=True)    Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised ServiceUnavailableError: The server is overloaded or not ready yet..Load runs that did not error‚ÄãNow we can select the successful runs to fine-tune on.from langsmith.client import Clientclient = Client()successful_traces = {    run.trace_id    for run in client.list_runs(        project_name=project_name,        execution_order=1,        error=False,    )}    llm_runs = [    run for run in client.list_runs(        project_name=project_name,        run_type="llm",    )     if run.trace_id in successful_traces]2. Prepare data‚ÄãNow we can create an instance of LangSmithRunChatLoader and load the chat sessions using its lazy_load() method.from langchain.chat_loaders.langsmith import LangSmithRunChatLoaderloader =
This notebook demonstrates how to directly load data from LangSmith's LLM runs and fine-tune a model on that data.
This notebook demonstrates how to directly load data from LangSmith's LLM runs and fine-tune a model on that data. ->: '+,-,*,/'}},                    'required': ['num1', 'num2', 'operation'],                    'title': 'Calculator',                    'type': 'object'}}from langchain.prompts import ChatPromptTemplatefrom langchain.chat_models import ChatOpenAIfrom langchain.output_parsers.openai_functions import PydanticOutputFunctionsParserprompt = ChatPromptTemplate.from_messages(    [        ("system", "You are an accounting assistant."),        ("user", "{input}"),    ])chain = (    prompt    | ChatOpenAI().bind(functions=[openai_function_def])    | PydanticOutputFunctionsParser(pydantic_schema=Calculator)    | (lambda x: x.calculate()))math_questions = [    "What's 45/9?",    "What's 81/9?",    "What's 72/8?",    "What's 56/7?",    "What's 36/6?",    "What's 64/8?",    "What's 12*6?",    "What's 8*8?",    "What's 10*10?",    "What's 11*11?",    "What's 13*13?",    "What's 45+30?",    "What's 72+28?",    "What's 56+44?",    "What's 63+37?",    "What's 70-35?",    "What's 60-30?",    "What's 50-25?",    "What's 40-20?",    "What's 30-15?"]results = chain.batch([{"input": q} for q in math_questions], return_exceptions=True)    Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised ServiceUnavailableError: The server is overloaded or not ready yet..Load runs that did not error‚ÄãNow we can select the successful runs to fine-tune on.from langsmith.client import Clientclient = Client()successful_traces = {    run.trace_id    for run in client.list_runs(        project_name=project_name,        execution_order=1,        error=False,    )}    llm_runs = [    run for run in client.list_runs(        project_name=project_name,        run_type="llm",    )     if run.trace_id in successful_traces]2. Prepare data‚ÄãNow we can create an instance of LangSmithRunChatLoader and load the chat sessions using its lazy_load() method.from langchain.chat_loaders.langsmith import LangSmithRunChatLoaderloader =