Skip to content

Commit a24856c

Browse files
docs: Add support for class methods in API reference (#7841)
* docs: Add support for class methods in API reference * lint fixes --------- Co-authored-by: chenmoneygithub <[email protected]>
1 parent f3d7f26 commit a24856c

File tree

5 files changed

+29
-18
lines changed

5 files changed

+29
-18
lines changed

docs/docs/api/adapters/ChatAdapter.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
- format
99
- format_fields
1010
- format_finetune_data
11-
- format_turn
1211
- parse
1312
show_source: true
1413
show_undocumented_members: true

docs/docs/api/primitives/Image.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44
handler: python
55
options:
66
members:
7-
- copy
8-
- dict
9-
- json
10-
- model_copy
11-
- model_dump
12-
- model_dump_json
13-
- model_post_init
7+
- from_PIL
8+
- from_file
9+
- from_url
1410
- serialize_model
11+
- validate_input
1512
show_source: true
1613
show_undocumented_members: true
1714
show_root_heading: true

docs/docs/api/primitives/Prediction.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
options:
66
members:
77
- copy
8+
- from_completions
89
- get
910
- inputs
1011
- items

docs/docs/api/signatures/Signature.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
handler: python
55
options:
66
members:
7-
- copy
8-
- dict
9-
- json
10-
- model_copy
11-
- model_dump
12-
- model_dump_json
13-
- model_post_init
7+
- append
8+
- dump_state
9+
- equals
10+
- insert
11+
- load_state
12+
- prepend
13+
- with_instructions
14+
- with_updated_fields
1415
show_source: true
1516
show_undocumented_members: true
1617
show_root_heading: true

docs/scripts/generate_api_docs.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,18 @@
7777
}
7878

7979

80+
def should_document_method(obj):
81+
name = obj.__name__
82+
# Exclude methods not defined in dspy, such as `model_dump_json` from pydantic.
83+
module = getattr(obj, "__module__", "")
84+
if not module or not module.startswith(f"dspy"):
85+
return False
86+
# Exclude private and dunder methods, but include `__call__`
87+
if name == "__call__" or not name.startswith("_"):
88+
return True
89+
return False
90+
91+
8092
def get_module_contents(module):
8193
"""Get all public classes and functions from a module."""
8294
contents_in_all = getattr(module, "__all__", None)
@@ -88,7 +100,7 @@ def get_module_contents(module):
88100
if inspect.ismodule(obj) and obj.__name__.startswith(module.__name__) and not name.startswith("_"):
89101
contents[name] = obj
90102
elif (
91-
(inspect.isclass(obj) or inspect.isfunction(obj))
103+
(inspect.isclass(obj) or (inspect.isroutine(obj) and should_document_method(obj)))
92104
and obj.__module__.startswith(module.__name__)
93105
and not name.startswith("_")
94106
):
@@ -100,8 +112,9 @@ def get_public_methods(cls):
100112
"""Returns a list of all public methods in a class."""
101113
return [
102114
name
103-
for name, member in inspect.getmembers(cls, predicate=inspect.isfunction)
104-
if name == "__call__" or not name.startswith("_") # Exclude private and dunder methods, but include `__call__`
115+
for name, member in inspect.getmembers(
116+
cls, predicate=lambda x: inspect.isroutine(x) and should_document_method(x)
117+
)
105118
]
106119

107120

0 commit comments

Comments
 (0)