Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

docs: Add support for class methods in API reference (#7841)

Akeem McLennona24856cd143e
diff --git a/docs/docs/api/adapters/ChatAdapter.md b/docs/docs/api/adapters/ChatAdapter.md
index 2d65e6e72..95c9be077 100644
--- a/docs/docs/api/adapters/ChatAdapter.md
+++ b/docs/docs/api/adapters/ChatAdapter.md
@@ -8,7 +8,6 @@
- format
- format_fields
- format_finetune_data
- - format_turn
- parse
show_source: true
show_undocumented_members: true
diff --git a/docs/docs/api/primitives/Image.md b/docs/docs/api/primitives/Image.md
index 548218405..95a19c279 100644
--- a/docs/docs/api/primitives/Image.md
+++ b/docs/docs/api/primitives/Image.md
@@ -4,14 +4,11 @@
handler: python
options:
members:
- - copy
- - dict
- - json
- - model_copy
- - model_dump
- - model_dump_json
- - model_post_init
+ - from_PIL
+ - from_file
+ - from_url
- serialize_model
+ - validate_input
show_source: true
show_undocumented_members: true
show_root_heading: true
diff --git a/docs/docs/api/primitives/Prediction.md b/docs/docs/api/primitives/Prediction.md
index ffecb60a9..0f197bcb3 100644
--- a/docs/docs/api/primitives/Prediction.md
+++ b/docs/docs/api/primitives/Prediction.md
@@ -5,6 +5,7 @@
options:
members:
- copy
+ - from_completions
- get
- inputs
- items
diff --git a/docs/docs/api/signatures/Signature.md b/docs/docs/api/signatures/Signature.md
index c784ffd2e..aa82101ae 100644
--- a/docs/docs/api/signatures/Signature.md
+++ b/docs/docs/api/signatures/Signature.md
@@ -4,13 +4,14 @@
handler: python
options:
members:
- - copy
- - dict
- - json
- - model_copy
- - model_dump
- - model_dump_json
- - model_post_init
+ - append
+ - dump_state
+ - equals
+ - insert
+ - load_state
+ - prepend
+ - with_instructions
+ - with_updated_fields
show_source: true
show_undocumented_members: true
show_root_heading: true
diff --git a/docs/scripts/generate_api_docs.py b/docs/scripts/generate_api_docs.py
index fed4a332f..7f6487e4f 100644
--- a/docs/scripts/generate_api_docs.py
+++ b/docs/scripts/generate_api_docs.py
@@ -77,6 +77,18 @@ API_MAPPING = {
}
+def should_document_method(obj):
+ name = obj.__name__
+ # Exclude methods not defined in dspy, such as `model_dump_json` from pydantic.
+ module = getattr(obj, "__module__", "")
+ if not module or not module.startswith(f"dspy"):
+ return False
+ # Exclude private and dunder methods, but include `__call__`
+ if name == "__call__" or not name.startswith("_"):
+ return True
+ return False
+
+
def get_module_contents(module):
"""Get all public classes and functions from a module."""
contents_in_all = getattr(module, "__all__", None)
@@ -88,7 +100,7 @@ def get_module_contents(module):
if inspect.ismodule(obj) and obj.__name__.startswith(module.__name__) and not name.startswith("_"):
contents[name] = obj
elif (
- (inspect.isclass(obj) or inspect.isfunction(obj))
+ (inspect.isclass(obj) or (inspect.isroutine(obj) and should_document_method(obj)))
and obj.__module__.startswith(module.__name__)
and not name.startswith("_")
):
@@ -100,8 +112,9 @@ def get_public_methods(cls):
"""Returns a list of all public methods in a class."""
return [
name
- for name, member in inspect.getmembers(cls, predicate=inspect.isfunction)
- if name == "__call__" or not name.startswith("_") # Exclude private and dunder methods, but include `__call__`
+ for name, member in inspect.getmembers(
+ cls, predicate=lambda x: inspect.isroutine(x) and should_document_method(x)
+ )
]