File size: 779 Bytes
0b84707
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
from langsmith import Client as LangSmithClient


_client: LangSmithClient | None = None


def _get_client() -> LangSmithClient | None:
    global _client
    if _client is None and os.getenv("LANGSMITH_API_KEY"):
        _client = LangSmithClient()
    return _client


def create_run(
    name: str,
    inputs: dict,
    outputs: dict | None = None,
    error: str | None = None,
    tags: list[str] | None = None,
    metadata: dict | None = None,
):
    client = _get_client()
    if client is None:
        return None

    run_type = "chain"

    client.create_run(
        name=name,
        inputs=inputs,
        outputs=outputs or {},
        error=error,
        run_type=run_type,
        tags=tags or [],
        extra={"metadata": metadata or {}},
    )