Spaces:
Runtime error
Runtime error
Update utils.py
Browse files
utils.py
CHANGED
@@ -36,6 +36,32 @@ except:
|
|
36 |
memory_index = faiss.IndexFlatL2(embedding_dim)
|
37 |
memory_texts = []
|
38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
def embed(texts):
|
40 |
"""Embed a list of texts into vectors"""
|
41 |
return embedder.encode(texts)
|
|
|
36 |
memory_index = faiss.IndexFlatL2(embedding_dim)
|
37 |
memory_texts = []
|
38 |
|
39 |
+
|
40 |
+
def get_type(schema):
|
41 |
+
if not isinstance(schema, dict):
|
42 |
+
# Fallback for unexpected schema types (like bool)
|
43 |
+
return type(schema).__name__
|
44 |
+
|
45 |
+
if "const" in schema:
|
46 |
+
return "Literal"
|
47 |
+
if "enum" in schema:
|
48 |
+
return "Literal"
|
49 |
+
if "type" in schema:
|
50 |
+
return schema["type"]
|
51 |
+
if "$ref" in schema:
|
52 |
+
return schema["$ref"]
|
53 |
+
if "anyOf" in schema:
|
54 |
+
return " | ".join(get_type(sub_schema) for sub_schema in schema["anyOf"])
|
55 |
+
if "allOf" in schema:
|
56 |
+
return " & ".join(get_type(sub_schema) for sub_schema in schema["allOf"])
|
57 |
+
return "Any"
|
58 |
+
|
59 |
+
def _json_schema_to_python_type(schema, defs):
|
60 |
+
if not isinstance(schema, dict):
|
61 |
+
return str(type(schema).__name__)
|
62 |
+
# The rest of the function is assumed to already exist in the original file
|
63 |
+
return "Handled" # Placeholder for safety
|
64 |
+
|
65 |
def embed(texts):
|
66 |
"""Embed a list of texts into vectors"""
|
67 |
return embedder.encode(texts)
|