chatan 0.1.0__tar.gz → 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {chatan-0.1.0 → chatan-0.1.1}/.gitignore +2 -0
- {chatan-0.1.0 → chatan-0.1.1}/PKG-INFO +1 -1
- {chatan-0.1.0 → chatan-0.1.1}/src/chatan/__init__.py +1 -1
- {chatan-0.1.0 → chatan-0.1.1}/src/chatan/generator.py +27 -7
- {chatan-0.1.0 → chatan-0.1.1}/tests/test_generator.py +21 -0
- {chatan-0.1.0 → chatan-0.1.1}/.python-version +0 -0
- {chatan-0.1.0 → chatan-0.1.1}/README.md +0 -0
- {chatan-0.1.0 → chatan-0.1.1}/main.py +0 -0
- {chatan-0.1.0 → chatan-0.1.1}/pyproject.toml +0 -0
- {chatan-0.1.0 → chatan-0.1.1}/src/chatan/dataset.py +0 -0
- {chatan-0.1.0 → chatan-0.1.1}/src/chatan/sampler.py +0 -0
- {chatan-0.1.0 → chatan-0.1.1}/tests/test_dataset_comprehensive.py +0 -0
- {chatan-0.1.0 → chatan-0.1.1}/tests/test_datset.py +0 -0
- {chatan-0.1.0 → chatan-0.1.1}/tests/test_sampler.py +0 -0
- {chatan-0.1.0 → chatan-0.1.1}/uv.lock +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: chatan
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.1
|
4
4
|
Summary: Create synthetic datasets with LLM generators and samplers
|
5
5
|
Project-URL: Documentation, https://github.com/cdreetz/chatan#readme
|
6
6
|
Project-URL: Issues, https://github.com/cdreetz/chatan/issues
|
@@ -58,14 +58,24 @@ class AnthropicGenerator(BaseGenerator):
|
|
58
58
|
|
59
59
|
class GeneratorFunction:
|
60
60
|
"""Callable generator function for use in dataset schemas."""
|
61
|
-
|
62
|
-
def __init__(
|
61
|
+
|
62
|
+
def __init__(
|
63
|
+
self,
|
64
|
+
generator: BaseGenerator,
|
65
|
+
prompt_template: str,
|
66
|
+
variables: Optional[Dict[str, Any]] = None,
|
67
|
+
):
|
63
68
|
self.generator = generator
|
64
69
|
self.prompt_template = prompt_template
|
65
|
-
|
70
|
+
self.variables = variables or {}
|
71
|
+
|
66
72
|
def __call__(self, context: Dict[str, Any]) -> str:
|
67
73
|
"""Generate content with context substitution."""
|
68
|
-
|
74
|
+
merged = dict(context)
|
75
|
+
for key, value in self.variables.items():
|
76
|
+
merged[key] = value(context) if callable(value) else value
|
77
|
+
|
78
|
+
prompt = self.prompt_template.format(**merged)
|
69
79
|
result = self.generator.generate(prompt)
|
70
80
|
return result.strip() if isinstance(result, str) else result
|
71
81
|
|
@@ -81,9 +91,19 @@ class GeneratorClient:
|
|
81
91
|
else:
|
82
92
|
raise ValueError(f"Unsupported provider: {provider}")
|
83
93
|
|
84
|
-
def __call__(self, prompt_template: str) -> GeneratorFunction:
|
85
|
-
"""Create a generator function.
|
86
|
-
|
94
|
+
def __call__(self, prompt_template: str, **variables) -> GeneratorFunction:
|
95
|
+
"""Create a generator function.
|
96
|
+
|
97
|
+
Parameters
|
98
|
+
----------
|
99
|
+
prompt_template:
|
100
|
+
Template string for the prompt.
|
101
|
+
**variables:
|
102
|
+
Optional variables to include when formatting the prompt. If a value
|
103
|
+
is callable it will be invoked with the row context when the
|
104
|
+
generator function is executed.
|
105
|
+
"""
|
106
|
+
return GeneratorFunction(self._generator, prompt_template, variables)
|
87
107
|
|
88
108
|
|
89
109
|
# Factory function
|
@@ -289,6 +289,27 @@ class TestIntegration:
|
|
289
289
|
assert result2 == "Response"
|
290
290
|
assert mock_client.chat.completions.create.call_count == 2
|
291
291
|
|
292
|
+
@patch('openai.OpenAI')
|
293
|
+
def test_generator_function_with_variables(self, mock_openai):
|
294
|
+
"""GeneratorFunction should accept default variables."""
|
295
|
+
mock_client = Mock()
|
296
|
+
mock_response = Mock()
|
297
|
+
mock_choice = Mock()
|
298
|
+
mock_choice.message.content = "Question about elephants"
|
299
|
+
mock_response.choices = [mock_choice]
|
300
|
+
mock_client.chat.completions.create.return_value = mock_response
|
301
|
+
mock_openai.return_value = mock_client
|
302
|
+
|
303
|
+
gen = generator("openai", "test-key")
|
304
|
+
func = gen("Question about {animal}", animal="elephants")
|
305
|
+
result = func({})
|
306
|
+
|
307
|
+
assert result == "Question about elephants"
|
308
|
+
mock_client.chat.completions.create.assert_called_once_with(
|
309
|
+
model="gpt-3.5-turbo",
|
310
|
+
messages=[{"role": "user", "content": "Question about elephants"}]
|
311
|
+
)
|
312
|
+
|
292
313
|
def test_case_insensitive_provider(self):
|
293
314
|
"""Test that provider names are case insensitive."""
|
294
315
|
with patch('chatan.generator.OpenAIGenerator') as mock_gen:
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|