mirror of
https://github.com/langchain-ai/docs.git
synced 2026-07-19 16:33:35 -04:00
docs(langsmith): SmithDB SDK migration guide for runs query and retrieve (#4614)
## Summary Adds an unlisted migration guide at `/langsmith/smithdb-sdk-migration` for partner customers migrating from v1 SDK methods to SmithDB-backed equivalents. The page is `noindex: true` and not wired into `docs.json` nav — accessible via direct URL only. Each method's content (parameter tables, examples, and their code-sample imports) lives in its own file under `src/snippets/langsmith/smithdb-migration/` (e.g. `runs-query.mdx`, `runs-retrieve.mdx`), included into the main page via Mintlify's snippet-import pattern. Adding a new method's migration guide only requires a new snippet file plus one import and one render line in the main page, so different teams can add methods in parallel without conflicting. The code-samples generation and testing pipeline was extended to support Go and cURL/bash, alongside existing Python/TypeScript/Java/Kotlin support, so every code sample in this guide is a real, tested source file rather than hand-authored prose. --------- Co-authored-by: Kiewan Villatel <kiewan@langchain.dev> Co-authored-by: Naomi Pentrel <5212232+npentrel@users.noreply.github.com>
This commit is contained in:
@@ -114,7 +114,28 @@ public class Example {
|
||||
// :snippet-end:
|
||||
```
|
||||
|
||||
Choose a unique `snippet-name` in kebab-case. All snippet names must include a language suffix: `-py` for Python files, `-js` for TypeScript/JavaScript files, `-java` for Java files, and `-kt` for Kotlin files (for example, `tool-return-values-py`, `tool-return-values-js`, `traceable-pipeline-java`, `traceable-pipeline-kt`). This becomes the base of the output filename.
|
||||
**Go:**
|
||||
```go
|
||||
// :snippet-start: snippet-name-go
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("hello")
|
||||
}
|
||||
// :snippet-end:
|
||||
```
|
||||
|
||||
**Bash (cURL):**
|
||||
```bash
|
||||
# :snippet-start: snippet-name-sh
|
||||
curl "https://api.smith.langchain.com/api/v1/runs" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY"
|
||||
# :snippet-end:
|
||||
```
|
||||
|
||||
Choose a unique `snippet-name` in kebab-case. All snippet names must include a language suffix: `-py` for Python files, `-js` for TypeScript/JavaScript files, `-java` for Java files, `-kt` for Kotlin files, `-go` for Go files, and `-sh` for bash/cURL files (for example, `tool-return-values-py`, `tool-return-values-js`, `traceable-pipeline-java`, `traceable-pipeline-kt`, `traceable-pipeline-go`, `traceable-pipeline-sh`). This becomes the base of the output filename.
|
||||
|
||||
### 3. Add runnable test code in remove blocks
|
||||
|
||||
@@ -169,6 +190,10 @@ Java files (`.java`) under `src/code-samples/` are run using `jbang`. To keep CI
|
||||
|
||||
`make test-code-samples` runs every `.java` file under `src/code-samples/` in **lexical path order** (after all Python and TypeScript samples). That order is unrelated to section order in the docs. If one sample must run before another (for example creating a hub prompt before pulling it), name the source files so they sort correctly. For example, `manage-prompts-pull.java` runs before `manage-prompts-push.java` because `pull` sorts before `push`; use prefixes such as `manage-prompts-0-push.java` and `manage-prompts-1-pull.java` when you need push to run first.
|
||||
|
||||
Go files (`.go`) under `src/code-samples/` are run with `go run` from `src/code-samples/`, which shares a single `go.mod`/`go.sum` at that directory (add new dependencies there with `go get`, then `go mod tidy`, similar to how `.ts` samples share `src/code-samples/package.json`). `go run <file>.go` only compiles that one file, not its sibling files in the same directory, so — like Kotlin — put each snippet variant in its own file (`topic-before.go`, `topic-after.go`) rather than multiple snippets sharing one file: two files in the same package cannot both declare `func main()`. Go samples do not guard on missing keys — let the SDK call fail fast (matching Python's behavior) rather than skipping with a printed message. `make test-code-samples` runs `.go` files last, after Kotlin, in lexical path order.
|
||||
|
||||
Bash/cURL files (`.sh`) under `src/code-samples/` are run with `bash <file>.sh` from `src/code-samples/`. Like Go, put each snippet variant in its own file (`topic-before.sh`, `topic-after.sh`) rather than sharing one file. Hide test-only setup (`#!/usr/bin/env bash`, `set -euo pipefail`, resolving a real ID/value for a `<placeholder>` shown in the docs) in `# :remove-start:`/`# :remove-end:` blocks so the visible snippet is exactly the illustrative curl command a reader would copy — including no shebang or `set -e` line. `curl` does not exit non-zero on an HTTP error status by itself, so when a script pipes a response into `jq` to extract a value used by a later request (for example resolving a project ID), add a hidden check that the resolved value is non-empty and not the literal string `null` before continuing, so a bad API response fails the test loudly instead of silently propagating into later requests. `make test-code-samples` runs `.sh` files last, after Go, in lexical path order.
|
||||
|
||||
Check formatting with:
|
||||
|
||||
```bash
|
||||
@@ -230,8 +255,8 @@ Replace the inline code blocks with the snippet components:
|
||||
|
||||
| Element | Convention | Example |
|
||||
|--------|-------------|---------|
|
||||
| Code file | Descriptive, kebab-case | `return-a-string.py`, `return-a-string.ts`, `traceable-pipeline.java`, `traceable-pipeline.kt` |
|
||||
| Snippet name | Kebab-case with language suffix: `-py` for Python, `-js` for JS/TS, `-java` for Java, `-kt` for Kotlin | `tool-return-values-py`, `tool-return-values-js`, `traceable-pipeline-java`, `traceable-pipeline-kt` |
|
||||
| Code file | Descriptive, kebab-case | `return-a-string.py`, `return-a-string.ts`, `traceable-pipeline.java`, `traceable-pipeline.kt`, `traceable-pipeline.go`, `traceable-pipeline.sh` |
|
||||
| Snippet name | Kebab-case with language suffix: `-py` for Python, `-js` for JS/TS, `-java` for Java, `-kt` for Kotlin, `-go` for Go, `-sh` for bash/cURL | `tool-return-values-py`, `tool-return-values-js`, `traceable-pipeline-java`, `traceable-pipeline-kt`, `traceable-pipeline-go`, `traceable-pipeline-sh` |
|
||||
| MDX snippet (Python) | `{snippet-name}.mdx` (snippet name ends in `-py`) | `tool-return-values-py.mdx` |
|
||||
| MDX snippet (JS) | `{snippet-name}.mdx` (snippet name ends in `-js`) | `tool-return-values-js.mdx` |
|
||||
| Component name | PascalCase | `ToolReturnValuesPy`, `ToolReturnValuesJs` |
|
||||
|
||||
@@ -62,14 +62,14 @@ jobs:
|
||||
fi
|
||||
|
||||
FILES=$(git diff --name-only "$BASE" HEAD -- src/code-samples/ \
|
||||
| grep -E '\.(py|ts|java|kt)$' \
|
||||
| grep -E '\.(py|ts|java|kt|go|sh)$' \
|
||||
| tr '\n' ' ' || true)
|
||||
|
||||
{ echo "files<<FILESEND"; echo "$FILES"; echo "FILESEND"; } >> "$GITHUB_OUTPUT"
|
||||
if [[ -n "$FILES" ]]; then
|
||||
echo "Modified code samples: $FILES"
|
||||
else
|
||||
echo "No modified .py, .ts, .java, or .kt files in src/code-samples/"
|
||||
echo "No modified .py, .ts, .java, .kt, .go, or .sh files in src/code-samples/"
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -95,6 +95,11 @@ jobs:
|
||||
- name: Install JBang
|
||||
uses: jbangdev/setup-jbang@v0.1.1
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version-file: src/code-samples/go.mod
|
||||
|
||||
- name: Wait for PostgreSQL
|
||||
run: |
|
||||
for i in $(seq 1 30); do
|
||||
|
||||
@@ -30,6 +30,7 @@ dependencies = [
|
||||
"langchain-quickjs>=0.3.2",
|
||||
"langgraph>=1.2.5",
|
||||
"langgraph-checkpoint-sqlite>=3.1.0",
|
||||
"langsmith>=0.9.6",
|
||||
]
|
||||
|
||||
|
||||
|
||||
@@ -11,8 +11,10 @@ Supported markers (same as this repo's Bluehawk usage):
|
||||
- ``# :snippet-start: <id>`` / ``# :snippet-end:`` (Python)
|
||||
- ``// :snippet-start: <id>`` / ``// :snippet-end:`` (TypeScript, Java)
|
||||
- ``// :snippet-start: <id>`` / ``// :snippet-end:`` (Kotlin)
|
||||
- ``# :remove-start:`` / ``# :remove-end:`` inside Python snippet bodies
|
||||
- ``// :remove-start:`` / ``// :remove-end:`` inside TypeScript/Java snippet bodies
|
||||
- ``// :snippet-start: <id>`` / ``// :snippet-end:`` (Go)
|
||||
- ``# :snippet-start: <id>`` / ``# :snippet-end:`` (bash)
|
||||
- ``# :remove-start:`` / ``# :remove-end:`` inside Python/bash snippet bodies
|
||||
- ``// :remove-start:`` / ``// :remove-end:`` inside TypeScript/Java/Kotlin/Go snippet bodies
|
||||
|
||||
Output files match Bluehawk: ``<source-basename>.snippet.<snippet-id>.<ext>`` in
|
||||
``src/code-samples-generated/``.
|
||||
@@ -23,7 +25,7 @@ or via ``make code-snippets``.
|
||||
Optional environment variable:
|
||||
|
||||
- ``CODE_SNIPPET_SOURCES``: space-separated repo-relative paths under ``src/code-samples/``
|
||||
(``.py``, ``.ts``, ``.java``, ``.kt``). When set, only those files are extracted; existing
|
||||
(``.py``, ``.ts``, ``.java``, ``.kt``, ``.go``, ``.sh``). When set, only those files are extracted; existing
|
||||
generated snippet files for those stems are replaced. Other stems in
|
||||
``src/code-samples-generated/`` are left unchanged. Use ``make code-snippets-langsmith``
|
||||
for the LangSmith JVM subset.
|
||||
@@ -81,10 +83,10 @@ def extract_snippets(
|
||||
language: str,
|
||||
) -> list[tuple[str, str]]:
|
||||
"""Return (snippet_id, body) for each ``:snippet-start:`` block in *text*."""
|
||||
if language == "python":
|
||||
if language in ("python", "bash", "shell", "sh"):
|
||||
start_re, end_re = _RE_SNIP_START_PY, _RE_SNIP_END_PY
|
||||
rs, re_ = _RE_REMOVE_START_PY, _RE_REMOVE_END_PY
|
||||
elif language in ("ts", "typescript", "javascript", "java", "kotlin"):
|
||||
elif language in ("ts", "typescript", "javascript", "java", "kotlin", "go"):
|
||||
start_re, end_re = _RE_SNIP_START_TS, _RE_SNIP_END_TS
|
||||
rs, re_ = _RE_REMOVE_START_TS, _RE_REMOVE_END_TS
|
||||
else:
|
||||
@@ -138,6 +140,14 @@ def _iter_source_files(root: Path) -> list[Path]:
|
||||
if "node_modules" in path.parts:
|
||||
continue
|
||||
out.append(path)
|
||||
for path in sorted(root.rglob("*.go")):
|
||||
if "node_modules" in path.parts:
|
||||
continue
|
||||
out.append(path)
|
||||
for path in sorted(root.rglob("*.sh")):
|
||||
if "node_modules" in path.parts:
|
||||
continue
|
||||
out.append(path)
|
||||
return out
|
||||
|
||||
|
||||
@@ -150,7 +160,11 @@ def _language_for_path(path: Path) -> str:
|
||||
return "java"
|
||||
if path.suffix == ".kt":
|
||||
return "kotlin"
|
||||
msg = f"expected .py, .ts, .java, or .kt, got {path.suffix!r}"
|
||||
if path.suffix == ".go":
|
||||
return "go"
|
||||
if path.suffix == ".sh":
|
||||
return "bash"
|
||||
msg = f"expected .py, .ts, .java, .kt, .go, or .sh, got {path.suffix!r}"
|
||||
raise ValueError(msg)
|
||||
|
||||
|
||||
@@ -162,11 +176,13 @@ def _normalize_newlines(s: str) -> str:
|
||||
return s
|
||||
|
||||
|
||||
def _delete_snippet_outputs_for_source(out_dir: Path, source_path: Path) -> None:
|
||||
def _delete_snippet_outputs_for_source(out_dir: Path, source_path: Path, code_samples: Path) -> None:
|
||||
"""Remove previously generated snippet files for one source file stem."""
|
||||
stem = source_path.stem
|
||||
ext = source_path.suffix.lstrip(".")
|
||||
for p in out_dir.glob(f"{stem}.snippet.*.{ext}"):
|
||||
rel = source_path.relative_to(code_samples)
|
||||
search_dir = out_dir / rel.parts[-2] if len(rel.parts) > 2 else out_dir
|
||||
for p in search_dir.glob(f"{stem}.snippet.*.{ext}"):
|
||||
if p.is_file():
|
||||
p.unlink()
|
||||
|
||||
@@ -188,8 +204,8 @@ def _resolve_partial_sources(repo_root: Path, code_samples: Path) -> list[Path]
|
||||
except ValueError as e:
|
||||
msg = f"CODE_SNIPPET_SOURCES must be under {code_samples}: {part}"
|
||||
raise ValueError(msg) from e
|
||||
if path.suffix not in (".py", ".ts", ".java", ".kt"):
|
||||
msg = f"CODE_SNIPPET_SOURCES must be .py, .ts, .java, or .kt: {part}"
|
||||
if path.suffix not in (".py", ".ts", ".java", ".kt", ".go", ".sh"):
|
||||
msg = f"CODE_SNIPPET_SOURCES must be .py, .ts, .java, .kt, .go, or .sh: {part}"
|
||||
raise ValueError(msg)
|
||||
out.append(path)
|
||||
return out
|
||||
@@ -213,13 +229,13 @@ def main() -> int:
|
||||
return 1
|
||||
|
||||
if partial_sources is None:
|
||||
for p in list(out_dir.iterdir()):
|
||||
if p.suffix in (".py", ".ts", ".java", ".kt") and p.is_file():
|
||||
for p in out_dir.rglob("*"):
|
||||
if p.suffix in (".py", ".ts", ".java", ".kt", ".go", ".sh") and p.is_file():
|
||||
p.unlink()
|
||||
paths_to_process = _iter_source_files(code_samples)
|
||||
else:
|
||||
for src in partial_sources:
|
||||
_delete_snippet_outputs_for_source(out_dir, src)
|
||||
_delete_snippet_outputs_for_source(out_dir, src, code_samples)
|
||||
paths_to_process = partial_sources
|
||||
|
||||
written: list[Path] = []
|
||||
@@ -237,7 +253,10 @@ def main() -> int:
|
||||
return 1
|
||||
for snippet_id, body in pairs:
|
||||
body = _normalize_newlines(body)
|
||||
out_path = out_dir / f"{path.stem}.snippet.{snippet_id}.{path.suffix.lstrip('.')}"
|
||||
rel = path.relative_to(code_samples)
|
||||
out_subdir = out_dir / rel.parts[-2] if len(rel.parts) > 2 else out_dir
|
||||
out_subdir.mkdir(parents=True, exist_ok=True)
|
||||
out_path = out_subdir / f"{path.stem}.snippet.{snippet_id}.{path.suffix.lstrip('.')}"
|
||||
out_path.write_text(body, encoding="utf-8", newline="\n")
|
||||
written.append(out_path)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Generate MDX snippet files from extracted code snippet files.
|
||||
|
||||
Reads .snippet.*.py, .snippet.*.ts, .snippet.*.java, and .snippet.*.kt files from src/code-samples-generated/
|
||||
Reads .snippet.*.py, .snippet.*.ts, .snippet.*.java, .snippet.*.kt, .snippet.*.go, and .snippet.*.sh files from src/code-samples-generated/
|
||||
(produced by ``scripts/extract_code_snippets.py``, Bluehawk-compatible layout).
|
||||
and creates corresponding MDX files in src/snippets/code-samples/ for use in docs.
|
||||
|
||||
@@ -255,12 +255,21 @@ def main() -> None:
|
||||
("*.snippet.*.ts", "ts", "ts"),
|
||||
("*.snippet.*.java", "java", "java"),
|
||||
("*.snippet.*.kt", "kotlin", "kotlin"),
|
||||
("*.snippet.*.go", "go", "go"),
|
||||
("*.snippet.*.sh", "bash", "bash"),
|
||||
]
|
||||
|
||||
lang_suffix = {"python": "-py", "ts": "-js", "java": "-java", "kotlin": "-kt"}
|
||||
lang_suffix = {
|
||||
"python": "-py",
|
||||
"ts": "-js",
|
||||
"java": "-java",
|
||||
"kotlin": "-kt",
|
||||
"go": "-go",
|
||||
"bash": "-sh",
|
||||
}
|
||||
|
||||
for glob_pattern, language, fence_lang in snippet_configs:
|
||||
for snippet_file in generated_dir.glob(glob_pattern):
|
||||
for snippet_file in generated_dir.rglob(glob_pattern):
|
||||
snippet_name = ".".join(snippet_file.stem.split(".")[2:])
|
||||
expected_suffix = lang_suffix[language]
|
||||
if not snippet_name.endswith(expected_suffix):
|
||||
@@ -270,7 +279,10 @@ def main() -> None:
|
||||
mdx_content = format_snippet_mdx(
|
||||
content, language=language, fence_lang=fence_lang
|
||||
)
|
||||
mdx_path = snippets_dir / f"{snippet_name}.mdx"
|
||||
rel_parent = snippet_file.parent.relative_to(generated_dir)
|
||||
out_subdir = snippets_dir / rel_parent
|
||||
out_subdir.mkdir(parents=True, exist_ok=True)
|
||||
mdx_path = out_subdir / f"{snippet_name}.mdx"
|
||||
mdx_path.write_text(mdx_content, encoding="utf-8")
|
||||
print(f"Generated {mdx_path.relative_to(repo_root)}")
|
||||
|
||||
|
||||
@@ -54,8 +54,10 @@ def collect_files_to_test(
|
||||
if not path.exists():
|
||||
print(f"Warning: {path} not found, skipping")
|
||||
continue
|
||||
if path.suffix not in (".py", ".ts", ".java", ".kt"):
|
||||
print(f"Warning: {path} not .py, .ts, .java, or .kt, skipping")
|
||||
if path.suffix not in (".py", ".ts", ".java", ".kt", ".go", ".sh"):
|
||||
print(
|
||||
f"Warning: {path} not .py, .ts, .java, .kt, .go, or .sh, skipping"
|
||||
)
|
||||
continue
|
||||
if code_samples_dir.resolve() not in path.parents:
|
||||
print(f"Warning: {path} not under src/code-samples/, skipping")
|
||||
@@ -66,8 +68,12 @@ def collect_files_to_test(
|
||||
lang = "ts"
|
||||
elif path.suffix == ".java":
|
||||
lang = "java"
|
||||
else:
|
||||
elif path.suffix == ".kt":
|
||||
lang = "kotlin"
|
||||
elif path.suffix == ".go":
|
||||
lang = "go"
|
||||
else:
|
||||
lang = "bash"
|
||||
result.append((path, lang))
|
||||
return result
|
||||
|
||||
@@ -92,11 +98,23 @@ def collect_files_to_test(
|
||||
for p in code_samples_dir.rglob("*.kt")
|
||||
if is_valid_sample(p, code_samples_dir)
|
||||
)
|
||||
go_files = sorted(
|
||||
p
|
||||
for p in code_samples_dir.rglob("*.go")
|
||||
if is_valid_sample(p, code_samples_dir)
|
||||
)
|
||||
sh_files = sorted(
|
||||
p
|
||||
for p in code_samples_dir.rglob("*.sh")
|
||||
if is_valid_sample(p, code_samples_dir)
|
||||
)
|
||||
return (
|
||||
[(p, "python") for p in py_files]
|
||||
+ [(p, "ts") for p in ts_files]
|
||||
+ [(p, "java") for p in java_files]
|
||||
+ [(p, "kotlin") for p in kt_files]
|
||||
+ [(p, "go") for p in go_files]
|
||||
+ [(p, "bash") for p in sh_files]
|
||||
)
|
||||
|
||||
|
||||
@@ -114,7 +132,7 @@ def main() -> int:
|
||||
if total == 0:
|
||||
if os.environ.get("FILES"):
|
||||
print(
|
||||
"No valid files to test. Check that paths exist under src/code-samples/ and use .py or .ts"
|
||||
"No valid files to test. Check that paths exist under src/code-samples/ and use .py, .ts, .java, .kt, .go, or .sh"
|
||||
)
|
||||
else:
|
||||
print("No code samples found in src/code-samples/")
|
||||
@@ -161,6 +179,34 @@ def main() -> int:
|
||||
success = result.returncode == 0
|
||||
stdout = result.stdout or ""
|
||||
stderr = result.stderr or ""
|
||||
elif lang == "go":
|
||||
# Go: run from code-samples dir so the shared go.mod resolves deps
|
||||
result = subprocess.run(
|
||||
["go", "run", str(file_path.relative_to(code_samples_dir))],
|
||||
check=False,
|
||||
cwd=str(code_samples_dir),
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=TIMEOUT_SECONDS,
|
||||
env=env,
|
||||
)
|
||||
success = result.returncode == 0
|
||||
stdout = result.stdout or ""
|
||||
stderr = result.stderr or ""
|
||||
elif lang == "bash":
|
||||
# Shell/cURL samples: run from code-samples dir for consistency with ts/go
|
||||
result = subprocess.run(
|
||||
["bash", str(file_path.relative_to(code_samples_dir))],
|
||||
check=False,
|
||||
cwd=str(code_samples_dir),
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=TIMEOUT_SECONDS,
|
||||
env=env,
|
||||
)
|
||||
success = result.returncode == 0
|
||||
stdout = result.stdout or ""
|
||||
stderr = result.stderr or ""
|
||||
else:
|
||||
# Java/Kotlin via JBang (single-file scripts).
|
||||
#
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
module github.com/langchain-ai/docs-code-samples
|
||||
|
||||
go 1.25.0
|
||||
|
||||
require github.com/langchain-ai/langsmith-go v0.17.0
|
||||
|
||||
require (
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||
github.com/go-logr/logr v1.4.3 // indirect
|
||||
github.com/go-logr/stdr v1.2.2 // indirect
|
||||
github.com/google/uuid v1.6.0 // indirect
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 // indirect
|
||||
github.com/klauspost/compress v1.19.0 // indirect
|
||||
github.com/tidwall/gjson v1.19.0 // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.1 // indirect
|
||||
github.com/tidwall/sjson v1.2.5 // indirect
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
||||
go.opentelemetry.io/otel v1.44.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.44.0 // indirect
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.44.0 // indirect
|
||||
go.opentelemetry.io/otel/metric v1.44.0 // indirect
|
||||
go.opentelemetry.io/otel/sdk v1.44.0 // indirect
|
||||
go.opentelemetry.io/otel/trace v1.44.0 // indirect
|
||||
go.opentelemetry.io/proto/otlp v1.10.0 // indirect
|
||||
golang.org/x/net v0.55.0 // indirect
|
||||
golang.org/x/sys v0.45.0 // indirect
|
||||
golang.org/x/text v0.37.0 // indirect
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa // indirect
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa // indirect
|
||||
google.golang.org/grpc v1.81.1 // indirect
|
||||
google.golang.org/protobuf v1.36.11 // indirect
|
||||
)
|
||||
@@ -0,0 +1,75 @@
|
||||
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
||||
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
||||
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 h1:5VipnvEpbqr2gA2VbM+nYVbkIF28c5ZQfqCBQ5g2xfk=
|
||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0/go.mod h1:Hyl3n6Twe1hvtd9XUXDec4pTvgMSEixRuQKPTMH2bNs=
|
||||
github.com/klauspost/compress v1.19.0 h1:sXLILfc9jV2QYWkzFOPWStmcUVH2RHEB1JCdY2oVvCQ=
|
||||
github.com/klauspost/compress v1.19.0/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
|
||||
github.com/langchain-ai/langsmith-go v0.17.0 h1:fZWO0tm/hB9CiaG+e8CQR2wPTZnsuZZrWKrC/14OCcE=
|
||||
github.com/langchain-ai/langsmith-go v0.17.0/go.mod h1:2NXq2u8YbQkpP9BaKG7RKs0g0ZoCeqVzAZsBu7nr58Y=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/gjson v1.19.0 h1:xwxm7n691Uf3u5OFjzngavjGTh55KX5q/9w9xHW88JU=
|
||||
github.com/tidwall/gjson v1.19.0/go.mod h1:V37/opeE/JbLUOfH0QTXiNez2l0RUjYUhpT4szFQAfc=
|
||||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
|
||||
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
|
||||
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||
go.opentelemetry.io/otel v1.44.0 h1:JjwHmHpA4iZ3wBxluu2fbbE7j4kqlE8jXyAyPXH7HqU=
|
||||
go.opentelemetry.io/otel v1.44.0/go.mod h1:BMgjTHL9WPRlRjL2oZCBTL4whCGtXch2H4BhOPIAyYc=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.44.0 h1:4YsVu3B8+3qtWYYrsUYgn0OG78pN0rnNPRGX4SbokQI=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.44.0/go.mod h1:+wnlSn0mD1ADVMe3v9Z/WIaiz6q6gL2J/ejaAmdmv80=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.44.0 h1:lgh3PiVrRUWMLOVSkQicxzZll5NjF1r+AtsX1XRIHw0=
|
||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.44.0/go.mod h1:5Cnhth3m/AgOeTgE3ex12pPmiu/gGtZit03kSzx9X7s=
|
||||
go.opentelemetry.io/otel/metric v1.44.0 h1:1w0gILTcHdr3YI+ixLyjemwrVnsMURbTZFrSYCdDdmc=
|
||||
go.opentelemetry.io/otel/metric v1.44.0/go.mod h1:8O7hanEPBNgEMmybD3s2VBKcgWOCsA6tzHBPODAiquo=
|
||||
go.opentelemetry.io/otel/sdk v1.44.0 h1:nHYwb9lK+fJPU/dnT6s7W7Z8itMWyqrnVfbheVYrZ58=
|
||||
go.opentelemetry.io/otel/sdk v1.44.0/go.mod h1:Osuydd3Se74nqjAKxid74N5eC+jfEqfTegHRnq58oK0=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.44.0 h1:3LlKgI+VjbVsjNRFZJZAJ30WjXC5VkNRks6si09iEfI=
|
||||
go.opentelemetry.io/otel/sdk/metric v1.44.0/go.mod h1:5B5pMARnXxKhltooO4xUuCBorl65a4EpnTalObqOigA=
|
||||
go.opentelemetry.io/otel/trace v1.44.0 h1:jxF5CsGYCe74MCRx2X4g7WsY/VBKRqqpNvXlX/6gtIk=
|
||||
go.opentelemetry.io/otel/trace v1.44.0/go.mod h1:oLl1jrMQAVo6v3GAggN+1VH9VIz9iUSvW53sW1Q8PIE=
|
||||
go.opentelemetry.io/proto/otlp v1.10.0 h1:IQRWgT5srOCYfiWnpqUYz9CVmbO8bFmKcwYxpuCSL2g=
|
||||
go.opentelemetry.io/proto/otlp v1.10.0/go.mod h1:/CV4QoCR/S9yaPj8utp3lvQPoqMtxXdzn7ozvvozVqk=
|
||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||
golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8=
|
||||
golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww=
|
||||
golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
|
||||
golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc=
|
||||
golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38=
|
||||
gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
|
||||
gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa h1:Kjn0N0tCrDgiAFW+lGO4JZ3ck44CehvJQMAwj9QF0G8=
|
||||
google.golang.org/genproto/googleapis/api v0.0.0-20260526163538-3dc84a4a5aaa/go.mod h1:q4lMZS6kskjT5HvCPrnnypcDPVJqT/f4nfxmkE7gryY=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa h1:mZHHdPZl0dbGHCflZgAq/Q468DWVFcU2whhB2KAo8fk=
|
||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
|
||||
google.golang.org/grpc v1.81.1 h1:VnnIIZ88UzOOKLukQi+ImGz8O1Wdp8nAGGnvOfEIWQQ=
|
||||
google.golang.org/grpc v1.81.1/go.mod h1:xGH9GfzOyMTGIOXBJmXt+BX/V0kcdQbdcuwQ/zNw42I=
|
||||
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
|
||||
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
@@ -0,0 +1,43 @@
|
||||
// :snippet-start: runs-query-boolean-filters-after-go
|
||||
// :codegroup-tab: After
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/langchain-ai/langsmith-go"
|
||||
)
|
||||
|
||||
// :remove-start:
|
||||
func main() {
|
||||
// :remove-end:
|
||||
ctx := context.Background()
|
||||
client := langsmith.NewClient()
|
||||
|
||||
sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{
|
||||
Name: langsmith.F("default"),
|
||||
Limit: langsmith.F(int64(1)),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
project := sessions.Items[0]
|
||||
|
||||
filterStr := `and(gt(start_time, "2023-07-15T12:34:56Z"), or(neq(status, "error"), and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))`
|
||||
runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{
|
||||
ProjectIDs: langsmith.F([]string{project.ID}),
|
||||
Filter: langsmith.F(filterStr),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
_ = runs
|
||||
// :remove-end:
|
||||
// :remove-start:
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,35 @@
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//JAVA 21
|
||||
//KOTLIN 2.2.0
|
||||
//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11
|
||||
|
||||
// :snippet-start: runs-query-boolean-filters-after-kt
|
||||
// :codegroup-tab: After
|
||||
import com.langchain.smith.client.LangsmithClient
|
||||
import com.langchain.smith.client.okhttp.LangsmithOkHttpClient
|
||||
import com.langchain.smith.models.runs.RunQueryV2Params
|
||||
import com.langchain.smith.models.sessions.SessionListParams
|
||||
|
||||
// :remove-start:
|
||||
fun main() {
|
||||
if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) {
|
||||
println("[smithdb-runs-query-boolean-filters-after] Skipping (LANGSMITH_API_KEY is not set).")
|
||||
return
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
val client: LangsmithClient = LangsmithOkHttpClient.fromEnv()
|
||||
|
||||
val project = client.sessions().list(
|
||||
SessionListParams.builder().name("default").limit(1L).build()
|
||||
).items().first()
|
||||
val filterStr = "and(gt(start_time, \"2023-07-15T12:34:56Z\")," +
|
||||
" or(neq(status, \"error\")," +
|
||||
" and(eq(feedback_key, \"Correctness\"), eq(feedback_score, 0.0))))"
|
||||
val runs = client.runs().queryV2(
|
||||
RunQueryV2Params.builder().addProjectId(project.id()).filter(filterStr).build()
|
||||
).items()
|
||||
// :remove-start:
|
||||
}
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# :snippet-start: runs-query-boolean-filters-after-sh
|
||||
PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id')
|
||||
# :remove-start:
|
||||
[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; }
|
||||
# :remove-end:
|
||||
|
||||
FILTER='and(gt(start_time, "2023-07-15T12:34:56Z"), or(neq(status, "error"), and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))'
|
||||
|
||||
curl -X POST "https://api.smith.langchain.com/v2/runs/query" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg pid "$PROJECT_ID" --arg f "$FILTER" '{"project_ids": [$pid], "filter": $f}')"
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,18 @@
|
||||
|
||||
// :snippet-start: runs-query-boolean-filters-after-js
|
||||
// :codegroup-tab: After
|
||||
import { Client } from "langsmith";
|
||||
|
||||
const client = new Client();
|
||||
const filterStr =
|
||||
'and(gt(start_time, "2023-07-15T12:34:56Z"),' +
|
||||
' or(neq(status, "error"),' +
|
||||
' and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))';
|
||||
const project = await client.projects
|
||||
.list({ name: "default", limit: 1 })
|
||||
.then((page) => page.getPaginatedItems()[0]);
|
||||
const runs = client.runs.query({
|
||||
project_ids: [project.id],
|
||||
filter: filterStr,
|
||||
});
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,43 @@
|
||||
// :snippet-start: runs-query-boolean-filters-before-go
|
||||
// :codegroup-tab: Before
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/langchain-ai/langsmith-go"
|
||||
)
|
||||
|
||||
// :remove-start:
|
||||
func main() {
|
||||
// :remove-end:
|
||||
ctx := context.Background()
|
||||
client := langsmith.NewClient()
|
||||
|
||||
sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{
|
||||
Name: langsmith.F("default"),
|
||||
Limit: langsmith.F(int64(1)),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
project := sessions.Items[0]
|
||||
|
||||
filterStr := `and(gt(start_time, "2023-07-15T12:34:56Z"), or(neq(status, "error"), and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))`
|
||||
runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{
|
||||
Session: langsmith.F([]string{project.ID}),
|
||||
Filter: langsmith.F(filterStr),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
_ = runs
|
||||
// :remove-end:
|
||||
// :remove-start:
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,35 @@
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//JAVA 21
|
||||
//KOTLIN 2.2.0
|
||||
//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11
|
||||
|
||||
// :snippet-start: runs-query-boolean-filters-before-kt
|
||||
// :codegroup-tab: Before
|
||||
import com.langchain.smith.client.LangsmithClient
|
||||
import com.langchain.smith.client.okhttp.LangsmithOkHttpClient
|
||||
import com.langchain.smith.models.runs.RunQueryParams
|
||||
import com.langchain.smith.models.sessions.SessionListParams
|
||||
|
||||
// :remove-start:
|
||||
fun main() {
|
||||
if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) {
|
||||
println("[smithdb-runs-query-boolean-filters-before] Skipping (LANGSMITH_API_KEY is not set).")
|
||||
return
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
val client: LangsmithClient = LangsmithOkHttpClient.fromEnv()
|
||||
|
||||
val project = client.sessions().list(
|
||||
SessionListParams.builder().name("default").limit(1L).build()
|
||||
).items().first()
|
||||
val filterStr = "and(gt(start_time, \"2023-07-15T12:34:56Z\")," +
|
||||
" or(neq(status, \"error\")," +
|
||||
" and(eq(feedback_key, \"Correctness\"), eq(feedback_score, 0.0))))"
|
||||
val runs = client.runs().query(
|
||||
RunQueryParams.builder().addSession(project.id()).filter(filterStr).build()
|
||||
).items()
|
||||
// :remove-start:
|
||||
}
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# :snippet-start: runs-query-boolean-filters-before-sh
|
||||
PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id')
|
||||
# :remove-start:
|
||||
[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; }
|
||||
# :remove-end:
|
||||
|
||||
FILTER='and(gt(start_time, "2023-07-15T12:34:56Z"), or(neq(status, "error"), and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))'
|
||||
|
||||
curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg pid "$PROJECT_ID" --arg f "$FILTER" '{"session": [$pid], "filter": $f}')"
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
// :snippet-start: runs-query-boolean-filters-before-js
|
||||
// :codegroup-tab: Before
|
||||
import { Client } from "langsmith";
|
||||
|
||||
const client = new Client();
|
||||
const filterStr =
|
||||
'and(gt(start_time, "2023-07-15T12:34:56Z"),' +
|
||||
' or(neq(status, "error"),' +
|
||||
' and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))';
|
||||
const runs = client.listRuns({ projectName: "default", filter: filterStr });
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
# :snippet-start: runs-query-boolean-filters-before-py
|
||||
# :codegroup-tab: Before
|
||||
from langsmith import Client
|
||||
|
||||
client = Client()
|
||||
filter_str = (
|
||||
'and(gt(start_time, "2023-07-15T12:34:56Z"),'
|
||||
' or(neq(status, "error"),'
|
||||
' and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))'
|
||||
)
|
||||
runs = client.list_runs(project_name="default", filter=filter_str)
|
||||
# :snippet-end:
|
||||
|
||||
# :snippet-start: runs-query-boolean-filters-after-py
|
||||
# :codegroup-tab: After
|
||||
import asyncio
|
||||
|
||||
from langsmith import Client
|
||||
|
||||
|
||||
async def main():
|
||||
client = Client()
|
||||
filter_str = (
|
||||
'and(gt(start_time, "2023-07-15T12:34:56Z"),'
|
||||
' or(neq(status, "error"),'
|
||||
' and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))'
|
||||
)
|
||||
async for project in client.projects.list(name="default", limit=1):
|
||||
break
|
||||
runs = client.runs.query(project_ids=[str(project.id)], filter=filter_str)
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,55 @@
|
||||
// :snippet-start: runs-query-fetch-by-id-after-go
|
||||
// :codegroup-tab: After
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/langchain-ai/langsmith-go"
|
||||
)
|
||||
|
||||
// :remove-start:
|
||||
func main() {
|
||||
// :remove-end:
|
||||
ctx := context.Background()
|
||||
client := langsmith.NewClient()
|
||||
|
||||
sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{
|
||||
Name: langsmith.F("default"),
|
||||
Limit: langsmith.F(int64(1)),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
project := sessions.Items[0]
|
||||
|
||||
runID1 := "<run-id-1>"
|
||||
runID2 := "<run-id-2>"
|
||||
// :remove-start:
|
||||
found, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{
|
||||
ProjectIDs: langsmith.F([]string{project.ID}),
|
||||
PageSize: langsmith.F(int64(2)),
|
||||
})
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
runID1 = found.Items[0].ID
|
||||
runID2 = found.Items[1].ID
|
||||
// :remove-end:
|
||||
runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{
|
||||
ProjectIDs: langsmith.F([]string{project.ID}),
|
||||
IDs: langsmith.F([]string{runID1, runID2}),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
_ = runs
|
||||
// :remove-end:
|
||||
// :remove-start:
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,36 @@
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//JAVA 21
|
||||
//KOTLIN 2.2.0
|
||||
//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11
|
||||
|
||||
// :snippet-start: runs-query-fetch-by-id-after-kt
|
||||
// :codegroup-tab: After
|
||||
import com.langchain.smith.client.LangsmithClient
|
||||
import com.langchain.smith.client.okhttp.LangsmithOkHttpClient
|
||||
import com.langchain.smith.models.runs.RunQueryV2Params
|
||||
import com.langchain.smith.models.sessions.SessionListParams
|
||||
|
||||
// :remove-start:
|
||||
fun main() {
|
||||
if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) {
|
||||
println("[smithdb-runs-query-fetch-by-id-after] Skipping (LANGSMITH_API_KEY is not set).")
|
||||
return
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
val client: LangsmithClient = LangsmithOkHttpClient.fromEnv()
|
||||
|
||||
val project = client.sessions().list(
|
||||
SessionListParams.builder().name("default").limit(1L).build()
|
||||
).items().first()
|
||||
val runs = client.runs().queryV2(
|
||||
RunQueryV2Params.builder()
|
||||
.addProjectId(project.id())
|
||||
.addId("<run-id-1>")
|
||||
.addId("<run-id-2>")
|
||||
.build()
|
||||
).items()
|
||||
// :remove-start:
|
||||
}
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# :snippet-start: runs-query-fetch-by-id-after-sh
|
||||
PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id')
|
||||
# :remove-start:
|
||||
[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; }
|
||||
# :remove-end:
|
||||
|
||||
RUN_ID_1="<run-id-1>"
|
||||
RUN_ID_2="<run-id-2>"
|
||||
# :remove-start:
|
||||
FOUND=$(curl -s -X POST "https://api.smith.langchain.com/v2/runs/query" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg pid "$PROJECT_ID" '{"project_ids": [$pid], "page_size": 2}')")
|
||||
RUN_ID_1=$(echo "$FOUND" | jq -r '.items[0].id')
|
||||
RUN_ID_2=$(echo "$FOUND" | jq -r '.items[1].id')
|
||||
[ -n "$RUN_ID_1" ] && [ "$RUN_ID_1" != "null" ] || { echo "error: could not resolve a run id" >&2; exit 1; }
|
||||
[ -n "$RUN_ID_2" ] && [ "$RUN_ID_2" != "null" ] || { echo "error: could not resolve a run id" >&2; exit 1; }
|
||||
# :remove-end:
|
||||
|
||||
curl -X POST "https://api.smith.langchain.com/v2/runs/query" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg pid "$PROJECT_ID" --arg r1 "$RUN_ID_1" --arg r2 "$RUN_ID_2" '{"project_ids": [$pid], "ids": [$r1, $r2]}')"
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
// :snippet-start: runs-query-fetch-by-id-after-js
|
||||
// :codegroup-tab: After
|
||||
import { Client } from "langsmith";
|
||||
|
||||
const client = new Client();
|
||||
const project = await client.projects
|
||||
.list({ name: "default", limit: 1 })
|
||||
.then((page) => page.getPaginatedItems()[0]);
|
||||
const runs = client.runs.query({
|
||||
project_ids: [project.id],
|
||||
ids: ["<run-id-1>", "<run-id-2>"],
|
||||
});
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,55 @@
|
||||
// :snippet-start: runs-query-fetch-by-id-before-go
|
||||
// :codegroup-tab: Before
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/langchain-ai/langsmith-go"
|
||||
)
|
||||
|
||||
// :remove-start:
|
||||
func main() {
|
||||
// :remove-end:
|
||||
ctx := context.Background()
|
||||
client := langsmith.NewClient()
|
||||
|
||||
sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{
|
||||
Name: langsmith.F("default"),
|
||||
Limit: langsmith.F(int64(1)),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
project := sessions.Items[0]
|
||||
|
||||
runID1 := "<run-id-1>"
|
||||
runID2 := "<run-id-2>"
|
||||
// :remove-start:
|
||||
found, err := client.Runs.Query(ctx, langsmith.RunQueryParams{
|
||||
Session: langsmith.F([]string{project.ID}),
|
||||
Limit: langsmith.F(int64(2)),
|
||||
})
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
runID1 = found.Runs[0].ID
|
||||
runID2 = found.Runs[1].ID
|
||||
// :remove-end:
|
||||
runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{
|
||||
Session: langsmith.F([]string{project.ID}),
|
||||
ID: langsmith.F([]string{runID1, runID2}),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
_ = runs
|
||||
// :remove-end:
|
||||
// :remove-start:
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,45 @@
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//JAVA 21
|
||||
//KOTLIN 2.2.0
|
||||
//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11
|
||||
|
||||
// :snippet-start: runs-query-fetch-by-id-before-kt
|
||||
// :codegroup-tab: Before
|
||||
import com.langchain.smith.client.LangsmithClient
|
||||
import com.langchain.smith.client.okhttp.LangsmithOkHttpClient
|
||||
import com.langchain.smith.models.runs.RunQueryParams
|
||||
import com.langchain.smith.models.sessions.SessionListParams
|
||||
|
||||
// :remove-start:
|
||||
fun main() {
|
||||
if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) {
|
||||
println("[smithdb-runs-query-fetch-by-id-before] Skipping (LANGSMITH_API_KEY is not set).")
|
||||
return
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
val client: LangsmithClient = LangsmithOkHttpClient.fromEnv()
|
||||
|
||||
val project = client.sessions().list(
|
||||
SessionListParams.builder().name("default").limit(1L).build()
|
||||
).items().first()
|
||||
var runId1 = "<run-id-1>"
|
||||
var runId2 = "<run-id-2>"
|
||||
// :remove-start:
|
||||
val foundRuns = client.runs().query(
|
||||
RunQueryParams.builder().addSession(project.id()).limit(2L).build()
|
||||
).items()
|
||||
runId1 = foundRuns[0].id()
|
||||
runId2 = foundRuns[1].id()
|
||||
// :remove-end:
|
||||
val runs = client.runs().query(
|
||||
RunQueryParams.builder()
|
||||
.addSession(project.id())
|
||||
.addId(runId1)
|
||||
.addId(runId2)
|
||||
.build()
|
||||
).items()
|
||||
// :remove-start:
|
||||
}
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# :snippet-start: runs-query-fetch-by-id-before-sh
|
||||
RUN_ID_1="<run-id-1>"
|
||||
RUN_ID_2="<run-id-2>"
|
||||
# :remove-start:
|
||||
PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id')
|
||||
[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; }
|
||||
FOUND=$(curl -s -X POST "https://api.smith.langchain.com/api/v1/runs/query" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg pid "$PROJECT_ID" '{"session": [$pid], "limit": 2}')")
|
||||
RUN_ID_1=$(echo "$FOUND" | jq -r '.runs[0].id')
|
||||
RUN_ID_2=$(echo "$FOUND" | jq -r '.runs[1].id')
|
||||
[ -n "$RUN_ID_1" ] && [ "$RUN_ID_1" != "null" ] || { echo "error: could not resolve a run id" >&2; exit 1; }
|
||||
[ -n "$RUN_ID_2" ] && [ "$RUN_ID_2" != "null" ] || { echo "error: could not resolve a run id" >&2; exit 1; }
|
||||
# :remove-end:
|
||||
|
||||
curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg r1 "$RUN_ID_1" --arg r2 "$RUN_ID_2" '{"id": [$r1, $r2]}')"
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
// :snippet-start: runs-query-fetch-by-id-before-js
|
||||
// :codegroup-tab: Before
|
||||
import { Client } from "langsmith";
|
||||
|
||||
const client = new Client();
|
||||
const runs = client.listRuns({ id: ["<run-id-1>", "<run-id-2>"] });
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,28 @@
|
||||
|
||||
# :snippet-start: runs-query-fetch-by-id-before-py
|
||||
# :codegroup-tab: Before
|
||||
from langsmith import Client
|
||||
|
||||
client = Client()
|
||||
runs = client.list_runs(id=["<run-id-1>", "<run-id-2>"])
|
||||
# :snippet-end:
|
||||
|
||||
# :snippet-start: runs-query-fetch-by-id-after-py
|
||||
# :codegroup-tab: After
|
||||
import asyncio
|
||||
|
||||
from langsmith import Client
|
||||
|
||||
|
||||
async def main():
|
||||
client = Client()
|
||||
async for project in client.projects.list(name="default", limit=1):
|
||||
break
|
||||
runs = client.runs.query(
|
||||
project_ids=[str(project.id)],
|
||||
ids=["<run-id-1>", "<run-id-2>"],
|
||||
)
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,42 @@
|
||||
// :snippet-start: runs-query-filter-errors-after-go
|
||||
// :codegroup-tab: After
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/langchain-ai/langsmith-go"
|
||||
)
|
||||
|
||||
// :remove-start:
|
||||
func main() {
|
||||
// :remove-end:
|
||||
ctx := context.Background()
|
||||
client := langsmith.NewClient()
|
||||
|
||||
sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{
|
||||
Name: langsmith.F("default"),
|
||||
Limit: langsmith.F(int64(1)),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
project := sessions.Items[0]
|
||||
|
||||
runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{
|
||||
ProjectIDs: langsmith.F([]string{project.ID}),
|
||||
HasError: langsmith.F(true),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
_ = runs
|
||||
// :remove-end:
|
||||
// :remove-start:
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,32 @@
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//JAVA 21
|
||||
//KOTLIN 2.2.0
|
||||
//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11
|
||||
|
||||
// :snippet-start: runs-query-filter-errors-after-kt
|
||||
// :codegroup-tab: After
|
||||
import com.langchain.smith.client.LangsmithClient
|
||||
import com.langchain.smith.client.okhttp.LangsmithOkHttpClient
|
||||
import com.langchain.smith.models.runs.RunQueryV2Params
|
||||
import com.langchain.smith.models.sessions.SessionListParams
|
||||
|
||||
// :remove-start:
|
||||
fun main() {
|
||||
if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) {
|
||||
println("[smithdb-runs-query-filter-errors-after] Skipping (LANGSMITH_API_KEY is not set).")
|
||||
return
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
val client: LangsmithClient = LangsmithOkHttpClient.fromEnv()
|
||||
|
||||
val project = client.sessions().list(
|
||||
SessionListParams.builder().name("default").limit(1L).build()
|
||||
).items().first()
|
||||
val runs = client.runs().queryV2(
|
||||
RunQueryV2Params.builder().addProjectId(project.id()).hasError(true).build()
|
||||
).items()
|
||||
// :remove-start:
|
||||
}
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# :snippet-start: runs-query-filter-errors-after-sh
|
||||
PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id')
|
||||
# :remove-start:
|
||||
[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; }
|
||||
# :remove-end:
|
||||
|
||||
curl -X POST "https://api.smith.langchain.com/v2/runs/query" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg pid "$PROJECT_ID" '{"project_ids": [$pid], "has_error": true}')"
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
// :snippet-start: runs-query-filter-errors-after-js
|
||||
// :codegroup-tab: After
|
||||
import { Client } from "langsmith";
|
||||
|
||||
const client = new Client();
|
||||
const project = await client.projects
|
||||
.list({ name: "default", limit: 1 })
|
||||
.then((page) => page.getPaginatedItems()[0]);
|
||||
const runs = client.runs.query({
|
||||
project_ids: [project.id],
|
||||
has_error: true,
|
||||
});
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,42 @@
|
||||
// :snippet-start: runs-query-filter-errors-before-go
|
||||
// :codegroup-tab: Before
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/langchain-ai/langsmith-go"
|
||||
)
|
||||
|
||||
// :remove-start:
|
||||
func main() {
|
||||
// :remove-end:
|
||||
ctx := context.Background()
|
||||
client := langsmith.NewClient()
|
||||
|
||||
sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{
|
||||
Name: langsmith.F("default"),
|
||||
Limit: langsmith.F(int64(1)),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
project := sessions.Items[0]
|
||||
|
||||
runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{
|
||||
Session: langsmith.F([]string{project.ID}),
|
||||
Error: langsmith.F(true),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
_ = runs
|
||||
// :remove-end:
|
||||
// :remove-start:
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,32 @@
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//JAVA 21
|
||||
//KOTLIN 2.2.0
|
||||
//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11
|
||||
|
||||
// :snippet-start: runs-query-filter-errors-before-kt
|
||||
// :codegroup-tab: Before
|
||||
import com.langchain.smith.client.LangsmithClient
|
||||
import com.langchain.smith.client.okhttp.LangsmithOkHttpClient
|
||||
import com.langchain.smith.models.runs.RunQueryParams
|
||||
import com.langchain.smith.models.sessions.SessionListParams
|
||||
|
||||
// :remove-start:
|
||||
fun main() {
|
||||
if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) {
|
||||
println("[smithdb-runs-query-filter-errors-before] Skipping (LANGSMITH_API_KEY is not set).")
|
||||
return
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
val client: LangsmithClient = LangsmithOkHttpClient.fromEnv()
|
||||
|
||||
val project = client.sessions().list(
|
||||
SessionListParams.builder().name("default").limit(1L).build()
|
||||
).items().first()
|
||||
val runs = client.runs().query(
|
||||
RunQueryParams.builder().addSession(project.id()).error(true).build()
|
||||
).items()
|
||||
// :remove-start:
|
||||
}
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# :snippet-start: runs-query-filter-errors-before-sh
|
||||
PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id')
|
||||
# :remove-start:
|
||||
[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; }
|
||||
# :remove-end:
|
||||
|
||||
curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg pid "$PROJECT_ID" '{"session": [$pid], "error": true}')"
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
// :snippet-start: runs-query-filter-errors-before-js
|
||||
// :codegroup-tab: Before
|
||||
import { Client } from "langsmith";
|
||||
|
||||
const client = new Client();
|
||||
const runs = client.listRuns({ projectName: "default", error: true });
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
# :snippet-start: runs-query-filter-errors-before-py
|
||||
# :codegroup-tab: Before
|
||||
from langsmith import Client
|
||||
|
||||
client = Client()
|
||||
runs = client.list_runs(project_name="default", error=True)
|
||||
# :snippet-end:
|
||||
|
||||
# :snippet-start: runs-query-filter-errors-after-py
|
||||
# :codegroup-tab: After
|
||||
import asyncio
|
||||
|
||||
from langsmith import Client
|
||||
|
||||
|
||||
async def main():
|
||||
client = Client()
|
||||
async for project in client.projects.list(name="default", limit=1):
|
||||
break
|
||||
runs = client.runs.query(project_ids=[str(project.id)], has_error=True)
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,43 @@
|
||||
// :snippet-start: runs-query-filter-metadata-after-go
|
||||
// :codegroup-tab: After
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/langchain-ai/langsmith-go"
|
||||
)
|
||||
|
||||
// :remove-start:
|
||||
func main() {
|
||||
// :remove-end:
|
||||
ctx := context.Background()
|
||||
client := langsmith.NewClient()
|
||||
|
||||
sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{
|
||||
Name: langsmith.F("default"),
|
||||
Limit: langsmith.F(int64(1)),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
project := sessions.Items[0]
|
||||
|
||||
filterStr := `and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))`
|
||||
runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{
|
||||
ProjectIDs: langsmith.F([]string{project.ID}),
|
||||
Filter: langsmith.F(filterStr),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
_ = runs
|
||||
// :remove-end:
|
||||
// :remove-start:
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,33 @@
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//JAVA 21
|
||||
//KOTLIN 2.2.0
|
||||
//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11
|
||||
|
||||
// :snippet-start: runs-query-filter-metadata-after-kt
|
||||
// :codegroup-tab: After
|
||||
import com.langchain.smith.client.LangsmithClient
|
||||
import com.langchain.smith.client.okhttp.LangsmithOkHttpClient
|
||||
import com.langchain.smith.models.runs.RunQueryV2Params
|
||||
import com.langchain.smith.models.sessions.SessionListParams
|
||||
|
||||
// :remove-start:
|
||||
fun main() {
|
||||
if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) {
|
||||
println("[smithdb-runs-query-filter-metadata-after] Skipping (LANGSMITH_API_KEY is not set).")
|
||||
return
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
val client: LangsmithClient = LangsmithOkHttpClient.fromEnv()
|
||||
|
||||
val project = client.sessions().list(
|
||||
SessionListParams.builder().name("default").limit(1L).build()
|
||||
).items().first()
|
||||
val filterStr = "and(eq(metadata_key, \"user_id\"), eq(metadata_value, \"u_123\"))"
|
||||
val runs = client.runs().queryV2(
|
||||
RunQueryV2Params.builder().addProjectId(project.id()).filter(filterStr).build()
|
||||
).items()
|
||||
// :remove-start:
|
||||
}
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# :snippet-start: runs-query-filter-metadata-after-sh
|
||||
PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id')
|
||||
# :remove-start:
|
||||
[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; }
|
||||
# :remove-end:
|
||||
|
||||
FILTER='and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))'
|
||||
|
||||
curl -X POST "https://api.smith.langchain.com/v2/runs/query" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg pid "$PROJECT_ID" --arg f "$FILTER" '{"project_ids": [$pid], "filter": $f}')"
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// :snippet-start: runs-query-filter-metadata-after-js
|
||||
// :codegroup-tab: After
|
||||
import { Client } from "langsmith";
|
||||
|
||||
const client = new Client();
|
||||
const filterStr = 'and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))';
|
||||
const project = await client.projects
|
||||
.list({ name: "default", limit: 1 })
|
||||
.then((page) => page.getPaginatedItems()[0]);
|
||||
const runs = client.runs.query({
|
||||
project_ids: [project.id],
|
||||
filter: filterStr,
|
||||
});
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,43 @@
|
||||
// :snippet-start: runs-query-filter-metadata-before-go
|
||||
// :codegroup-tab: Before
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/langchain-ai/langsmith-go"
|
||||
)
|
||||
|
||||
// :remove-start:
|
||||
func main() {
|
||||
// :remove-end:
|
||||
ctx := context.Background()
|
||||
client := langsmith.NewClient()
|
||||
|
||||
sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{
|
||||
Name: langsmith.F("default"),
|
||||
Limit: langsmith.F(int64(1)),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
project := sessions.Items[0]
|
||||
|
||||
filterStr := `and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))`
|
||||
runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{
|
||||
Session: langsmith.F([]string{project.ID}),
|
||||
Filter: langsmith.F(filterStr),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
_ = runs
|
||||
// :remove-end:
|
||||
// :remove-start:
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,33 @@
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//JAVA 21
|
||||
//KOTLIN 2.2.0
|
||||
//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11
|
||||
|
||||
// :snippet-start: runs-query-filter-metadata-before-kt
|
||||
// :codegroup-tab: Before
|
||||
import com.langchain.smith.client.LangsmithClient
|
||||
import com.langchain.smith.client.okhttp.LangsmithOkHttpClient
|
||||
import com.langchain.smith.models.runs.RunQueryParams
|
||||
import com.langchain.smith.models.sessions.SessionListParams
|
||||
|
||||
// :remove-start:
|
||||
fun main() {
|
||||
if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) {
|
||||
println("[smithdb-runs-query-filter-metadata-before] Skipping (LANGSMITH_API_KEY is not set).")
|
||||
return
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
val client: LangsmithClient = LangsmithOkHttpClient.fromEnv()
|
||||
|
||||
val project = client.sessions().list(
|
||||
SessionListParams.builder().name("default").limit(1L).build()
|
||||
).items().first()
|
||||
val filterStr = "and(eq(metadata_key, \"user_id\"), eq(metadata_value, \"u_123\"))"
|
||||
val runs = client.runs().query(
|
||||
RunQueryParams.builder().addSession(project.id()).filter(filterStr).build()
|
||||
).items()
|
||||
// :remove-start:
|
||||
}
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# :snippet-start: runs-query-filter-metadata-before-sh
|
||||
PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id')
|
||||
# :remove-start:
|
||||
[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; }
|
||||
# :remove-end:
|
||||
|
||||
FILTER='and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))'
|
||||
|
||||
curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg pid "$PROJECT_ID" --arg f "$FILTER" '{"session": [$pid], "filter": $f}')"
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,9 @@
|
||||
|
||||
// :snippet-start: runs-query-filter-metadata-before-js
|
||||
// :codegroup-tab: Before
|
||||
import { Client } from "langsmith";
|
||||
|
||||
const client = new Client();
|
||||
const filterStr = 'and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))';
|
||||
const runs = client.listRuns({ projectName: "default", filter: filterStr });
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,27 @@
|
||||
|
||||
# :snippet-start: runs-query-filter-metadata-before-py
|
||||
# :codegroup-tab: Before
|
||||
from langsmith import Client
|
||||
|
||||
client = Client()
|
||||
filter_str = 'and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))'
|
||||
runs = client.list_runs(project_name="default", filter=filter_str)
|
||||
# :snippet-end:
|
||||
|
||||
# :snippet-start: runs-query-filter-metadata-after-py
|
||||
# :codegroup-tab: After
|
||||
import asyncio
|
||||
|
||||
from langsmith import Client
|
||||
|
||||
|
||||
async def main():
|
||||
client = Client()
|
||||
filter_str = 'and(eq(metadata_key, "user_id"), eq(metadata_value, "u_123"))'
|
||||
async for project in client.projects.list(name="default", limit=1):
|
||||
break
|
||||
runs = client.runs.query(project_ids=[str(project.id)], filter=filter_str)
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,42 @@
|
||||
// :snippet-start: runs-query-filter-root-after-go
|
||||
// :codegroup-tab: After
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/langchain-ai/langsmith-go"
|
||||
)
|
||||
|
||||
// :remove-start:
|
||||
func main() {
|
||||
// :remove-end:
|
||||
ctx := context.Background()
|
||||
client := langsmith.NewClient()
|
||||
|
||||
sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{
|
||||
Name: langsmith.F("default"),
|
||||
Limit: langsmith.F(int64(1)),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
project := sessions.Items[0]
|
||||
|
||||
runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{
|
||||
ProjectIDs: langsmith.F([]string{project.ID}),
|
||||
IsRoot: langsmith.F(true),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
_ = runs
|
||||
// :remove-end:
|
||||
// :remove-start:
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,32 @@
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//JAVA 21
|
||||
//KOTLIN 2.2.0
|
||||
//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11
|
||||
|
||||
// :snippet-start: runs-query-filter-root-after-kt
|
||||
// :codegroup-tab: After
|
||||
import com.langchain.smith.client.LangsmithClient
|
||||
import com.langchain.smith.client.okhttp.LangsmithOkHttpClient
|
||||
import com.langchain.smith.models.runs.RunQueryV2Params
|
||||
import com.langchain.smith.models.sessions.SessionListParams
|
||||
|
||||
// :remove-start:
|
||||
fun main() {
|
||||
if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) {
|
||||
println("[smithdb-runs-query-filter-root-after] Skipping (LANGSMITH_API_KEY is not set).")
|
||||
return
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
val client: LangsmithClient = LangsmithOkHttpClient.fromEnv()
|
||||
|
||||
val project = client.sessions().list(
|
||||
SessionListParams.builder().name("default").limit(1L).build()
|
||||
).items().first()
|
||||
val runs = client.runs().queryV2(
|
||||
RunQueryV2Params.builder().addProjectId(project.id()).isRoot(true).build()
|
||||
).items()
|
||||
// :remove-start:
|
||||
}
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# :snippet-start: runs-query-filter-root-after-sh
|
||||
PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id')
|
||||
# :remove-start:
|
||||
[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; }
|
||||
# :remove-end:
|
||||
|
||||
curl -X POST "https://api.smith.langchain.com/v2/runs/query" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg pid "$PROJECT_ID" '{"project_ids": [$pid], "is_root": true}')"
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
// :snippet-start: runs-query-filter-root-after-js
|
||||
// :codegroup-tab: After
|
||||
import { Client } from "langsmith";
|
||||
|
||||
const client = new Client();
|
||||
const project = await client.projects
|
||||
.list({ name: "default", limit: 1 })
|
||||
.then((page) => page.getPaginatedItems()[0]);
|
||||
const runs = client.runs.query({
|
||||
project_ids: [project.id],
|
||||
is_root: true,
|
||||
});
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,42 @@
|
||||
// :snippet-start: runs-query-filter-root-before-go
|
||||
// :codegroup-tab: Before
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/langchain-ai/langsmith-go"
|
||||
)
|
||||
|
||||
// :remove-start:
|
||||
func main() {
|
||||
// :remove-end:
|
||||
ctx := context.Background()
|
||||
client := langsmith.NewClient()
|
||||
|
||||
sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{
|
||||
Name: langsmith.F("default"),
|
||||
Limit: langsmith.F(int64(1)),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
project := sessions.Items[0]
|
||||
|
||||
runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{
|
||||
Session: langsmith.F([]string{project.ID}),
|
||||
IsRoot: langsmith.F(true),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
_ = runs
|
||||
// :remove-end:
|
||||
// :remove-start:
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,32 @@
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//JAVA 21
|
||||
//KOTLIN 2.2.0
|
||||
//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11
|
||||
|
||||
// :snippet-start: runs-query-filter-root-before-kt
|
||||
// :codegroup-tab: Before
|
||||
import com.langchain.smith.client.LangsmithClient
|
||||
import com.langchain.smith.client.okhttp.LangsmithOkHttpClient
|
||||
import com.langchain.smith.models.runs.RunQueryParams
|
||||
import com.langchain.smith.models.sessions.SessionListParams
|
||||
|
||||
// :remove-start:
|
||||
fun main() {
|
||||
if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) {
|
||||
println("[smithdb-runs-query-filter-root-before] Skipping (LANGSMITH_API_KEY is not set).")
|
||||
return
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
val client: LangsmithClient = LangsmithOkHttpClient.fromEnv()
|
||||
|
||||
val project = client.sessions().list(
|
||||
SessionListParams.builder().name("default").limit(1L).build()
|
||||
).items().first()
|
||||
val runs = client.runs().query(
|
||||
RunQueryParams.builder().addSession(project.id()).isRoot(true).build()
|
||||
).items()
|
||||
// :remove-start:
|
||||
}
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# :snippet-start: runs-query-filter-root-before-sh
|
||||
PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id')
|
||||
# :remove-start:
|
||||
[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; }
|
||||
# :remove-end:
|
||||
|
||||
curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg pid "$PROJECT_ID" '{"session": [$pid], "is_root": true}')"
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
// :snippet-start: runs-query-filter-root-before-js
|
||||
// :codegroup-tab: Before
|
||||
import { Client } from "langsmith";
|
||||
|
||||
const client = new Client();
|
||||
const runs = client.listRuns({ projectName: "default", isRoot: true });
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
# :snippet-start: runs-query-filter-root-before-py
|
||||
# :codegroup-tab: Before
|
||||
from langsmith import Client
|
||||
|
||||
client = Client()
|
||||
runs = client.list_runs(project_name="default", is_root=True)
|
||||
# :snippet-end:
|
||||
|
||||
# :snippet-start: runs-query-filter-root-after-py
|
||||
# :codegroup-tab: After
|
||||
import asyncio
|
||||
|
||||
from langsmith import Client
|
||||
|
||||
|
||||
async def main():
|
||||
client = Client()
|
||||
async for project in client.projects.list(name="default", limit=1):
|
||||
break
|
||||
runs = client.runs.query(project_ids=[str(project.id)], is_root=True)
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,44 @@
|
||||
// :snippet-start: runs-query-filter-time-range-after-go
|
||||
// :codegroup-tab: After
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/langchain-ai/langsmith-go"
|
||||
)
|
||||
|
||||
// :remove-start:
|
||||
func main() {
|
||||
// :remove-end:
|
||||
ctx := context.Background()
|
||||
client := langsmith.NewClient()
|
||||
|
||||
sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{
|
||||
Name: langsmith.F("default"),
|
||||
Limit: langsmith.F(int64(1)),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
project := sessions.Items[0]
|
||||
|
||||
runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{
|
||||
ProjectIDs: langsmith.F([]string{project.ID}),
|
||||
MinStartTime: langsmith.F(time.Now().Add(-24 * time.Hour)),
|
||||
RunType: langsmith.F(langsmith.RunQueryV2ParamsRunTypeLlm),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
_ = runs
|
||||
// :remove-end:
|
||||
// :remove-start:
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,38 @@
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//JAVA 21
|
||||
//KOTLIN 2.2.0
|
||||
//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11
|
||||
|
||||
// :snippet-start: runs-query-filter-time-range-after-kt
|
||||
// :codegroup-tab: After
|
||||
import java.time.OffsetDateTime
|
||||
|
||||
import com.langchain.smith.client.LangsmithClient
|
||||
import com.langchain.smith.client.okhttp.LangsmithOkHttpClient
|
||||
import com.langchain.smith.models.runs.RunQueryV2Params
|
||||
import com.langchain.smith.models.sessions.SessionListParams
|
||||
|
||||
// :remove-start:
|
||||
fun main() {
|
||||
if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) {
|
||||
println("[smithdb-runs-query-filter-time-range-after] Skipping (LANGSMITH_API_KEY is not set).")
|
||||
return
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
val client: LangsmithClient = LangsmithOkHttpClient.fromEnv()
|
||||
|
||||
val project = client.sessions().list(
|
||||
SessionListParams.builder().name("default").limit(1L).build()
|
||||
).items().first()
|
||||
val runs = client.runs().queryV2(
|
||||
RunQueryV2Params.builder()
|
||||
.addProjectId(project.id())
|
||||
.minStartTime(OffsetDateTime.now().minusDays(1))
|
||||
.runType(RunQueryV2Params.RunType.LLM)
|
||||
.build()
|
||||
).items()
|
||||
// :remove-start:
|
||||
}
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# :snippet-start: runs-query-filter-time-range-after-sh
|
||||
PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id')
|
||||
# :remove-start:
|
||||
[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; }
|
||||
# :remove-end:
|
||||
|
||||
curl -X POST "https://api.smith.langchain.com/v2/runs/query" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg pid "$PROJECT_ID" '{"project_ids": [$pid], "run_type": "LLM", "min_start_time": "2025-01-01T00:00:00Z"}')"
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
// :snippet-start: runs-query-filter-time-range-after-js
|
||||
// :codegroup-tab: After
|
||||
import { Client } from "langsmith";
|
||||
|
||||
const client = new Client();
|
||||
const project = await client.projects
|
||||
.list({ name: "default", limit: 1 })
|
||||
.then((page) => page.getPaginatedItems()[0]);
|
||||
const oneDayAgo = new Date(Date.now() - 24 * 60 * 60 * 1000);
|
||||
const runs = client.runs.query({
|
||||
project_ids: [project.id],
|
||||
min_start_time: oneDayAgo.toISOString(),
|
||||
run_type: "LLM",
|
||||
});
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,44 @@
|
||||
// :snippet-start: runs-query-filter-time-range-before-go
|
||||
// :codegroup-tab: Before
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/langchain-ai/langsmith-go"
|
||||
)
|
||||
|
||||
// :remove-start:
|
||||
func main() {
|
||||
// :remove-end:
|
||||
ctx := context.Background()
|
||||
client := langsmith.NewClient()
|
||||
|
||||
sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{
|
||||
Name: langsmith.F("default"),
|
||||
Limit: langsmith.F(int64(1)),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
project := sessions.Items[0]
|
||||
|
||||
runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{
|
||||
Session: langsmith.F([]string{project.ID}),
|
||||
StartTime: langsmith.F(time.Now().Add(-24 * time.Hour)),
|
||||
RunType: langsmith.F(langsmith.RunTypeEnumLlm),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
_ = runs
|
||||
// :remove-end:
|
||||
// :remove-start:
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,39 @@
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//JAVA 21
|
||||
//KOTLIN 2.2.0
|
||||
//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11
|
||||
|
||||
// :snippet-start: runs-query-filter-time-range-before-kt
|
||||
// :codegroup-tab: Before
|
||||
import java.time.OffsetDateTime
|
||||
|
||||
import com.langchain.smith.client.LangsmithClient
|
||||
import com.langchain.smith.client.okhttp.LangsmithOkHttpClient
|
||||
import com.langchain.smith.models.runs.RunQueryParams
|
||||
import com.langchain.smith.models.runs.RunTypeEnum
|
||||
import com.langchain.smith.models.sessions.SessionListParams
|
||||
|
||||
// :remove-start:
|
||||
fun main() {
|
||||
if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) {
|
||||
println("[smithdb-runs-query-filter-time-range-before] Skipping (LANGSMITH_API_KEY is not set).")
|
||||
return
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
val client: LangsmithClient = LangsmithOkHttpClient.fromEnv()
|
||||
|
||||
val project = client.sessions().list(
|
||||
SessionListParams.builder().name("default").limit(1L).build()
|
||||
).items().first()
|
||||
val runs = client.runs().query(
|
||||
RunQueryParams.builder()
|
||||
.addSession(project.id())
|
||||
.startTime(OffsetDateTime.now().minusDays(1))
|
||||
.runType(RunTypeEnum.LLM)
|
||||
.build()
|
||||
).items()
|
||||
// :remove-start:
|
||||
}
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# :snippet-start: runs-query-filter-time-range-before-sh
|
||||
PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id')
|
||||
# :remove-start:
|
||||
[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; }
|
||||
# :remove-end:
|
||||
|
||||
curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg pid "$PROJECT_ID" '{"session": [$pid], "run_type": "llm", "start_time": "2025-01-01T00:00:00Z"}')"
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
// :snippet-start: runs-query-filter-time-range-before-js
|
||||
// :codegroup-tab: Before
|
||||
import { Client } from "langsmith";
|
||||
|
||||
const client = new Client();
|
||||
const runs = client.listRuns({
|
||||
projectName: "default",
|
||||
startTime: new Date(Date.now() - 24 * 60 * 60 * 1000),
|
||||
runType: "llm",
|
||||
});
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,36 @@
|
||||
|
||||
# :snippet-start: runs-query-filter-time-range-before-py
|
||||
# :codegroup-tab: Before
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from langsmith import Client
|
||||
|
||||
client = Client()
|
||||
runs = client.list_runs(
|
||||
project_name="default",
|
||||
start_time=datetime.now() - timedelta(days=1),
|
||||
run_type="llm",
|
||||
)
|
||||
# :snippet-end:
|
||||
|
||||
# :snippet-start: runs-query-filter-time-range-after-py
|
||||
# :codegroup-tab: After
|
||||
import asyncio
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from langsmith import Client
|
||||
|
||||
|
||||
async def main():
|
||||
client = Client()
|
||||
async for project in client.projects.list(name="default", limit=1):
|
||||
break
|
||||
runs = client.runs.query(
|
||||
project_ids=[str(project.id)],
|
||||
min_start_time=datetime.now() - timedelta(days=1),
|
||||
run_type="LLM",
|
||||
)
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,41 @@
|
||||
// :snippet-start: runs-query-list-all-after-go
|
||||
// :codegroup-tab: After
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/langchain-ai/langsmith-go"
|
||||
)
|
||||
|
||||
// :remove-start:
|
||||
func main() {
|
||||
// :remove-end:
|
||||
ctx := context.Background()
|
||||
client := langsmith.NewClient()
|
||||
|
||||
sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{
|
||||
Name: langsmith.F("default"),
|
||||
Limit: langsmith.F(int64(1)),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
project := sessions.Items[0]
|
||||
|
||||
runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{
|
||||
ProjectIDs: langsmith.F([]string{project.ID}),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
_ = runs
|
||||
// :remove-end:
|
||||
// :remove-start:
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,32 @@
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//JAVA 21
|
||||
//KOTLIN 2.2.0
|
||||
//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11
|
||||
|
||||
// :snippet-start: runs-query-list-all-after-kt
|
||||
// :codegroup-tab: After
|
||||
import com.langchain.smith.client.LangsmithClient
|
||||
import com.langchain.smith.client.okhttp.LangsmithOkHttpClient
|
||||
import com.langchain.smith.models.runs.RunQueryV2Params
|
||||
import com.langchain.smith.models.sessions.SessionListParams
|
||||
|
||||
// :remove-start:
|
||||
fun main() {
|
||||
if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) {
|
||||
println("[smithdb-runs-query-list-all-after] Skipping (LANGSMITH_API_KEY is not set).")
|
||||
return
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
val client: LangsmithClient = LangsmithOkHttpClient.fromEnv()
|
||||
|
||||
val project = client.sessions().list(
|
||||
SessionListParams.builder().name("default").limit(1L).build()
|
||||
).items().first()
|
||||
val runs = client.runs().queryV2(
|
||||
RunQueryV2Params.builder().addProjectId(project.id()).build()
|
||||
).items()
|
||||
// :remove-start:
|
||||
}
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# :snippet-start: runs-query-list-all-after-sh
|
||||
PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id')
|
||||
# :remove-start:
|
||||
[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; }
|
||||
# :remove-end:
|
||||
|
||||
curl -X POST "https://api.smith.langchain.com/v2/runs/query" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg pid "$PROJECT_ID" '{"project_ids": [$pid]}')"
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,11 @@
|
||||
|
||||
// :snippet-start: runs-query-list-all-after-js
|
||||
// :codegroup-tab: After
|
||||
import { Client } from "langsmith";
|
||||
|
||||
const client = new Client();
|
||||
const project = await client.projects
|
||||
.list({ name: "default", limit: 1 })
|
||||
.then((page) => page.getPaginatedItems()[0]);
|
||||
const runs = client.runs.query({ project_ids: [project.id] });
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,41 @@
|
||||
// :snippet-start: runs-query-list-all-before-go
|
||||
// :codegroup-tab: Before
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/langchain-ai/langsmith-go"
|
||||
)
|
||||
|
||||
// :remove-start:
|
||||
func main() {
|
||||
// :remove-end:
|
||||
ctx := context.Background()
|
||||
client := langsmith.NewClient()
|
||||
|
||||
sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{
|
||||
Name: langsmith.F("default"),
|
||||
Limit: langsmith.F(int64(1)),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
project := sessions.Items[0]
|
||||
|
||||
runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{
|
||||
Session: langsmith.F([]string{project.ID}),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
_ = runs
|
||||
// :remove-end:
|
||||
// :remove-start:
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,32 @@
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//JAVA 21
|
||||
//KOTLIN 2.2.0
|
||||
//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11
|
||||
|
||||
// :snippet-start: runs-query-list-all-before-kt
|
||||
// :codegroup-tab: Before
|
||||
import com.langchain.smith.client.LangsmithClient
|
||||
import com.langchain.smith.client.okhttp.LangsmithOkHttpClient
|
||||
import com.langchain.smith.models.runs.RunQueryParams
|
||||
import com.langchain.smith.models.sessions.SessionListParams
|
||||
|
||||
// :remove-start:
|
||||
fun main() {
|
||||
if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) {
|
||||
println("[smithdb-runs-query-list-all-before] Skipping (LANGSMITH_API_KEY is not set).")
|
||||
return
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
val client: LangsmithClient = LangsmithOkHttpClient.fromEnv()
|
||||
|
||||
val project = client.sessions().list(
|
||||
SessionListParams.builder().name("default").limit(1L).build()
|
||||
).items().first()
|
||||
val runs = client.runs().query(
|
||||
RunQueryParams.builder().addSession(project.id()).build()
|
||||
).items()
|
||||
// :remove-start:
|
||||
}
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# :snippet-start: runs-query-list-all-before-sh
|
||||
PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id')
|
||||
# :remove-start:
|
||||
[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; }
|
||||
# :remove-end:
|
||||
|
||||
curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg pid "$PROJECT_ID" '{"session": [$pid]}')"
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
// :snippet-start: runs-query-list-all-before-js
|
||||
// :codegroup-tab: Before
|
||||
import { Client } from "langsmith";
|
||||
|
||||
const client = new Client();
|
||||
const runs = client.listRuns({ projectName: "default" });
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,25 @@
|
||||
|
||||
# :snippet-start: runs-query-list-all-before-py
|
||||
# :codegroup-tab: Before
|
||||
from langsmith import Client
|
||||
|
||||
client = Client()
|
||||
runs = client.list_runs(project_name="default")
|
||||
# :snippet-end:
|
||||
|
||||
# :snippet-start: runs-query-list-all-after-py
|
||||
# :codegroup-tab: After
|
||||
import asyncio
|
||||
|
||||
from langsmith import Client
|
||||
|
||||
|
||||
async def main():
|
||||
client = Client()
|
||||
async for project in client.projects.list(name="default", limit=1):
|
||||
break
|
||||
runs = client.runs.query(project_ids=[str(project.id)])
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,47 @@
|
||||
// :snippet-start: runs-query-pagination-after-go
|
||||
// :codegroup-tab: After
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/langchain-ai/langsmith-go"
|
||||
)
|
||||
|
||||
// :remove-start:
|
||||
func main() {
|
||||
// :remove-end:
|
||||
ctx := context.Background()
|
||||
client := langsmith.NewClient()
|
||||
|
||||
sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{
|
||||
Name: langsmith.F("default"),
|
||||
Limit: langsmith.F(int64(1)),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
project := sessions.Items[0]
|
||||
|
||||
runs := []langsmith.Run{}
|
||||
iter := client.Runs.QueryV2AutoPaging(ctx, langsmith.RunQueryV2Params{
|
||||
ProjectIDs: langsmith.F([]string{project.ID}),
|
||||
})
|
||||
for iter.Next() {
|
||||
runs = append(runs, iter.Current())
|
||||
if len(runs) >= 150 {
|
||||
break
|
||||
}
|
||||
}
|
||||
// :remove-start:
|
||||
if iter.Err() != nil {
|
||||
panic(iter.Err().Error())
|
||||
}
|
||||
// :remove-end:
|
||||
// :remove-start:
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,36 @@
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//JAVA 21
|
||||
//KOTLIN 2.2.0
|
||||
//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11
|
||||
|
||||
// :snippet-start: runs-query-pagination-after-kt
|
||||
// :codegroup-tab: After
|
||||
import com.langchain.smith.client.LangsmithClient
|
||||
import com.langchain.smith.client.okhttp.LangsmithOkHttpClient
|
||||
import com.langchain.smith.models.runs.RunQueryV2Params
|
||||
import com.langchain.smith.models.sessions.SessionListParams
|
||||
|
||||
// :remove-start:
|
||||
fun main() {
|
||||
if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) {
|
||||
println("[smithdb-runs-query-pagination-after] Skipping (LANGSMITH_API_KEY is not set).")
|
||||
return
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
val client: LangsmithClient = LangsmithOkHttpClient.fromEnv()
|
||||
|
||||
val project = client.sessions().list(
|
||||
SessionListParams.builder().name("default").limit(1L).build()
|
||||
).items().first()
|
||||
val runs = mutableListOf<Any>()
|
||||
for (run in client.runs().queryV2(
|
||||
RunQueryV2Params.builder().addProjectId(project.id()).build()
|
||||
).autoPager()) {
|
||||
runs.add(run)
|
||||
if (runs.size >= 150) break
|
||||
}
|
||||
// :remove-start:
|
||||
}
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# :snippet-start: runs-query-pagination-after-sh
|
||||
PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id')
|
||||
# :remove-start:
|
||||
[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; }
|
||||
# :remove-end:
|
||||
|
||||
# Fetch pages, passing the cursor from each response's next_cursor field
|
||||
# to fetch the next page, until 150 runs are collected or pages run out.
|
||||
TOTAL=0
|
||||
CURSOR=""
|
||||
while :; do
|
||||
BODY=$(jq -n --arg pid "$PROJECT_ID" --arg cursor "$CURSOR" \
|
||||
'if $cursor == "" then {"project_ids": [$pid]} else {"project_ids": [$pid], "cursor": $cursor} end')
|
||||
RESPONSE=$(curl -s -X POST "https://api.smith.langchain.com/v2/runs/query" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$BODY")
|
||||
TOTAL=$((TOTAL + $(echo "$RESPONSE" | jq '.items | length')))
|
||||
CURSOR=$(echo "$RESPONSE" | jq -r '.next_cursor // empty')
|
||||
[ "$TOTAL" -lt 150 ] && [ -n "$CURSOR" ] || break
|
||||
done
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
// :snippet-start: runs-query-pagination-after-js
|
||||
// :codegroup-tab: After
|
||||
import { Client } from "langsmith";
|
||||
|
||||
const client = new Client();
|
||||
const project = await client.projects
|
||||
.list({ name: "default", limit: 1 })
|
||||
.then((page) => page.getPaginatedItems()[0]);
|
||||
const runs: unknown[] = [];
|
||||
for await (const run of client.runs.query({
|
||||
project_ids: [project.id],
|
||||
})) {
|
||||
runs.push(run);
|
||||
if (runs.length >= 150) break;
|
||||
}
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,47 @@
|
||||
// :snippet-start: runs-query-pagination-before-go
|
||||
// :codegroup-tab: Before
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/langchain-ai/langsmith-go"
|
||||
)
|
||||
|
||||
// :remove-start:
|
||||
func main() {
|
||||
// :remove-end:
|
||||
ctx := context.Background()
|
||||
client := langsmith.NewClient()
|
||||
|
||||
sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{
|
||||
Name: langsmith.F("default"),
|
||||
Limit: langsmith.F(int64(1)),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
project := sessions.Items[0]
|
||||
|
||||
runs := []langsmith.RunSchema{}
|
||||
iter := client.Runs.QueryAutoPaging(ctx, langsmith.RunQueryParams{
|
||||
Session: langsmith.F([]string{project.ID}),
|
||||
})
|
||||
for iter.Next() {
|
||||
runs = append(runs, iter.Current())
|
||||
if len(runs) >= 150 {
|
||||
break
|
||||
}
|
||||
}
|
||||
// :remove-start:
|
||||
if iter.Err() != nil {
|
||||
panic(iter.Err().Error())
|
||||
}
|
||||
// :remove-end:
|
||||
// :remove-start:
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,36 @@
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//JAVA 21
|
||||
//KOTLIN 2.2.0
|
||||
//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11
|
||||
|
||||
// :snippet-start: runs-query-pagination-before-kt
|
||||
// :codegroup-tab: Before
|
||||
import com.langchain.smith.client.LangsmithClient
|
||||
import com.langchain.smith.client.okhttp.LangsmithOkHttpClient
|
||||
import com.langchain.smith.models.runs.RunQueryParams
|
||||
import com.langchain.smith.models.sessions.SessionListParams
|
||||
|
||||
// :remove-start:
|
||||
fun main() {
|
||||
if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) {
|
||||
println("[smithdb-runs-query-pagination-before] Skipping (LANGSMITH_API_KEY is not set).")
|
||||
return
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
val client: LangsmithClient = LangsmithOkHttpClient.fromEnv()
|
||||
|
||||
val project = client.sessions().list(
|
||||
SessionListParams.builder().name("default").limit(1L).build()
|
||||
).items().first()
|
||||
val runs = mutableListOf<Any>()
|
||||
for (run in client.runs().query(
|
||||
RunQueryParams.builder().addSession(project.id()).build()
|
||||
).autoPager()) {
|
||||
runs.add(run)
|
||||
if (runs.size >= 150) break
|
||||
}
|
||||
// :remove-start:
|
||||
}
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# :snippet-start: runs-query-pagination-before-sh
|
||||
PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id')
|
||||
# :remove-start:
|
||||
[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; }
|
||||
# :remove-end:
|
||||
|
||||
curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg pid "$PROJECT_ID" '{"session": [$pid], "limit": 150}')"
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,12 @@
|
||||
|
||||
// :snippet-start: runs-query-pagination-before-js
|
||||
// :codegroup-tab: Before
|
||||
import { Client } from "langsmith";
|
||||
|
||||
const client = new Client();
|
||||
const runs: unknown[] = [];
|
||||
for await (const run of client.listRuns({ projectName: "default" })) {
|
||||
runs.push(run);
|
||||
if (runs.length >= 150) break;
|
||||
}
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
# :snippet-start: runs-query-pagination-before-py
|
||||
# :codegroup-tab: Before
|
||||
from langsmith import Client
|
||||
|
||||
client = Client()
|
||||
runs = client.list_runs(project_name="default", limit=150)
|
||||
# :snippet-end:
|
||||
|
||||
# :snippet-start: runs-query-pagination-after-py
|
||||
# :codegroup-tab: After
|
||||
import asyncio
|
||||
|
||||
from langsmith import Client
|
||||
|
||||
|
||||
async def main():
|
||||
client = Client()
|
||||
async for project in client.projects.list(name="default", limit=1):
|
||||
break
|
||||
runs = []
|
||||
async for run in client.runs.query(
|
||||
project_ids=[str(project.id)],
|
||||
):
|
||||
runs.append(run)
|
||||
if len(runs) >= 150:
|
||||
break
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,44 @@
|
||||
// :snippet-start: runs-query-scoped-filters-after-go
|
||||
// :codegroup-tab: After
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/langchain-ai/langsmith-go"
|
||||
)
|
||||
|
||||
// :remove-start:
|
||||
func main() {
|
||||
// :remove-end:
|
||||
ctx := context.Background()
|
||||
client := langsmith.NewClient()
|
||||
|
||||
sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{
|
||||
Name: langsmith.F("default"),
|
||||
Limit: langsmith.F(int64(1)),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
project := sessions.Items[0]
|
||||
|
||||
runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{
|
||||
ProjectIDs: langsmith.F([]string{project.ID}),
|
||||
Filter: langsmith.F(`eq(name, "RetrieveDocs")`),
|
||||
TraceFilter: langsmith.F(`and(eq(feedback_key, "user_score"), eq(feedback_score, 1))`),
|
||||
TreeFilter: langsmith.F(`eq(name, "ExpandQuery")`),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
_ = runs
|
||||
// :remove-end:
|
||||
// :remove-start:
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,37 @@
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//JAVA 21
|
||||
//KOTLIN 2.2.0
|
||||
//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11
|
||||
|
||||
// :snippet-start: runs-query-scoped-filters-after-kt
|
||||
// :codegroup-tab: After
|
||||
import com.langchain.smith.client.LangsmithClient
|
||||
import com.langchain.smith.client.okhttp.LangsmithOkHttpClient
|
||||
import com.langchain.smith.models.runs.RunQueryV2Params
|
||||
import com.langchain.smith.models.sessions.SessionListParams
|
||||
|
||||
// :remove-start:
|
||||
fun main() {
|
||||
if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) {
|
||||
println("[smithdb-runs-query-scoped-filters-after] Skipping (LANGSMITH_API_KEY is not set).")
|
||||
return
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
val client: LangsmithClient = LangsmithOkHttpClient.fromEnv()
|
||||
|
||||
val project = client.sessions().list(
|
||||
SessionListParams.builder().name("default").limit(1L).build()
|
||||
).items().first()
|
||||
val runs = client.runs().queryV2(
|
||||
RunQueryV2Params.builder()
|
||||
.addProjectId(project.id())
|
||||
.filter("eq(name, \"RetrieveDocs\")")
|
||||
.traceFilter("and(eq(feedback_key, \"user_score\"), eq(feedback_score, 1))")
|
||||
.treeFilter("eq(name, \"ExpandQuery\")")
|
||||
.build()
|
||||
).items()
|
||||
// :remove-start:
|
||||
}
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# :snippet-start: runs-query-scoped-filters-after-sh
|
||||
PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id')
|
||||
# :remove-start:
|
||||
[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; }
|
||||
# :remove-end:
|
||||
|
||||
FILTER='eq(name, "RetrieveDocs")'
|
||||
TRACE_FILTER='and(eq(feedback_key, "user_score"), eq(feedback_score, 1))'
|
||||
TREE_FILTER='eq(name, "ExpandQuery")'
|
||||
|
||||
curl -X POST "https://api.smith.langchain.com/v2/runs/query" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n \
|
||||
--arg pid "$PROJECT_ID" \
|
||||
--arg f "$FILTER" \
|
||||
--arg tf "$TRACE_FILTER" \
|
||||
--arg treef "$TREE_FILTER" \
|
||||
'{"project_ids": [$pid], "filter": $f, "trace_filter": $tf, "tree_filter": $treef}')"
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,16 @@
|
||||
|
||||
// :snippet-start: runs-query-scoped-filters-after-js
|
||||
// :codegroup-tab: After
|
||||
import { Client } from "langsmith";
|
||||
|
||||
const client = new Client();
|
||||
const project = await client.projects
|
||||
.list({ name: "default", limit: 1 })
|
||||
.then((page) => page.getPaginatedItems()[0]);
|
||||
const runs = client.runs.query({
|
||||
project_ids: [project.id],
|
||||
filter: 'eq(name, "RetrieveDocs")',
|
||||
trace_filter: 'and(eq(feedback_key, "user_score"), eq(feedback_score, 1))',
|
||||
tree_filter: 'eq(name, "ExpandQuery")',
|
||||
});
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,44 @@
|
||||
// :snippet-start: runs-query-scoped-filters-before-go
|
||||
// :codegroup-tab: Before
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/langchain-ai/langsmith-go"
|
||||
)
|
||||
|
||||
// :remove-start:
|
||||
func main() {
|
||||
// :remove-end:
|
||||
ctx := context.Background()
|
||||
client := langsmith.NewClient()
|
||||
|
||||
sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{
|
||||
Name: langsmith.F("default"),
|
||||
Limit: langsmith.F(int64(1)),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
project := sessions.Items[0]
|
||||
|
||||
runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{
|
||||
Session: langsmith.F([]string{project.ID}),
|
||||
Filter: langsmith.F(`eq(name, "RetrieveDocs")`),
|
||||
TraceFilter: langsmith.F(`and(eq(feedback_key, "user_score"), eq(feedback_score, 1))`),
|
||||
TreeFilter: langsmith.F(`eq(name, "ExpandQuery")`),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
_ = runs
|
||||
// :remove-end:
|
||||
// :remove-start:
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,37 @@
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//JAVA 21
|
||||
//KOTLIN 2.2.0
|
||||
//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11
|
||||
|
||||
// :snippet-start: runs-query-scoped-filters-before-kt
|
||||
// :codegroup-tab: Before
|
||||
import com.langchain.smith.client.LangsmithClient
|
||||
import com.langchain.smith.client.okhttp.LangsmithOkHttpClient
|
||||
import com.langchain.smith.models.runs.RunQueryParams
|
||||
import com.langchain.smith.models.sessions.SessionListParams
|
||||
|
||||
// :remove-start:
|
||||
fun main() {
|
||||
if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) {
|
||||
println("[smithdb-runs-query-scoped-filters-before] Skipping (LANGSMITH_API_KEY is not set).")
|
||||
return
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
val client: LangsmithClient = LangsmithOkHttpClient.fromEnv()
|
||||
|
||||
val project = client.sessions().list(
|
||||
SessionListParams.builder().name("default").limit(1L).build()
|
||||
).items().first()
|
||||
val runs = client.runs().query(
|
||||
RunQueryParams.builder()
|
||||
.addSession(project.id())
|
||||
.filter("eq(name, \"RetrieveDocs\")")
|
||||
.traceFilter("and(eq(feedback_key, \"user_score\"), eq(feedback_score, 1))")
|
||||
.treeFilter("eq(name, \"ExpandQuery\")")
|
||||
.build()
|
||||
).items()
|
||||
// :remove-start:
|
||||
}
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# :snippet-start: runs-query-scoped-filters-before-sh
|
||||
PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id')
|
||||
# :remove-start:
|
||||
[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; }
|
||||
# :remove-end:
|
||||
|
||||
FILTER='eq(name, "RetrieveDocs")'
|
||||
TRACE_FILTER='and(eq(feedback_key, "user_score"), eq(feedback_score, 1))'
|
||||
TREE_FILTER='eq(name, "ExpandQuery")'
|
||||
|
||||
curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n \
|
||||
--arg pid "$PROJECT_ID" \
|
||||
--arg f "$FILTER" \
|
||||
--arg tf "$TRACE_FILTER" \
|
||||
--arg treef "$TREE_FILTER" \
|
||||
'{"session": [$pid], "filter": $f, "trace_filter": $tf, "tree_filter": $treef}')"
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,13 @@
|
||||
|
||||
// :snippet-start: runs-query-scoped-filters-before-js
|
||||
// :codegroup-tab: Before
|
||||
import { Client } from "langsmith";
|
||||
|
||||
const client = new Client();
|
||||
const runs = client.listRuns({
|
||||
projectName: "default",
|
||||
filter: 'eq(name, "RetrieveDocs")',
|
||||
traceFilter: 'and(eq(feedback_key, "user_score"), eq(feedback_score, 1))',
|
||||
treeFilter: 'eq(name, "ExpandQuery")',
|
||||
});
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
# :snippet-start: runs-query-scoped-filters-before-py
|
||||
# :codegroup-tab: Before
|
||||
from langsmith import Client
|
||||
|
||||
client = Client()
|
||||
runs = client.list_runs(
|
||||
project_name="default",
|
||||
filter='eq(name, "RetrieveDocs")',
|
||||
trace_filter='and(eq(feedback_key, "user_score"), eq(feedback_score, 1))',
|
||||
tree_filter='eq(name, "ExpandQuery")',
|
||||
)
|
||||
# :snippet-end:
|
||||
|
||||
# :snippet-start: runs-query-scoped-filters-after-py
|
||||
# :codegroup-tab: After
|
||||
import asyncio
|
||||
|
||||
from langsmith import Client
|
||||
|
||||
|
||||
async def main():
|
||||
client = Client()
|
||||
async for project in client.projects.list(name="default", limit=1):
|
||||
break
|
||||
runs = client.runs.query(
|
||||
project_ids=[str(project.id)],
|
||||
filter='eq(name, "RetrieveDocs")',
|
||||
trace_filter='and(eq(feedback_key, "user_score"), eq(feedback_score, 1))',
|
||||
tree_filter='eq(name, "ExpandQuery")',
|
||||
)
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,57 @@
|
||||
// :snippet-start: runs-query-selecting-fields-after-go
|
||||
// :codegroup-tab: After
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/langchain-ai/langsmith-go"
|
||||
)
|
||||
|
||||
// :remove-start:
|
||||
func main() {
|
||||
// :remove-end:
|
||||
ctx := context.Background()
|
||||
client := langsmith.NewClient()
|
||||
|
||||
sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{
|
||||
Name: langsmith.F("default"),
|
||||
Limit: langsmith.F(int64(1)),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
project := sessions.Items[0]
|
||||
|
||||
// must explicitly list every field needed; default returns only id
|
||||
runs, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{
|
||||
ProjectIDs: langsmith.F([]string{project.ID}),
|
||||
Selects: langsmith.F([]langsmith.RunQueryV2ParamsSelect{
|
||||
langsmith.RunQueryV2ParamsSelectID,
|
||||
langsmith.RunQueryV2ParamsSelectName,
|
||||
langsmith.RunQueryV2ParamsSelectRunType,
|
||||
langsmith.RunQueryV2ParamsSelectStatus,
|
||||
langsmith.RunQueryV2ParamsSelectStartTime,
|
||||
langsmith.RunQueryV2ParamsSelectInputs,
|
||||
langsmith.RunQueryV2ParamsSelectError,
|
||||
}),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
for _, run := range runs.Items {
|
||||
fmt.Println(run.ID, run.Name, run.RunType, run.Status, run.StartTime, run.Inputs, run.Error)
|
||||
// :remove-start:
|
||||
break
|
||||
// :remove-end:
|
||||
}
|
||||
// :remove-start:
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,48 @@
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//JAVA 21
|
||||
//KOTLIN 2.2.0
|
||||
//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11
|
||||
|
||||
// :snippet-start: runs-query-selecting-fields-after-kt
|
||||
// :codegroup-tab: After
|
||||
import com.langchain.smith.client.LangsmithClient
|
||||
import com.langchain.smith.client.okhttp.LangsmithOkHttpClient
|
||||
import com.langchain.smith.models.runs.RunQueryV2Params
|
||||
import com.langchain.smith.models.sessions.SessionListParams
|
||||
|
||||
// :remove-start:
|
||||
fun main() {
|
||||
if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) {
|
||||
println("[smithdb-runs-query-selecting-fields-after] Skipping (LANGSMITH_API_KEY is not set).")
|
||||
return
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
val client: LangsmithClient = LangsmithOkHttpClient.fromEnv()
|
||||
|
||||
val project = client.sessions().list(
|
||||
SessionListParams.builder().name("default").limit(1L).build()
|
||||
).items().first()
|
||||
// must explicitly list every field needed; default returns only id
|
||||
val runs = client.runs().queryV2(
|
||||
RunQueryV2Params.builder()
|
||||
.addProjectId(project.id())
|
||||
.addSelect(RunQueryV2Params.Select.ID)
|
||||
.addSelect(RunQueryV2Params.Select.NAME)
|
||||
.addSelect(RunQueryV2Params.Select.RUN_TYPE)
|
||||
.addSelect(RunQueryV2Params.Select.STATUS)
|
||||
.addSelect(RunQueryV2Params.Select.START_TIME)
|
||||
.addSelect(RunQueryV2Params.Select.INPUTS)
|
||||
.addSelect(RunQueryV2Params.Select.ERROR)
|
||||
.build()
|
||||
).items()
|
||||
for (run in runs) {
|
||||
println("${run.id()} ${run.name()} ${run.runType()} ${run.status()} ${run.startTime()} ${run.inputs()} ${run.error()}")
|
||||
// :remove-start:
|
||||
break
|
||||
// :remove-end:
|
||||
}
|
||||
// :remove-start:
|
||||
}
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# :snippet-start: runs-query-selecting-fields-after-sh
|
||||
PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id')
|
||||
# :remove-start:
|
||||
[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; }
|
||||
# :remove-end:
|
||||
|
||||
curl -X POST "https://api.smith.langchain.com/v2/runs/query" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg pid "$PROJECT_ID" '{"project_ids": [$pid], "selects": ["ID", "NAME", "RUN_TYPE", "STATUS", "START_TIME", "INPUTS", "ERROR"]}')"
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,20 @@
|
||||
|
||||
// :snippet-start: runs-query-selecting-fields-after-js
|
||||
// :codegroup-tab: After
|
||||
import { Client } from "langsmith";
|
||||
|
||||
const client = new Client();
|
||||
const project = await client.projects
|
||||
.list({ name: "default", limit: 1 })
|
||||
.then((page) => page.getPaginatedItems()[0]);
|
||||
// must explicitly list every field needed; default returns only id
|
||||
for await (const run of client.runs.query({
|
||||
project_ids: [project.id],
|
||||
selects: ["ID", "NAME", "RUN_TYPE", "STATUS", "START_TIME", "INPUTS", "ERROR"],
|
||||
})) {
|
||||
console.log(run.id, run.name, run.run_type, run.status, run.start_time, run.inputs, run.error);
|
||||
// :remove-start:
|
||||
break;
|
||||
// :remove-end:
|
||||
}
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,48 @@
|
||||
// :snippet-start: runs-query-selecting-fields-before-go
|
||||
// :codegroup-tab: Before
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/langchain-ai/langsmith-go"
|
||||
)
|
||||
|
||||
// :remove-start:
|
||||
func main() {
|
||||
// :remove-end:
|
||||
ctx := context.Background()
|
||||
client := langsmith.NewClient()
|
||||
|
||||
sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{
|
||||
Name: langsmith.F("default"),
|
||||
Limit: langsmith.F(int64(1)),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
project := sessions.Items[0]
|
||||
|
||||
// returns a default set of fields; no explicit selection needed
|
||||
runs, err := client.Runs.Query(ctx, langsmith.RunQueryParams{
|
||||
Session: langsmith.F([]string{project.ID}),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
for _, run := range runs.Runs {
|
||||
fmt.Println(run.ID, run.Name, run.RunType, run.Status, run.StartTime, run.Inputs, run.Error)
|
||||
// :remove-start:
|
||||
break
|
||||
// :remove-end:
|
||||
}
|
||||
// :remove-start:
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,39 @@
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//JAVA 21
|
||||
//KOTLIN 2.2.0
|
||||
//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11
|
||||
|
||||
// :snippet-start: runs-query-selecting-fields-before-kt
|
||||
// :codegroup-tab: Before
|
||||
import com.langchain.smith.client.LangsmithClient
|
||||
import com.langchain.smith.client.okhttp.LangsmithOkHttpClient
|
||||
import com.langchain.smith.models.runs.RunQueryParams
|
||||
import com.langchain.smith.models.sessions.SessionListParams
|
||||
|
||||
// :remove-start:
|
||||
fun main() {
|
||||
if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) {
|
||||
println("[smithdb-runs-query-selecting-fields-before] Skipping (LANGSMITH_API_KEY is not set).")
|
||||
return
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
val client: LangsmithClient = LangsmithOkHttpClient.fromEnv()
|
||||
|
||||
val project = client.sessions().list(
|
||||
SessionListParams.builder().name("default").limit(1L).build()
|
||||
).items().first()
|
||||
// returns a default set of fields; no explicit selection needed
|
||||
val runs = client.runs().query(
|
||||
RunQueryParams.builder().addSession(project.id()).build()
|
||||
).items()
|
||||
for (run in runs) {
|
||||
println("${run.id()} ${run.name()} ${run.runType()} ${run.status()} ${run.startTime()} ${run.inputs()} ${run.error()}")
|
||||
// :remove-start:
|
||||
break
|
||||
// :remove-end:
|
||||
}
|
||||
// :remove-start:
|
||||
}
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
# :snippet-start: runs-query-selecting-fields-before-sh
|
||||
PROJECT_ID=$(curl -s "https://api.smith.langchain.com/api/v1/sessions?name=default&limit=1" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" | jq -r '.[0].id')
|
||||
# :remove-start:
|
||||
[ -n "$PROJECT_ID" ] && [ "$PROJECT_ID" != "null" ] || { echo "error: could not resolve project id for \"default\"" >&2; exit 1; }
|
||||
# :remove-end:
|
||||
|
||||
curl -X POST "https://api.smith.langchain.com/api/v1/runs/query" \
|
||||
-H "x-api-key: $LANGSMITH_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "$(jq -n --arg pid "$PROJECT_ID" '{"session": [$pid]}')"
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
// :snippet-start: runs-query-selecting-fields-before-js
|
||||
// :codegroup-tab: Before
|
||||
import { Client } from "langsmith";
|
||||
|
||||
const client = new Client();
|
||||
// returns a default set of fields; no explicit selection needed
|
||||
const runs = client.listRuns({ projectName: "default" });
|
||||
for await (const run of runs) {
|
||||
console.log(run.id, run.name, run.run_type, run.status, run.start_time, run.inputs, run.error);
|
||||
// :remove-start:
|
||||
break;
|
||||
// :remove-end:
|
||||
}
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,39 @@
|
||||
|
||||
# :snippet-start: runs-query-selecting-fields-before-py
|
||||
# :codegroup-tab: Before
|
||||
from langsmith import Client
|
||||
|
||||
client = Client()
|
||||
# returns a default set of fields; no explicit selection needed
|
||||
runs = client.list_runs(project_name="default")
|
||||
for run in runs:
|
||||
print(run.id, run.name, run.run_type, run.status, run.start_time, run.inputs, run.error)
|
||||
# :remove-start:
|
||||
break
|
||||
# :remove-end:
|
||||
# :snippet-end:
|
||||
|
||||
# :snippet-start: runs-query-selecting-fields-after-py
|
||||
# :codegroup-tab: After
|
||||
import asyncio
|
||||
|
||||
from langsmith import Client
|
||||
|
||||
|
||||
async def main():
|
||||
client = Client()
|
||||
async for project in client.projects.list(name="default", limit=1):
|
||||
break
|
||||
# must explicitly list every field needed; default returns only id
|
||||
async for run in client.runs.query(
|
||||
project_ids=[str(project.id)],
|
||||
selects=["ID", "NAME", "RUN_TYPE", "STATUS", "START_TIME", "INPUTS", "ERROR"],
|
||||
):
|
||||
print(run.id, run.name, run.run_type, run.status, run.start_time, run.inputs, run.error)
|
||||
# :remove-start:
|
||||
break
|
||||
# :remove-end:
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
# :snippet-end:
|
||||
@@ -0,0 +1,64 @@
|
||||
// :snippet-start: runs-retrieve-basic-after-go
|
||||
// :codegroup-tab: After
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/langchain-ai/langsmith-go"
|
||||
)
|
||||
|
||||
// :remove-start:
|
||||
func main() {
|
||||
// :remove-end:
|
||||
ctx := context.Background()
|
||||
client := langsmith.NewClient()
|
||||
|
||||
runID := "<run-id>"
|
||||
startTime := time.Date(2026, 6, 1, 12, 0, 0, 0, time.UTC)
|
||||
projectID := "<project-id>"
|
||||
// :remove-start:
|
||||
sessions, err := client.Sessions.List(ctx, langsmith.SessionListParams{
|
||||
Name: langsmith.F("default"),
|
||||
Limit: langsmith.F(int64(1)),
|
||||
})
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
projectID = sessions.Items[0].ID
|
||||
found, err := client.Runs.QueryV2(ctx, langsmith.RunQueryV2Params{
|
||||
ProjectIDs: langsmith.F([]string{projectID}),
|
||||
Selects: langsmith.F([]langsmith.RunQueryV2ParamsSelect{
|
||||
langsmith.RunQueryV2ParamsSelectID,
|
||||
langsmith.RunQueryV2ParamsSelectStartTime,
|
||||
}),
|
||||
PageSize: langsmith.F(int64(1)),
|
||||
})
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
runID = found.Items[0].ID
|
||||
startTime = found.Items[0].StartTime
|
||||
// :remove-end:
|
||||
run, err := client.Runs.GetV2(ctx, runID, langsmith.RunGetV2Params{
|
||||
ProjectID: langsmith.F(projectID),
|
||||
StartTime: langsmith.F(startTime),
|
||||
Selects: langsmith.F([]langsmith.RunGetV2ParamsSelect{
|
||||
langsmith.RunGetV2ParamsSelectName,
|
||||
langsmith.RunGetV2ParamsSelectStatus,
|
||||
langsmith.RunGetV2ParamsSelectTotalTokens,
|
||||
}),
|
||||
})
|
||||
// :remove-start:
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
// :remove-end:
|
||||
fmt.Println(run.Name, run.Status, run.TotalTokens)
|
||||
// :remove-start:
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
@@ -0,0 +1,60 @@
|
||||
///usr/bin/env jbang "$0" "$@" ; exit $?
|
||||
//JAVA 21
|
||||
//KOTLIN 2.2.0
|
||||
//DEPS com.langchain.smith:langsmith-java:0.1.0-beta.11
|
||||
|
||||
// :snippet-start: runs-retrieve-basic-after-kt
|
||||
// :codegroup-tab: After
|
||||
import java.time.OffsetDateTime
|
||||
|
||||
import com.langchain.smith.client.LangsmithClient
|
||||
import com.langchain.smith.client.okhttp.LangsmithOkHttpClient
|
||||
import com.langchain.smith.models.runs.RunRetrieveV2Params
|
||||
import com.langchain.smith.models.sessions.SessionListParams
|
||||
// :remove-start:
|
||||
import com.langchain.smith.models.runs.RunQueryV2Params
|
||||
// :remove-end:
|
||||
|
||||
// :remove-start:
|
||||
fun main() {
|
||||
if (System.getenv("LANGSMITH_API_KEY").isNullOrBlank()) {
|
||||
println("[smithdb-runs-retrieve-basic-after] Skipping (LANGSMITH_API_KEY is not set).")
|
||||
return
|
||||
}
|
||||
|
||||
// :remove-end:
|
||||
val client: LangsmithClient = LangsmithOkHttpClient.fromEnv()
|
||||
|
||||
val project = client.sessions().list(
|
||||
SessionListParams.builder().name("default").limit(1L).build()
|
||||
).items().first()
|
||||
|
||||
var runId = "<run-id>"
|
||||
var startTime = "<run-start-time-rfc3339>"
|
||||
// :remove-start:
|
||||
val foundRun = client.runs().queryV2(
|
||||
RunQueryV2Params.builder()
|
||||
.addProjectId(project.id())
|
||||
.addSelect(RunQueryV2Params.Select.ID)
|
||||
.addSelect(RunQueryV2Params.Select.START_TIME)
|
||||
.pageSize(1L)
|
||||
.build()
|
||||
).items().first()
|
||||
runId = foundRun.id().get()
|
||||
startTime = foundRun.startTime().get().toString()
|
||||
// :remove-end:
|
||||
val run = client.runs().retrieveV2(
|
||||
runId,
|
||||
RunRetrieveV2Params.builder()
|
||||
.projectId(project.id())
|
||||
.startTime(OffsetDateTime.parse(startTime))
|
||||
.addSelect(RunRetrieveV2Params.Select.NAME)
|
||||
.addSelect(RunRetrieveV2Params.Select.STATUS)
|
||||
.addSelect(RunRetrieveV2Params.Select.TOTAL_TOKENS)
|
||||
.build()
|
||||
)
|
||||
println("${run.name()} ${run.status()} ${run.totalTokens()}")
|
||||
// :remove-start:
|
||||
}
|
||||
// :remove-end:
|
||||
// :snippet-end:
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user