Skip to content

Commit dcc9754

Browse files
shixishclaude
andcommitted
feat(live,docs): S2 live cases, 3.4.0 changelog, S2 leftovers
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent d2558f5 commit dcc9754

4 files changed

Lines changed: 111 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,48 @@
11
# Changelog
22

3+
## 3.4.0 (unreleased)
4+
5+
Named options on endpoints the SDK already calls, plus `nlp()` and two ontology
6+
helpers. Additive, except that invalid `snippet_length` values now raise (see
7+
Changed). The package version in `pyproject.toml` is bumped at release time.
8+
9+
### Added
10+
11+
- `dql()`/`dql_async()` (and so `dql_parallel`) keyword-only options `type`
12+
(`"query"`, `"text"`, `"queryTextFallback"`, `"crawl"`; `"crawl"` searches crawl
13+
collections), `col`, `filter_exclude`, `exportseparator`, `exportfile`,
14+
`jsonmode`, `non_canonical_facts`, `no_dedup_articles`, `cluster`. They go in the
15+
POST JSON body (wire names `filterExclude`, `nonCanonicalFacts`,
16+
`noDedupArticles`); the token stays in the query string. Passing the same key as a
17+
named option and in `extra` raises `ValidationError`. `report` and `view` are not
18+
named; use `extra`. `size` still defaults to 10. Types: `DqlType`, `DqlJsonMode`,
19+
`DqlCluster`, `DqlOptions`.
20+
- `crawl()` keyword-only create options `url_crawl_regex`, `url_process_regex`,
21+
`page_process_pattern`, `max_to_crawl_per_subdomain`, `max_to_process_per_subdomain`,
22+
`use_canonical`, `notify_webhook`, `notify_email` (query params on the existing
23+
GET). `custom_headers` now accepts a string or a sequence of strings (sent as
24+
repeated `customHeaders` params). Recurring-crawl admin (`repeat`, `maxRounds`, ...)
25+
is not exposed.
26+
- `nlp(text, *, fields, lang, format, document_type, custom_summary)` (sync and
27+
async) on the existing NL endpoint, single document. `fields` is a sequence of
28+
`NlpField`; `format` may be `"plain text with title"`;
29+
`custom_summary={"max_number_of_sentences": n}`. `entities()` is unchanged. Types:
30+
`NlpField`, `NlpFormat`, `NlpCustomSummary`, `NlpResponse`.
31+
- `web_search(text=...)` accepts a string or 1-5 strings (repeated `text=` params on
32+
the existing GET). Out-of-range lengths raise `ValidationError` before any request.
33+
- `dql_fetch_ontology_text()` (sync and async) returns the raw ontology JSON text;
34+
`dql_refresh_ontology` is now also available on `DiffbotAsync` (module function
35+
`diffbot.kg.dql_refresh_ontology_async`). `dql_fetch_ontology()` reuses the text fetch.
36+
- Live suite: `web_search` (single and two-value `text`) and `entities` + `nlp`.
37+
38+
### Changed
39+
40+
- **`web_search(snippet_length=...)` is validated** (parity with the TypeScript SDK):
41+
the value is case-insensitive and must be one of `short`, `medium`, `long`, `full`;
42+
anything else raises `ValidationError` instead of being sent upstream. Breaking only
43+
for invalid input. `snippet_length` and `rerank` are undocumented upstream and
44+
labelled so in the docstrings.
45+
346
## 3.3.0 (unreleased)
447

548
Response types, a pyright gate, and two small methods that complete existing

‎S1_LEFTOVERS.md‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,5 @@ the plan's wording, and what is unverified.
3232

3333
## Not in S1 (see plan §2/§8)
3434

35-
S2 items (DQL named params, crawl-create options, `nlp()`, web-search multi-value
36-
`text` + `snippet_length` validation, ontology text/async parity) and everything marked
37-
Out.
35+
The S2 items that were listed here landed in S2: see `S2_LEFTOVERS.md`. Everything
36+
marked Out in the plan is still out.

