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.
- nous/__init__.py +3 -0
- nous/genai/__init__.py +56 -0
- nous/genai/__main__.py +3 -0
- nous/genai/_internal/__init__.py +1 -0
- nous/genai/_internal/capability_rules.py +476 -0
- nous/genai/_internal/config.py +102 -0
- nous/genai/_internal/errors.py +63 -0
- nous/genai/_internal/http.py +951 -0
- nous/genai/_internal/json_schema.py +54 -0
- nous/genai/cli.py +1316 -0
- nous/genai/client.py +719 -0
- nous/genai/mcp_cli.py +275 -0
- nous/genai/mcp_server.py +1080 -0
- nous/genai/providers/__init__.py +15 -0
- nous/genai/providers/aliyun.py +535 -0
- nous/genai/providers/anthropic.py +483 -0
- nous/genai/providers/gemini.py +1606 -0
- nous/genai/providers/openai.py +1909 -0
- nous/genai/providers/tuzi.py +1158 -0
- nous/genai/providers/volcengine.py +273 -0
- nous/genai/reference/__init__.py +17 -0
- nous/genai/reference/catalog.py +206 -0
- nous/genai/reference/mappings.py +467 -0
- nous/genai/reference/mode_overrides.py +26 -0
- nous/genai/reference/model_catalog.py +82 -0
- nous/genai/reference/model_catalog_data/__init__.py +1 -0
- nous/genai/reference/model_catalog_data/aliyun.py +98 -0
- nous/genai/reference/model_catalog_data/anthropic.py +10 -0
- nous/genai/reference/model_catalog_data/google.py +45 -0
- nous/genai/reference/model_catalog_data/openai.py +44 -0
- nous/genai/reference/model_catalog_data/tuzi_anthropic.py +21 -0
- nous/genai/reference/model_catalog_data/tuzi_google.py +19 -0
- nous/genai/reference/model_catalog_data/tuzi_openai.py +75 -0
- nous/genai/reference/model_catalog_data/tuzi_web.py +136 -0
- nous/genai/reference/model_catalog_data/volcengine.py +107 -0
- nous/genai/tools/__init__.py +13 -0
- nous/genai/tools/output_parser.py +119 -0
- nous/genai/types.py +416 -0
- nous/py.typed +1 -0
- nous_genai-0.1.0.dist-info/METADATA +200 -0
- nous_genai-0.1.0.dist-info/RECORD +45 -0
- nous_genai-0.1.0.dist-info/WHEEL +5 -0
- nous_genai-0.1.0.dist-info/entry_points.txt +4 -0
- nous_genai-0.1.0.dist-info/licenses/LICENSE +190 -0
- 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)
|