Generate JSON output from the model. Args: prompt: User prompt to generate from schema: JSON schema that the output should conform to system_prompt: System prompt (instructions for the model) temperature: Sampling temperature
(self,
prompt: str,
schema: Dict[str, Any],
system_prompt: Optional[str] = None,
temperature: Optional[float] = None,
default: Optional[Dict[str, Any]] = None,
**kwargs)
| 165 | raise |
| 166 | |
| 167 | async def generate_json(self, |
| 168 | prompt: str, |
| 169 | schema: Dict[str, Any], |
| 170 | system_prompt: Optional[str] = None, |
| 171 | temperature: Optional[float] = None, |
| 172 | default: Optional[Dict[str, Any]] = None, |
| 173 | **kwargs) -> Dict[str, Any]: |
| 174 | """ |
| 175 | Generate JSON output from the model. |
| 176 | |
| 177 | Args: |
| 178 | prompt: User prompt to generate from |
| 179 | schema: JSON schema that the output should conform to |
| 180 | system_prompt: System prompt (instructions for the model) |
| 181 | temperature: Sampling temperature (0.0 to 1.0) |
| 182 | default: Default JSON to return if generation fails |
| 183 | **kwargs: Additional model-specific parameters |
| 184 | |
| 185 | Returns: |
| 186 | JSON output as a Python dictionary |
| 187 | |
| 188 | Raises: |
| 189 | ModelError: If generation fails and no default is provided |
| 190 | """ |
| 191 | try: |
| 192 | return await self.generate_with_json_output( |
| 193 | prompt=prompt, |
| 194 | json_schema=schema, |
| 195 | system_prompt=system_prompt, |
| 196 | temperature=temperature, |
| 197 | **kwargs |
| 198 | ) |
| 199 | except Exception as e: |
| 200 | logger.error(f"Error in generate_json: {e}") |
| 201 | if default is not None: |
| 202 | logger.warning(f"Returning default JSON due to error: {e}") |
| 203 | return default |
| 204 | raise |
| 205 | |
| 206 | async def embed(self, text: Union[str, List[str]]) -> Union[List[float], List[List[float]]]: |
| 207 | """ |
no test coverage detected