‎S2_LEFTOVERS.md‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# S2 leftovers (Python)
2+
3+
S2 (plan §2, §6, §8; Python 3.4.0) landed on `feat/sdk-s2`, stacked on `feat/sdk-s1`.
4+
`pyproject.toml` is not bumped (release-time).
5+
6+
## Landed
7+
8+
- DQL named params (`type`, `col`, `filter_exclude`, `exportseparator`, `exportfile`,
9+
`jsonmode`, `non_canonical_facts`, `no_dedup_articles`, `cluster`), POST body, `extra`
10+
collision -> `ValidationError`, forwarded by `dql_parallel`.
11+
- Crawl-create named options and `custom_headers: str | Sequence[str]`.
12+
- `nlp()` (sync/async) on the NL endpoint; `entities()` untouched.
13+
- Web search: 1-5 `text` values, `snippet_length` validation.
14+
- Ontology: `dql_fetch_ontology_text`, `dql_refresh_ontology_async`.
15+
- Live cases: web search (single/2-value `text`), entities + nlp.
16+
17+
## Deliberately narrower than the plan
18+
19+
- **DQL overloads use `**options: Unpack[DqlOptions]`** (type-level only, like extract);
20+
the implementation has explicit keyword parameters.
21+
- **`extra` collision applies to the new named keys only.** Existing keys (`size`,
22+
`from`, `format`, `filter`, `exportspec`) can still be overridden through `extra`, as
23+
before; changing that would be a behaviour change outside S2. A named option whose
24+
value is `None` does not collide, so `extra={"jsonmode": ...}` keeps working.
25+
- **`crawl()` has no `extra`**, so `repeat`/`maxRounds`/`seedRecrawlFrequency`/
26+
`onlyProcessIfNew` are simply unreachable (per the task, no new backdoor).
27+
`Diffbot.crawl` still takes `**kwargs: Any`, so the new names are not type-checked
28+
there. `use_canonical` is sent as `1`/`0` only when set.
29+
- **`nlp()` response is one `NlpResponse` TypedDict** (all fields optional), not a
30+
per-`fields` `Pick`. `facts`/`records`/`categories`/`sentences` are `List[Any]`.
31+
`custom_summary` uses the Python key `max_number_of_sentences` (wire
32+
`maxNumberOfSentences`); the 1-10 range is left to the server.
33+
- **Async refresh naming:** on `DiffbotAsync` it is `dql_refresh_ontology` (no suffix,
34+
like `dql_fetch_ontology`); `dql_refresh_ontology_async` is the `diffbot.kg` function.
35+
- `snippet_length` stays typed as the lowercase `SnippetLength` Literal; uppercase input
36+
is accepted at runtime only.
37+
- `crawl_get_job` still returns `{}` for a missing job (TS: `undefined`); unchanged.
38+
39+
## Unverified
40+
41+
- Live tests (`pytest -m live`) were not run in this session, including the two new
42+
cases. Not confirmed against the real API: `nlp()` `documentType`/`customSummary`
43+
placement inside the document object (taken from the docs), repeated `text=` on the
44+
live web search endpoint, repeated `customHeaders` on the crawl create, and
45+
`type=crawl` DQL requests.
46+
- The TypeScript S2 counterpart was not present when this was written, so field-for-field
47+
parity (names, validation messages) is unchecked beyond `snippetLength`.
48+
- Plan §11 open question about DQL POST parity is still open (see `S1_LEFTOVERS.md`).

‎tests/test_live.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ def test_live_entities(db):
4545
assert "entities" in result
4646

4747

48+
def test_live_nlp_on_one_sentence(db):
49+
sentence = "Diffbot is a company based in Menlo Park."
50+
ents = db.entities(sentence)
51+
assert "entities" in ents
52+
result = db.nlp(sentence, fields=["entities", "sentiment", "language"])
53+
assert isinstance(result, dict)
54+
assert "entities" in result
55+
assert "language" in result
56+
57+
58+
def test_live_web_search_single_and_two_value_text(db):
59+
one = db.web_search("diffbot knowledge graph", num_results=1)
60+
assert "search_results" in one
61+
assert len(one["search_results"]) <= 1
62+
two = db.web_search(["diffbot knowledge graph", "diffbot crawl api"], num_results=1)
63+
assert "search_results" in two
64+
65+
4866
def _redacted(account) -> str:
4967
"""Account bodies carry ``token``/``childTokens``: only ever show the other keys."""
5068
return f"keys={sorted(k for k in account if k not in ('token', 'childTokens'))}"

0 commit comments

Comments
 (0)