synth-ai 0.1.0.dev9__py3-none-any.whl → 0.1.0.dev11__py3-none-any.whl

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.

Potentially problematic release.


This version of synth-ai might be problematic. Click here for more details.

@@ -0,0 +1,180 @@
1
+ import asyncio
2
+ import unittest
3
+ from typing import List
4
+
5
+ from pydantic import BaseModel, Field
6
+
7
+ from synth_ai.zyk.lms.core.main import LM
8
+
9
+
10
+ # Define example structured output models
11
+ class SimpleResponse(BaseModel):
12
+ message: str
13
+ confidence: float
14
+
15
+
16
+ class ComplexResponse(BaseModel):
17
+ title: str
18
+ tags: List[str]
19
+ content: str
20
+
21
+
22
+ class NestedResponse(BaseModel):
23
+ main_category: str
24
+ subcategories: List[str]
25
+ details: SimpleResponse
26
+
27
+
28
+ # Define nested structured output models
29
+ class Address(BaseModel):
30
+ street: str
31
+ city: str
32
+ country: str
33
+
34
+
35
+ class PersonalInfo(BaseModel):
36
+ name: str
37
+ age: int
38
+ address: Address
39
+
40
+
41
+ class WorkInfo(BaseModel):
42
+ company: str
43
+ position: str
44
+ years_experience: int
45
+
46
+
47
+ class NestedPersonResponse(BaseModel):
48
+ personal: PersonalInfo
49
+ work: WorkInfo
50
+ skills: List[str]
51
+
52
+
53
+ class ProjectDetails(BaseModel):
54
+ name: str
55
+ description: str
56
+ technologies: List[str]
57
+
58
+
59
+ class NestedPortfolioResponse(BaseModel):
60
+ developer: PersonalInfo
61
+ projects: List[ProjectDetails]
62
+ total_experience: int
63
+
64
+
65
+ class NestedCompanyResponse(BaseModel):
66
+ name: str
67
+ founded: int
68
+ headquarters: Address
69
+ employees: List[PersonalInfo]
70
+ main_products: List[str]
71
+
72
+
73
+ class TestLMStructuredOutputs(unittest.TestCase):
74
+ @classmethod
75
+ def setUpClass(cls):
76
+ # Initialize the LM once for all tests
77
+ cls.lm = LM(
78
+ model_name="gpt-4o-mini",
79
+ formatting_model_name="gpt-4o-mini",
80
+ temperature=0.7,
81
+ max_retries="Few",
82
+ structured_output_mode="forced_json",
83
+ )
84
+
85
+ def test_sync_simple_response(self):
86
+ result = self.lm.respond_sync(
87
+ system_message="You are a helpful assistant.",
88
+ user_message="Give me a short greeting and your confidence level.",
89
+ response_model=SimpleResponse,
90
+ )
91
+ self.assertIsInstance(result, SimpleResponse)
92
+ self.assertIsInstance(result.message, str)
93
+ self.assertIsInstance(result.confidence, float)
94
+ self.assertGreaterEqual(result.confidence, 0)
95
+ self.assertLessEqual(result.confidence, 1)
96
+
97
+ def test_sync_complex_response(self):
98
+ result = self.lm.respond_sync(
99
+ system_message="You are a content creator.",
100
+ user_message="Create a short blog post about AI.",
101
+ response_model=ComplexResponse,
102
+ )
103
+ self.assertIsInstance(result, ComplexResponse)
104
+ self.assertIsInstance(result.title, str)
105
+ self.assertIsInstance(result.tags, list)
106
+ self.assertIsInstance(result.content, str)
107
+
108
+ async def async_nested_response(self):
109
+ result = await self.lm.respond_async(
110
+ system_message="You are a categorization expert.",
111
+ user_message="Categorize 'Python' and provide a brief description.",
112
+ response_model=NestedResponse,
113
+ )
114
+ self.assertIsInstance(result, NestedResponse)
115
+ self.assertIsInstance(result.main_category, str)
116
+ self.assertIsInstance(result.subcategories, list)
117
+ self.assertIsInstance(result.details, SimpleResponse)
118
+
119
+ def test_async_nested_response(self):
120
+ asyncio.run(self.async_nested_response())
121
+
122
+
123
+ class TestLMNestedStructuredOutputs(unittest.TestCase):
124
+ @classmethod
125
+ def setUpClass(cls):
126
+ # Initialize the LM once for all tests
127
+ cls.lm = LM(
128
+ model_name="gpt-4o-mini",
129
+ formatting_model_name="gpt-4o-mini",
130
+ temperature=0.7,
131
+ max_retries="Few",
132
+ structured_output_mode="forced_json",
133
+ )
134
+
135
+ def test_sync_nested_person_response(self):
136
+ result = self.lm.respond_sync(
137
+ system_message="You are an HR assistant.",
138
+ user_message="Provide detailed information about a fictional employee named John Doe.",
139
+ response_model=NestedPersonResponse,
140
+ )
141
+ self.assertIsInstance(result, NestedPersonResponse)
142
+ self.assertIsInstance(result.personal, PersonalInfo)
143
+ self.assertIsInstance(result.personal.address, Address)
144
+ self.assertIsInstance(result.work, WorkInfo)
145
+ self.assertIsInstance(result.skills, list)
146
+
147
+ def test_sync_nested_portfolio_response(self):
148
+ result = self.lm.respond_sync(
149
+ system_message="You are a portfolio manager.",
150
+ user_message="Create a portfolio for a fictional software developer with multiple projects.",
151
+ response_model=NestedPortfolioResponse,
152
+ )
153
+ self.assertIsInstance(result, NestedPortfolioResponse)
154
+ self.assertIsInstance(result.developer, PersonalInfo)
155
+ self.assertIsInstance(result.developer.address, Address)
156
+ self.assertIsInstance(result.projects, list)
157
+ for project in result.projects:
158
+ self.assertIsInstance(project, ProjectDetails)
159
+ self.assertIsInstance(result.total_experience, int)
160
+
161
+ async def async_nested_company_response(self):
162
+ result = await self.lm.respond_async(
163
+ system_message="You are a company information specialist.",
164
+ user_message="Provide detailed information about a fictional tech company.",
165
+ response_model=NestedCompanyResponse,
166
+ )
167
+ self.assertIsInstance(result, NestedCompanyResponse)
168
+ self.assertIsInstance(result.headquarters, Address)
169
+ self.assertIsInstance(result.employees, list)
170
+ for employee in result.employees:
171
+ self.assertIsInstance(employee, PersonalInfo)
172
+ self.assertIsInstance(employee.address, Address)
173
+ self.assertIsInstance(result.main_products, list)
174
+
175
+ def test_async_nested_company_response(self):
176
+ asyncio.run(self.async_nested_company_response())
177
+
178
+
179
+ if __name__ == "__main__":
180
+ unittest.main()
@@ -0,0 +1,100 @@
1
+ import asyncio
2
+ import unittest
3
+ from typing import List
4
+
5
+ from pydantic import BaseModel, Field
6
+
7
+ from synth_ai.zyk.lms.core.main import LM
8
+
9
+
10
+ # Define example structured output models
11
+ class SimpleResponse(BaseModel):
12
+ message: str
13
+ confidence_between_zero_one: float = Field(
14
+ ..., description="Confidence level between 0 and 1"
15
+ )
16
+
17
+
18
+ class ComplexResponse(BaseModel):
19
+ title: str
20
+ tags: List[str]
21
+ content: str
22
+
23
+
24
+ class NestedResponse(BaseModel):
25
+ main_category: str
26
+ subcategories: List[str]
27
+ details: SimpleResponse
28
+
29
+
30
+ class TestLMStructuredOutputs(unittest.TestCase):
31
+ @classmethod
32
+ def setUpClass(cls):
33
+ # Initialize LMs for both forced_json and stringified_json modes
34
+ cls.lm_forced_json = LM(
35
+ model_name="gpt-4o-mini",
36
+ formatting_model_name="gpt-4o-mini",
37
+ temperature=0.7,
38
+ max_retries="Few",
39
+ structured_output_mode="forced_json",
40
+ )
41
+ cls.lm_stringified_json = LM(
42
+ model_name="gpt-4o-mini",
43
+ formatting_model_name="gpt-4o-mini",
44
+ temperature=0.7,
45
+ max_retries="Few",
46
+ structured_output_mode="stringified_json",
47
+ )
48
+
49
+ def test_sync_simple_response(self):
50
+ for lm in [self.lm_forced_json, self.lm_stringified_json]:
51
+ with self.subTest(
52
+ mode=lm.structured_output_handler.handler.structured_output_mode
53
+ ):
54
+ result = lm.respond_sync(
55
+ system_message="You are a helpful assistant.",
56
+ user_message="Give me a short greeting and your confidence level.",
57
+ response_model=SimpleResponse,
58
+ )
59
+ self.assertIsInstance(result, SimpleResponse)
60
+ self.assertIsInstance(result.message, str)
61
+ self.assertIsInstance(result.confidence_between_zero_one, float)
62
+ self.assertGreaterEqual(result.confidence_between_zero_one, 0)
63
+ self.assertLessEqual(result.confidence_between_zero_one, 1)
64
+
65
+ def test_sync_complex_response(self):
66
+ for lm in [self.lm_forced_json, self.lm_stringified_json]:
67
+ with self.subTest(
68
+ mode=lm.structured_output_handler.handler.structured_output_mode
69
+ ):
70
+ result = lm.respond_sync(
71
+ system_message="You are a content creator.",
72
+ user_message="Create a short blog post about AI.",
73
+ response_model=ComplexResponse,
74
+ )
75
+ self.assertIsInstance(result, ComplexResponse)
76
+ self.assertIsInstance(result.title, str)
77
+ self.assertIsInstance(result.tags, list)
78
+ self.assertIsInstance(result.content, str)
79
+
80
+ async def async_nested_response(self, lm):
81
+ result = await lm.respond_async(
82
+ system_message="You are a categorization expert.",
83
+ user_message="Categorize 'Python' and provide a brief description.",
84
+ response_model=NestedResponse,
85
+ )
86
+ self.assertIsInstance(result, NestedResponse)
87
+ self.assertIsInstance(result.main_category, str)
88
+ self.assertIsInstance(result.subcategories, list)
89
+ self.assertIsInstance(result.details, SimpleResponse)
90
+
91
+ def test_async_nested_response(self):
92
+ for lm in [self.lm_forced_json, self.lm_stringified_json]: #
93
+ with self.subTest(
94
+ mode=lm.structured_output_handler.handler.structured_output_mode
95
+ ):
96
+ asyncio.run(self.async_nested_response(lm))
97
+
98
+
99
+ if __name__ == "__main__":
100
+ unittest.main()
File without changes