synth-ai 0.1.0.dev38__py3-none-any.whl → 0.1.0.dev49__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.
Files changed (69) hide show
  1. synth_ai/__init__.py +3 -1
  2. {synth_ai-0.1.0.dev38.dist-info → synth_ai-0.1.0.dev49.dist-info}/METADATA +12 -11
  3. synth_ai-0.1.0.dev49.dist-info/RECORD +6 -0
  4. {synth_ai-0.1.0.dev38.dist-info → synth_ai-0.1.0.dev49.dist-info}/WHEEL +1 -1
  5. synth_ai-0.1.0.dev49.dist-info/top_level.txt +1 -0
  6. private_tests/try_synth_sdk.py +0 -1
  7. public_tests/test_agent.py +0 -538
  8. public_tests/test_all_structured_outputs.py +0 -196
  9. public_tests/test_anthropic_structured_outputs.py +0 -0
  10. public_tests/test_deepseek_structured_outputs.py +0 -0
  11. public_tests/test_deepseek_tools.py +0 -64
  12. public_tests/test_gemini_output.py +0 -188
  13. public_tests/test_gemini_structured_outputs.py +0 -106
  14. public_tests/test_models.py +0 -183
  15. public_tests/test_openai_structured_outputs.py +0 -106
  16. public_tests/test_reasoning_effort.py +0 -75
  17. public_tests/test_reasoning_models.py +0 -92
  18. public_tests/test_recursive_structured_outputs.py +0 -180
  19. public_tests/test_structured.py +0 -137
  20. public_tests/test_structured_outputs.py +0 -109
  21. public_tests/test_synth_sdk.py +0 -384
  22. public_tests/test_text.py +0 -160
  23. public_tests/test_tools.py +0 -319
  24. synth_ai/zyk/__init__.py +0 -3
  25. synth_ai/zyk/lms/__init__.py +0 -0
  26. synth_ai/zyk/lms/caching/__init__.py +0 -0
  27. synth_ai/zyk/lms/caching/constants.py +0 -1
  28. synth_ai/zyk/lms/caching/dbs.py +0 -0
  29. synth_ai/zyk/lms/caching/ephemeral.py +0 -72
  30. synth_ai/zyk/lms/caching/handler.py +0 -142
  31. synth_ai/zyk/lms/caching/initialize.py +0 -13
  32. synth_ai/zyk/lms/caching/persistent.py +0 -83
  33. synth_ai/zyk/lms/config.py +0 -8
  34. synth_ai/zyk/lms/core/__init__.py +0 -0
  35. synth_ai/zyk/lms/core/all.py +0 -47
  36. synth_ai/zyk/lms/core/exceptions.py +0 -9
  37. synth_ai/zyk/lms/core/main.py +0 -314
  38. synth_ai/zyk/lms/core/vendor_clients.py +0 -85
  39. synth_ai/zyk/lms/cost/__init__.py +0 -0
  40. synth_ai/zyk/lms/cost/monitor.py +0 -1
  41. synth_ai/zyk/lms/cost/statefulness.py +0 -1
  42. synth_ai/zyk/lms/structured_outputs/__init__.py +0 -0
  43. synth_ai/zyk/lms/structured_outputs/handler.py +0 -442
  44. synth_ai/zyk/lms/structured_outputs/inject.py +0 -314
  45. synth_ai/zyk/lms/structured_outputs/rehabilitate.py +0 -187
  46. synth_ai/zyk/lms/tools/base.py +0 -104
  47. synth_ai/zyk/lms/vendors/__init__.py +0 -0
  48. synth_ai/zyk/lms/vendors/base.py +0 -31
  49. synth_ai/zyk/lms/vendors/constants.py +0 -22
  50. synth_ai/zyk/lms/vendors/core/__init__.py +0 -0
  51. synth_ai/zyk/lms/vendors/core/anthropic_api.py +0 -413
  52. synth_ai/zyk/lms/vendors/core/gemini_api.py +0 -306
  53. synth_ai/zyk/lms/vendors/core/mistral_api.py +0 -327
  54. synth_ai/zyk/lms/vendors/core/openai_api.py +0 -185
  55. synth_ai/zyk/lms/vendors/local/__init__.py +0 -0
  56. synth_ai/zyk/lms/vendors/local/ollama.py +0 -0
  57. synth_ai/zyk/lms/vendors/openai_standard.py +0 -375
  58. synth_ai/zyk/lms/vendors/retries.py +0 -3
  59. synth_ai/zyk/lms/vendors/supported/__init__.py +0 -0
  60. synth_ai/zyk/lms/vendors/supported/deepseek.py +0 -73
  61. synth_ai/zyk/lms/vendors/supported/groq.py +0 -16
  62. synth_ai/zyk/lms/vendors/supported/ollama.py +0 -14
  63. synth_ai/zyk/lms/vendors/supported/together.py +0 -11
  64. synth_ai-0.1.0.dev38.dist-info/RECORD +0 -67
  65. synth_ai-0.1.0.dev38.dist-info/top_level.txt +0 -4
  66. tests/test_agent.py +0 -538
  67. tests/test_recursive_structured_outputs.py +0 -180
  68. tests/test_structured_outputs.py +0 -100
  69. {synth_ai-0.1.0.dev38.dist-info → synth_ai-0.1.0.dev49.dist-info}/licenses/LICENSE +0 -0
