Skip to content

Commit

Permalink
Update documentation for class-based Prompter
Browse files Browse the repository at this point in the history
- Add comprehensive examples in docstrings
- Document both function-based and class-based approaches
- Include detailed usage examples
- Improve method documentation
  • Loading branch information
devin-ai-integration[bot] committed Nov 24, 2024
1 parent 5d880e5 commit c426e94
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 2 deletions.
40 changes: 39 additions & 1 deletion src/bespokelabs/curator/prompter/base_prompter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,42 @@
"""Base class for Prompter implementations."""
"""Base class for Prompter implementations.
This module provides the abstract base class for implementing custom prompters.
The BasePrompter class defines the interface that all prompter implementations
must follow.
Example:
Creating a custom prompter:
```python
class CustomPrompter(BasePrompter):
def prompt_func(self, row: Optional[Dict[str, Any]] = None) -> Dict[str, str]:
# Generate prompts for your specific use case
if row is None:
return {
"user_prompt": "Default prompt",
"system_prompt": "System instructions",
}
return {
"user_prompt": f"Process input: {row['data']}",
"system_prompt": "System instructions",
}
def parse_func(self, row: Dict[str, Any], response: Dict[str, Any]) -> Any:
# Optional: Override to customize response parsing
return response
# Usage
prompter = CustomPrompter(
model_name="gpt-4",
response_format=MyResponseFormat,
)
result = prompter(dataset) # Process dataset
single_result = prompter() # Single completion
```
For simpler use cases where you don't need a full class implementation,
you can use the function-based approach with the Prompter class directly.
See the Prompter class documentation for details.
"""

from abc import ABC, abstractmethod
from typing import Any, Dict, Optional, Type, TypeVar, Union
Expand Down
61 changes: 60 additions & 1 deletion src/bespokelabs/curator/prompter/prompter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,63 @@
"""Curator: Bespoke Labs Synthetic Data Generation Library."""
"""Curator: Bespoke Labs Synthetic Data Generation Library.
This module provides the Prompter class for interacting with LLMs. It supports
both function-based and class-based approaches to defining prompt generation
and response parsing logic.
Examples:
Function-based approach (simple use cases):
```python
from bespokelabs.curator import Prompter
# Define prompt and parse functions
def prompt_func(row=None):
if row is None:
return {
"user_prompt": "Default prompt",
"system_prompt": "You are a helpful assistant.",
}
return {
"user_prompt": f"Process: {row['data']}",
"system_prompt": "You are a helpful assistant.",
}
def parse_func(row, response):
return {"result": response.message}
# Create prompter instance
prompter = Prompter(
model_name="gpt-4",
prompt_func=prompt_func,
parse_func=parse_func,
response_format=MyResponseFormat,
)
# Use the prompter
result = prompter(dataset) # Process dataset
single_result = prompter() # Single completion
```
Class-based approach (complex use cases):
```python
from bespokelabs.curator.prompter.base_prompter import BasePrompter
class CustomPrompter(BasePrompter):
def prompt_func(self, row=None):
# Your custom prompt generation logic
return {
"user_prompt": "...",
"system_prompt": "...",
}
def parse_func(self, row, response):
# Your custom response parsing logic
return response
prompter = CustomPrompter(model_name="gpt-4")
```
For more examples, see the examples/ directory in the repository.
"""

import inspect
import logging
Expand Down

0 comments on commit c426e94

Please sign in to comment.