Coverage for src/integry/utils/common.py: 27%
20 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-03-26 01:26 +0500
« prev ^ index » next coverage.py v7.6.1, created at 2025-03-26 01:26 +0500
1import hashlib, hmac
2from typing import (
3 Any,
4)
7def get_hash(app_secret: str, user_id: str):
8 hash = hmac.new(
9 bytearray(app_secret, "utf-8"),
10 bytearray(user_id, "utf-8"),
11 digestmod=hashlib.sha256,
12 ).hexdigest()
13 return hash
16def generate_docstring_from_schema_for_smolagent(schema: dict[str, Any]) -> str:
17 """
18 Generates a dynamic docstring based on a given JSON schema.
20 Args:
21 schema (dict): JSON schema containing parameter definitions.
23 Returns:
24 Formatted docstring with parameter details.
25 """
26 description = schema.get("description", "No description provided.")
28 docstring = f"{description}\n\n"
29 docstring += "Args:\n"
30 docstring += f" kwargs: A dictionary containing the following keys:\n"
32 parameters = schema.get("parameters", {})
33 properties = parameters.get("properties", {})
34 required_fields = parameters.get("required", [])
36 for param, details in properties.items():
37 param_type = details.get("type")
38 param_description = details.get("description", "No description available.")
39 is_required = "(required)" if param in required_fields else "(optional)"
40 docstring += f" {param} ({param_type}): {param_description} {is_required}\n"
42 docstring += f"\nReturns:\n dict: Response for the {schema.get('name', '')}.\n"
43 return docstring