@@ -1,185 +0,0 @@
1
- import json
2
- from typing import Any, Dict, List, Optional, Tuple, Type
3
-
4
- import openai
5
- import pydantic_core
6
-
7
- # from openai import AsyncOpenAI, OpenAI
8
- from pydantic import BaseModel
9
-
10
- from synth_ai.zyk.lms.caching.initialize import get_cache_handler
11
- from synth_ai.zyk.lms.tools.base import BaseTool
12
- from synth_ai.zyk.lms.vendors.base import BaseLMResponse
13
- from synth_ai.zyk.lms.vendors.constants import SPECIAL_BASE_TEMPS, openai_reasoners
14
- from synth_ai.zyk.lms.vendors.openai_standard import OpenAIStandard
15
-
16
- OPENAI_EXCEPTIONS_TO_RETRY: Tuple[Type[Exception], ...] = (
17
- pydantic_core._pydantic_core.ValidationError,
18
- openai.OpenAIError,
19
- openai.APIConnectionError,
20
- openai.RateLimitError,
21
- openai.APIError,
22
- openai.Timeout,
23
- openai.InternalServerError,
24
- openai.APIConnectionError,
25
- )
26
-
27
-
28
- class OpenAIStructuredOutputClient(OpenAIStandard):
29
- def __init__(self, synth_logging: bool = True):
30
- if synth_logging:
31
- # print("Using synth logging - OpenAIStructuredOutputClient")
32
- from synth_sdk import AsyncOpenAI, OpenAI
33
- else:
34
- # print("Not using synth logging - OpenAIStructuredOutputClient")
35
- from openai import AsyncOpenAI, OpenAI
36
-
37
- super().__init__(
38
- used_for_structured_outputs=True,
39
- exceptions_to_retry=OPENAI_EXCEPTIONS_TO_RETRY,
40
- sync_client=OpenAI(),
41
- async_client=AsyncOpenAI(),
42
- )
43
-
44
- async def _hit_api_async_structured_output(
45
- self,
46
- model: str,
47
- messages: List[Dict[str, Any]],
48
- response_model: BaseModel,
49
- temperature: float,
50
- use_ephemeral_cache_only: bool = False,
51
- tools: Optional[List[BaseTool]] = None,
52
- reasoning_effort: str = "high",
53
- ) -> str:
54
- if tools:
55
- raise ValueError("Tools are not supported for async structured output")
56
- # "Hit client")
57
- lm_config = {"temperature": temperature, "response_model": response_model}
58
- used_cache_handler = get_cache_handler(
59
- use_ephemeral_cache_only=use_ephemeral_cache_only
60
- )
61
- cache_result = used_cache_handler.hit_managed_cache(
62
- model, messages, lm_config=lm_config
63
- )
64
- if cache_result:
65
- # print("Hit cache")
66
- assert type(cache_result) in [
67
- dict,
68
- BaseLMResponse,
69
- ], f"Expected dict or BaseLMResponse, got {type(cache_result)}"
70
- return (
71
- cache_result["response"] if type(cache_result) == dict else cache_result
72
- )
73
- if model in openai_reasoners:
74
- output = await self.async_client.chat.completions.create(
75
- model=model,
76
- messages=messages,
77
- temperature=temperature,
78
- tools=tools,
79
- max_completion_tokens=lm_config.get("max_tokens"),
80
- )
81
- else:
82
- output = await self.async_client.chat.completions.create(
83
- model=model,
84
- messages=messages,
85
- temperature=temperature,
86
- max_tokens=lm_config.get("max_tokens"),
87
- )
88
- # "Output", output)
89
- api_result = response_model(**json.loads(output.choices[0].message.content))
90
- lm_response = BaseLMResponse(
91
- raw_response="",
92
- structured_output=api_result,
93
- tool_calls=None,
94
- )
95
- used_cache_handler.add_to_managed_cache(
96
- model, messages, lm_config, output=lm_response
97
- )
98
- return lm_response
99
-
100
- def _hit_api_sync_structured_output(
101
- self,
102
- model: str,
103
- messages: List[Dict[str, Any]],
104
- response_model: BaseModel,
105
- temperature: float,
106
- use_ephemeral_cache_only: bool = False,
107
- tools: Optional[List[BaseTool]] = None,
108
- reasoning_effort: str = "high",
109
- ) -> str:
110
- if tools:
111
- raise ValueError("Tools are not supported for sync structured output")
112
- lm_config = {"temperature": temperature, "response_model": response_model}
113
- used_cache_handler = get_cache_handler(
114
- use_ephemeral_cache_only=use_ephemeral_cache_only
115
- )
116
- cache_result = used_cache_handler.hit_managed_cache(
117
- model, messages, lm_config=lm_config
118
- )
119
- if cache_result:
120
- assert type(cache_result) in [
121
- dict,
122
- BaseLMResponse,
123
- ], f"Expected dict or BaseLMResponse, got {type(cache_result)}"
124
- return (
125
- cache_result["response"] if type(cache_result) == dict else cache_result
126
- )
127
- if model in ["o3-mini", "o3", "o1-mini", "o1"]:
128
- output = self.sync_client.chat.completions.create(
129
- model=model,
130
- messages=messages,
131
- temperature=temperature,
132
- tools=tools,
133
- max_tokens=lm_config.get("max_tokens"),
134
- )
135
- else:
136
- output = self.sync_client.chat.completions.create(
137
- model=model,
138
- messages=messages,
139
- temperature=temperature,
140
- max_tokens=lm_config.get("max_tokens"),
141
- )
142
- api_result = response_model(**json.loads(output.choices[0].message.content))
143
-
144
- lm_response = BaseLMResponse(
145
- raw_response="",
146
- structured_output=api_result,
147
- tool_calls=None,
148
- )
149
- used_cache_handler.add_to_managed_cache(
150
- model, messages, lm_config=lm_config, output=lm_response
151
- )
152
- return lm_response
153
-
154
-
155
- class OpenAIPrivate(OpenAIStandard):
156
- def __init__(self, synth_logging: bool = True):
157
- if synth_logging:
158
- # print("Using synth logging - OpenAIPrivate")
159
- from synth_sdk import AsyncOpenAI, OpenAI
160
- else:
161
- # print("Not using synth logging - OpenAIPrivate")
162
- from openai import AsyncOpenAI, OpenAI
163
-
164
- self.sync_client = OpenAI()
165
- self.async_client = AsyncOpenAI()
166
-
167
-
168
- if __name__ == "__main__":
169
- client = OpenAIStructuredOutputClient(
170
- sync_client=openai.OpenAI(),
171
- async_client=openai.AsyncOpenAI(),
172
- used_for_structured_outputs=True,
173
- exceptions_to_retry=[],
174
- )
175
-
176
- class TestModel(BaseModel):
177
- name: str
178
-
179
- sync_model_response = client._hit_api_sync_structured_output(
180
- model="gpt-4o-mini-2024-07-18",
181
- messages=[{"role": "user", "content": " What is the capital of the moon?"}],
182
- response_model=TestModel,
183
- temperature=0.0,
184
- )
185
- # print(sync_model_response)
File without changes
File without changes
@@ -1,375 +0,0 @@
1
- from typing import Any, Dict, List, Optional, Union
2
-
3
- import groq
4
- import openai
5
- import pydantic_core
6
- from pydantic import BaseModel
7
-
8
- from synth_ai.zyk.lms.caching.initialize import (
9
- get_cache_handler,
10
- )
11
- from synth_ai.zyk.lms.tools.base import BaseTool
12
- from synth_ai.zyk.lms.vendors.base import BaseLMResponse, VendorBase
13
- from synth_ai.zyk.lms.vendors.constants import SPECIAL_BASE_TEMPS, openai_reasoners
14
-
15
- DEFAULT_EXCEPTIONS_TO_RETRY = (
16
- pydantic_core._pydantic_core.ValidationError,
17
- openai.APIConnectionError,
18
- openai.APITimeoutError,
19
- groq.InternalServerError,
20
- groq.APITimeoutError,
21
- groq.APIConnectionError,
22
- )
23
-
24
-
25
- def special_orion_transform(
26
- model: str, messages: List[Dict[str, Any]]
27
- ) -> List[Dict[str, Any]]:
28
- if "o1-" in model:
29
- messages = [
30
- {
31
- "role": "user",
32
- "content": f"<instructions>{messages[0]['content']}</instructions><information>{messages[1]}</information>",
33
- }
34
- ]
35
- return messages
36
-
37
-
38
- def on_backoff_handler_async(details):
39
- # Print every 5th retry attempt, excluding the first retry
40
- if details["tries"] > 1 and (details["tries"] - 1) % 5 == 0:
41
- print(f"Retrying async API call (attempt {details['tries'] - 1})")
42
-
43
-
44
- def on_backoff_handler_sync(details):
45
- # Print every 5th retry attempt, excluding the first retry
46
- if details["tries"] > 1 and (details["tries"] - 1) % 5 == 0:
47
- print(f"Retrying sync API call (attempt {details['tries'] - 1})")
48
-
49
-
50
- class OpenAIStandard(VendorBase):
51
- used_for_structured_outputs: bool = True
52
- exceptions_to_retry: List = DEFAULT_EXCEPTIONS_TO_RETRY
53
- sync_client: Any
54
- async_client: Any
55
-
56
- def __init__(
57
- self,
58
- sync_client: Any,
59
- async_client: Any,
60
- exceptions_to_retry: List[Exception] = DEFAULT_EXCEPTIONS_TO_RETRY,
61
- used_for_structured_outputs: bool = False,
62
- ):
63
- self.sync_client = sync_client
64
- self.async_client = async_client
65
- self.used_for_structured_outputs = used_for_structured_outputs
66
- self.exceptions_to_retry = exceptions_to_retry
67
-
68
- # @backoff.on_exception(
69
- # backoff.expo,
70
- # exceptions_to_retry,
71
- # max_tries=BACKOFF_TOLERANCE,
72
- # on_backoff=on_backoff_handler_async,
73
- # on_giveup=lambda e: print(e),
74
- # )
75
- async def _hit_api_async(
76
- self,
77
- model: str,
78
- messages: List[Dict[str, Any]],
79
- lm_config: Dict[str, Any],
80
- use_ephemeral_cache_only: bool = False,
81
- reasoning_effort: str = "high",
82
- tools: Optional[List[BaseTool]] = None,
83
- ) -> BaseLMResponse:
84
- assert (
85
- lm_config.get("response_model", None) is None
86
- ), "response_model is not supported for standard calls"
87
- messages = special_orion_transform(model, messages)
88
- used_cache_handler = get_cache_handler(use_ephemeral_cache_only)
89
- cache_result = used_cache_handler.hit_managed_cache(
90
- model, messages, lm_config=lm_config, tools=tools, reasoning_effort=reasoning_effort
91
- )
92
- if cache_result:
93
- return cache_result
94
-
95
- # Common API call params
96
- api_params = {
97
- "model": model,
98
- "messages": messages,
99
- }
100
- # Add max_tokens if present in lm_config
101
- if "max_tokens" in lm_config:
102
- api_params["max_completion_tokens"] = lm_config["max_tokens"]
103
-
104
- # Add tools if provided
105
- if tools:
106
- api_params["tools"] = []
107
- for tool in tools:
108
- if isinstance(tool, BaseTool):
109
- api_params["tools"].append(tool.to_openai_tool())
110
- else:
111
- api_params["tools"].append(tool)
112
-
113
- # Only add temperature for non o1/o3 models
114
- if model not in openai_reasoners:
115
- api_params["temperature"] = lm_config.get(
116
- "temperature", SPECIAL_BASE_TEMPS.get(model, 0)
117
- )
118
-
119
- # Add reasoning_effort only for o3-mini
120
- if model in openai_reasoners:
121
- print("Reasoning effort:", reasoning_effort)
122
- api_params["reasoning_effort"] = reasoning_effort
123
-
124
- output = await self.async_client.chat.completions.create(**api_params)
125
- message = output.choices[0].message
126
-
127
- # Convert tool calls to dict format
128
- tool_calls = None
129
- if message.tool_calls:
130
- tool_calls = [
131
- {
132
- "id": tc.id,
133
- "type": tc.type,
134
- "function": {
135
- "name": tc.function.name,
136
- "arguments": tc.function.arguments,
137
- },
138
- }
139
- for tc in message.tool_calls
140
- ]
141
-
142
- lm_response = BaseLMResponse(
143
- raw_response=message.content or "", # Use empty string if no content
144
- structured_output=None,
145
- tool_calls=tool_calls,
146
- )
147
- used_cache_handler.add_to_managed_cache(
148
- model, messages, lm_config=lm_config, output=lm_response, tools=tools, reasoning_effort=reasoning_effort
149
- )
150
- return lm_response
151
-
152
- # @backoff.on_exception(
153
- # backoff.expo,
154
- # exceptions_to_retry,
155
- # max_tries=BACKOFF_TOLERANCE,
156
- # on_backoff=on_backoff_handler_sync,
157
- # on_giveup=lambda e: print(e),
158
- # )
159
- def _hit_api_sync(
160
- self,
161
- model: str,
162
- messages: List[Dict[str, Any]],
163
- lm_config: Dict[str, Any],
164
- use_ephemeral_cache_only: bool = False,
165
- reasoning_effort: str = "high",
166
- tools: Optional[List[BaseTool]] = None,
167
- ) -> BaseLMResponse:
168
- assert (
169
- lm_config.get("response_model", None) is None
170
- ), "response_model is not supported for standard calls"
171
- messages = special_orion_transform(model, messages)
172
- used_cache_handler = get_cache_handler(
173
- use_ephemeral_cache_only=use_ephemeral_cache_only
174
- )
175
- cache_result = used_cache_handler.hit_managed_cache(
176
- model, messages, lm_config=lm_config, tools=tools, reasoning_effort=reasoning_effort
177
- )
178
- if cache_result:
179
- return cache_result
180
-
181
- # Common API call params
182
- api_params = {
183
- "model": model,
184
- "messages": messages,
185
- }
186
- # Add max_tokens if present in lm_config
187
- if "max_tokens" in lm_config:
188
- api_params["max_tokens"] = lm_config["max_tokens"]
189
-
190
- # Add tools if provided
191
- if tools:
192
- api_params["tools"] = []
193
- for tool in tools:
194
- if isinstance(tool, BaseTool):
195
- api_params["tools"].append(tool.to_openai_tool())
196
- else:
197
- api_params["tools"].append(tool)
198
-
199
- # Only add temperature for non o1/o3 models
200
- if model not in openai_reasoners:
201
- api_params["temperature"] = lm_config.get(
202
- "temperature", SPECIAL_BASE_TEMPS.get(model, 0)
203
- )
204
-
205
- # Add reasoning_effort only for o3-mini
206
- if model in openai_reasoners:
207
- api_params["reasoning_effort"] = reasoning_effort
208
-
209
- output = self.sync_client.chat.completions.create(**api_params)
210
- message = output.choices[0].message
211
-
212
- # Convert tool calls to dict format
213
- tool_calls = None
214
- if message.tool_calls:
215
- tool_calls = [
216
- {
217
- "id": tc.id,
218
- "type": tc.type,
219
- "function": {
220
- "name": tc.function.name,
221
- "arguments": tc.function.arguments,
222
- },
223
- }
224
- for tc in message.tool_calls
225
- ]
226
-
227
- lm_response = BaseLMResponse(
228
- raw_response=message.content or "", # Use empty string if no content
229
- structured_output=None,
230
- tool_calls=tool_calls,
231
- )
232
- used_cache_handler.add_to_managed_cache(
233
- model, messages, lm_config=lm_config, output=lm_response, tools=tools, reasoning_effort=reasoning_effort
234
- )
235
- return lm_response
236
-
237
- async def _hit_api_async_structured_output(
238
- self,
239
- model: str,
240
- messages: List[Dict[str, Any]],
241
- response_model: BaseModel,
242
- temperature: float,
243
- use_ephemeral_cache_only: bool = False,
244
- reasoning_effort: str = "high",
245
- tools: Optional[List[BaseTool]] = None,
246
- ) -> BaseLMResponse:
247
- lm_config = {"temperature": temperature, "response_model": response_model}
248
- used_cache_handler = get_cache_handler(use_ephemeral_cache_only)
249
- cache_result: Union[BaseLMResponse, None] = (
250
- used_cache_handler.hit_managed_cache(
251
- model,
252
- messages,
253
- lm_config=lm_config,
254
- tools=tools,
255
- reasoning_effort=reasoning_effort,
256
- )
257
- )
258
- if cache_result is not None:
259
- return cache_result
260
-
261
- # Common API call params
262
- api_params = {
263
- "model": model,
264
- "messages": messages,
265
- }
266
-
267
- # Add tools if provided
268
- if tools:
269
- api_params["tools"] = []
270
- for tool in tools:
271
- if isinstance(tool, BaseTool):
272
- api_params["tools"].append(tool.to_openai_tool())
273
- else:
274
- api_params["tools"].append(tool)
275
-
276
- # Only add temperature for non o1/o3 models
277
- if model not in openai_reasoners:
278
- api_params["temperature"] = lm_config.get(
279
- "temperature", SPECIAL_BASE_TEMPS.get(model, 0)
280
- )
281
-
282
- # Add reasoning_effort only for o3-mini
283
- if model in openai_reasoners:
284
- api_params["reasoning_effort"] = reasoning_effort
285
-
286
- output = await self.async_client.chat.completions.create(**api_params)
287
-
288
- structured_output_api_result = response_model(
289
- **output.choices[0].message.content
290
- )
291
- tool_calls = output.choices[0].message.tool_calls
292
- lm_response = BaseLMResponse(
293
- raw_response=output.choices[0].message.content,
294
- structured_output=structured_output_api_result,
295
- tool_calls=tool_calls,
296
- )
297
- used_cache_handler.add_to_managed_cache(
298
- model,
299
- messages,
300
- lm_config=lm_config,
301
- output=lm_response,
302
- tools=tools,
303
- reasoning_effort=reasoning_effort,
304
- )
305
- return lm_response
306
-
307
- def _hit_api_sync_structured_output(
308
- self,
309
- model: str,
310
- messages: List[Dict[str, Any]],
311
- response_model: BaseModel,
312
- temperature: float,
313
- use_ephemeral_cache_only: bool = False,
314
- reasoning_effort: str = "high",
315
- tools: Optional[List[BaseTool]] = None,
316
- ) -> BaseLMResponse:
317
- lm_config = {"temperature": temperature, "response_model": response_model}
318
- used_cache_handler = get_cache_handler(use_ephemeral_cache_only)
319
- cache_result: Union[BaseLMResponse, None] = (
320
- used_cache_handler.hit_managed_cache(
321
- model,
322
- messages,
323
- lm_config=lm_config,
324
- tools=tools,
325
- reasoning_effort=reasoning_effort,
326
- )
327
- )
328
- if cache_result is not None:
329
- return cache_result
330
-
331
- # Common API call params
332
- api_params = {
333
- "model": model,
334
- "messages": messages,
335
- }
336
-
337
- # Add tools if provided
338
- if tools:
339
- api_params["tools"] = []
340
- for tool in tools:
341
- if isinstance(tool, BaseTool):
342
- api_params["tools"].append(tool.to_openai_tool())
343
- else:
344
- api_params["tools"].append(tool)
345
-
346
- # Only add temperature for non o1/o3 models
347
- if model not in openai_reasoners:
348
- api_params["temperature"] = lm_config.get(
349
- "temperature", SPECIAL_BASE_TEMPS.get(model, 0)
350
- )
351
-
352
- # Add reasoning_effort only for o3-mini
353
- if model in openai_reasoners:
354
- api_params["reasoning_effort"] = reasoning_effort
355
-
356
- output = self.sync_client.chat.completions.create(**api_params)
357
-
358
- structured_output_api_result = response_model(
359
- **output.choices[0].message.content
360
- )
361
- tool_calls = output.choices[0].message.tool_calls
362
- lm_response = BaseLMResponse(
363
- raw_response=output.choices[0].message.content,
364
- structured_output=structured_output_api_result,
365
- tool_calls=tool_calls,
366
- )
367
- used_cache_handler.add_to_managed_cache(
368
- model,
369
- messages,
370
- lm_config=lm_config,
371
- output=lm_response,
372
- tools=tools,
373
- reasoning_effort=reasoning_effort,
374
- )
375
- return lm_response
@@ -1,3 +0,0 @@
1
- import backoff
2
-
3
- BACKOFF_TOLERANCE = 20
File without changes
@@ -1,73 +0,0 @@
1
- import os
2
- from typing import Any, Dict, List, Optional, Tuple
3
-
4
- from openai import AsyncOpenAI, OpenAI
5
-
6
- from synth_ai.zyk.lms.tools.base import BaseTool
7
- from synth_ai.zyk.lms.vendors.openai_standard import OpenAIStandard
8
-
9
-
10
- class DeepSeekAPI(OpenAIStandard):
11
- def __init__(self):
12
- # print("Setting up DeepSeek API")
13
- self.sync_client = OpenAI(
14
- api_key=os.environ.get("DEEPSEEK_API_KEY"),
15
- base_url="https://api.deepseek.com",
16
- )
17
- self.async_client = AsyncOpenAI(
18
- api_key=os.environ.get("DEEPSEEK_API_KEY"),
19
- base_url="https://api.deepseek.com",
20
- )
21
-
22
- def _convert_tools_to_openai_format(self, tools: List[BaseTool]) -> List[Dict]:
23
- return [tool.to_openai_tool() for tool in tools]
24
-
25
- async def _private_request_async(
26
- self,
27
- messages: List[Dict],
28
- temperature: float = 0,
29
- model_name: str = "deepseek-chat",
30
- reasoning_effort: str = "high",
31
- tools: Optional[List[BaseTool]] = None,
32
- lm_config: Optional[Dict[str, Any]] = None,
33
- ) -> Tuple[str, Optional[List[Dict]]]:
34
- request_params = {
35
- "model": model_name,
36
- "messages": messages,
37
- "temperature": temperature,
38
- }
39
-
40
- if tools:
41
- request_params["tools"] = self._convert_tools_to_openai_format(tools)
42
-
43
- response = await self.async_client.chat.completions.create(**request_params)
44
- message = response.choices[0].message
45
-
46
- return message.content, message.tool_calls if hasattr(
47
- message, "tool_calls"
48
- ) else None
49
-
50
- def _private_request_sync(
51
- self,
52
- messages: List[Dict],
53
- temperature: float = 0,
54
- model_name: str = "deepseek-chat",
55
- reasoning_effort: str = "high",
56
- tools: Optional[List[BaseTool]] = None,
57
- lm_config: Optional[Dict[str, Any]] = None,
58
- ) -> Tuple[str, Optional[List[Dict]]]:
59
- request_params = {
60
- "model": model_name,
61
- "messages": messages,
62
- "temperature": temperature,
63
- }
64
-
65
- if tools:
66
- request_params["tools"] = self._convert_tools_to_openai_format(tools)
67
-
68
- response = self.sync_client.chat.completions.create(**request_params)
69
- message = response.choices[0].message
70
-
71
- return message.content, message.tool_calls if hasattr(
72
- message, "tool_calls"
73
- ) else None
@@ -1,16 +0,0 @@
1
- import os
2
-
3
- from dotenv import load_dotenv
4
- from groq import AsyncGroq, Groq
5
-
6
- from synth_ai.zyk.lms.vendors.openai_standard import OpenAIStandard
7
-
8
- load_dotenv()
9
-
10
-
11
- class GroqAPI(OpenAIStandard):
12
- def __init__(self):
13
- super().__init__(
14
- sync_client=Groq(api_key=os.getenv("GROQ_API_KEY")),
15
- async_client=AsyncGroq(api_key=os.getenv("GROQ_API_KEY")),
16
- )
@@ -1,14 +0,0 @@
1
- from openai import OpenAI, AsyncOpenAI
2
- from synth_ai.zyk.lms.vendors.openai_standard import OpenAIStandard
3
-
4
-
5
- class OllamaAPI(OpenAIStandard):
6
- def __init__(self):
7
- self.sync_client = OpenAI(
8
- base_url="http://localhost:11434/v1",
9
- api_key="ollama", # required, but unused
10
- )
11
- self.async_client = AsyncOpenAI(
12
- base_url="http://localhost:11434/v1",
13
- api_key="ollama", # required, but unused
14
- )
@@ -1,11 +0,0 @@
1
- import os
2
-
3
- from together import AsyncTogether, Together
4
-
5
- from synth_ai.zyk.lms.vendors.openai_standard import OpenAIStandard
6
-
7
-
8
- class TogetherAPI(OpenAIStandard):
9
- def __init__(self):
10
- self.sync_client = Together(api_key=os.getenv("TOGETHER_API_KEY"))
11
- self.async_client = AsyncTogether(api_key=os.getenv("TOGETHER_API_KEY"))