nous-genai 0.1.0__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 (45) hide show
  1. nous/__init__.py +3 -0
  2. nous/genai/__init__.py +56 -0
  3. nous/genai/__main__.py +3 -0
  4. nous/genai/_internal/__init__.py +1 -0
  5. nous/genai/_internal/capability_rules.py +476 -0
  6. nous/genai/_internal/config.py +102 -0
  7. nous/genai/_internal/errors.py +63 -0
  8. nous/genai/_internal/http.py +951 -0
  9. nous/genai/_internal/json_schema.py +54 -0
  10. nous/genai/cli.py +1316 -0
  11. nous/genai/client.py +719 -0
  12. nous/genai/mcp_cli.py +275 -0
  13. nous/genai/mcp_server.py +1080 -0
  14. nous/genai/providers/__init__.py +15 -0
  15. nous/genai/providers/aliyun.py +535 -0
  16. nous/genai/providers/anthropic.py +483 -0
  17. nous/genai/providers/gemini.py +1606 -0
  18. nous/genai/providers/openai.py +1909 -0
  19. nous/genai/providers/tuzi.py +1158 -0
  20. nous/genai/providers/volcengine.py +273 -0
  21. nous/genai/reference/__init__.py +17 -0
  22. nous/genai/reference/catalog.py +206 -0
  23. nous/genai/reference/mappings.py +467 -0
  24. nous/genai/reference/mode_overrides.py +26 -0
  25. nous/genai/reference/model_catalog.py +82 -0
  26. nous/genai/reference/model_catalog_data/__init__.py +1 -0
  27. nous/genai/reference/model_catalog_data/aliyun.py +98 -0
  28. nous/genai/reference/model_catalog_data/anthropic.py +10 -0
  29. nous/genai/reference/model_catalog_data/google.py +45 -0
  30. nous/genai/reference/model_catalog_data/openai.py +44 -0
  31. nous/genai/reference/model_catalog_data/tuzi_anthropic.py +21 -0
  32. nous/genai/reference/model_catalog_data/tuzi_google.py +19 -0
  33. nous/genai/reference/model_catalog_data/tuzi_openai.py +75 -0
  34. nous/genai/reference/model_catalog_data/tuzi_web.py +136 -0
  35. nous/genai/reference/model_catalog_data/volcengine.py +107 -0
  36. nous/genai/tools/__init__.py +13 -0
  37. nous/genai/tools/output_parser.py +119 -0
  38. nous/genai/types.py +416 -0
  39. nous/py.typed +1 -0
  40. nous_genai-0.1.0.dist-info/METADATA +200 -0
  41. nous_genai-0.1.0.dist-info/RECORD +45 -0
  42. nous_genai-0.1.0.dist-info/WHEEL +5 -0
  43. nous_genai-0.1.0.dist-info/entry_points.txt +4 -0
  44. nous_genai-0.1.0.dist-info/licenses/LICENSE +190 -0
  45. nous_genai-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,54 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+
5
+ from .errors import invalid_request_error, not_supported_error
6
+
7
+ _GEMINI_RESPONSE_SCHEMA_TYPES = frozenset(
8
+ {
9
+ "TYPE_UNSPECIFIED",
10
+ "STRING",
11
+ "NUMBER",
12
+ "INTEGER",
13
+ "BOOLEAN",
14
+ "ARRAY",
15
+ "OBJECT",
16
+ }
17
+ )
18
+
19
+
20
+ def reject_gemini_response_schema_dict(schema: dict[str, Any]) -> None:
21
+ t = schema.get("type")
22
+ if isinstance(t, str) and t in _GEMINI_RESPONSE_SCHEMA_TYPES:
23
+ raise invalid_request_error(
24
+ "output.text.json_schema must be JSON Schema (not Gemini responseSchema); "
25
+ "pass a Python type/model or use provider_options.google.generationConfig.responseSchema"
26
+ )
27
+
28
+
29
+ def python_type_to_json_schema(schema: Any) -> dict[str, Any]:
30
+ try:
31
+ from pydantic import TypeAdapter
32
+ except ModuleNotFoundError as e: # pragma: no cover
33
+ raise not_supported_error(
34
+ "pydantic is required for python-type output.text.json_schema"
35
+ ) from e
36
+
37
+ try:
38
+ return TypeAdapter(schema).json_schema()
39
+ except Exception:
40
+ pass
41
+
42
+ try:
43
+ return TypeAdapter(type(schema)).json_schema()
44
+ except Exception as e:
45
+ raise invalid_request_error(
46
+ "output.text.json_schema must be a JSON Schema object or a Python type supported by pydantic TypeAdapter"
47
+ ) from e
48
+
49
+
50
+ def normalize_json_schema(schema: Any) -> dict[str, Any]:
51
+ if isinstance(schema, dict):
52
+ reject_gemini_response_schema_dict(schema)
53
+ return schema
54
+ return python_type_to_json_schema(schema)