
    6i,                    `    d dl mZ d dlZd dlZd dlmZ  e       rd dlZndZddZ	 	 	 	 ddZy)    )annotationsN)is_jmespath_availablec                d   | j                         r5| j                         j                         D ci c]  \  }}|	|| c}}S t        | j                               }t	        |      dkD  rt        d| d      t	        |      dk(  rt        d| j                  d             |d   S c c}}w )N   z+Regex has multiple unnamed groups!
Groups: 
r   zRegex has no capture groups:

)	groupdictitemslistgroupslen
ValueErrorgroup)
node_matchkeyvalr   s       a/mnt/e/genesis-system/.venv/lib/python3.12/site-packages/transformers/utils/chat_parsing_utils.py_parse_re_matchr      s    )3)=)=)?)E)E)G[XS#3?S[[ j'')*v;?KF8SUVWW[A?
@P@PQR@S?TUVVay \s
   
B,B,c           
        d|v r|d   S | y|j                  d      }d|v xs
 d|v xs d|v }|r!t        | t              st        d|  d|       |j                  d      }|j                  d      }|j                  d      }|4t	        j
                  || t        j                  	      }|syt        |      } |U|d
k7  rt        d| d|       t	        j                  || t        j                  	      D cg c]  }t        |       } }| sy||dk7  rt        d| d|       i }t	        j                  || t        j                  	      D ]A  }t        |      }	t        |	t              rd|	vsd|	vrt        d|	 d|       |	d   ||	d   <   C |} | syd|v r|d   }
|
dk(  rt        | t              st        d|  d|       |j                  di       }|j                  d      }|j                  dd      }	 t        j                  |       }|*t        t        d      t        j
                  |d   |      }|} nt        d|
 d|       d|v r2t        | t              st        d| d|  d|       |d   }| |v r||    } d |v rht        | t              st        d| d!|  d|       |d    }|j!                         D ],  \  }}t	        j"                  ||| t        j                  	      } . |dk(  ri }t        | t              rLd"|vrt        d#|  d|       |d"   j!                         D ]  \  }}t%        | |d"   |         }||||<   ! |S t        | t              r|j                  d"i       j!                         D ]6  \  }}d|v r	|d   ||<   || v rt%        | |   |      ||<   *d$|v s/|d$   ||<   8 d%|v r?| j!                         D ],  \  }}||j                  d"i       vst%        ||d%         ||<   . |S t        d&|        |d
k(  r| sg S g }d'|v rEt        | t&              st        d(|        | D ]   }|j)                  t%        ||d'                " |S d)|v rt        | t&              s#t+        |d)         d*k(  r| g} nt        d(|        t+        |       t+        |d)         k7  r,t        d+t+        |        d,t+        |d)          d-|  d|       t-        | |d)         D ]   \  }}|j)                  t%        ||             " |S t        d.|       |d/v r|t        | t              st        d0| d1|        |d2k(  rt/        |       S |d3k(  rt1        |       S |d4k(  r4| j3                         d5v ry6| j3                         d7v ryt        d8|        | S || S t        d9| d:|        c c}w # t        j                  $ r!}|r| }nt        d|  d|       Y d}~d}~ww xY w);a  
    This function takes content and a JSON schema which includes
    regex extractors, and recursively parses the content. The output
    should be a data structure matching the schema.

    Args:
        node_content: The content corresponding to this node. Usually a string, but can be something else
                      if the parent node has multiple capture groups or named groups. In that case,
                      we generally pass the capture groups straight through to the children of this node
                      and don't do any parsing at this level.
        node_schema: The schema node controlling the parsing.

    Returns:
        The parsed data structure for the current node.
    constNtypezx-regexzx-regex-iteratorzx-regex-key-valuezHSchema node got a non-string input, but has a regex for parsing.
Input: z	
Schema: )flagsarrayzSchema node with type z& cannot use x-regex-iterator.
Schema: objectz' cannot use x-regex-key-value.
Schema: r   valuezTRegex for x-regex-key-value must have named groups 'key' and 'value'.
Match groups: zx-parserjsonz/Node has JSON parser but got non-string input: zx-parser-args	transformallow_non_jsonFzNode has JSON parser but could not parse its contents as JSON. You can use the `allow_non_json` parser arg for nodes which may contain JSON or string content.

Content: z	

Error: zChat response schema includes a jmespath transformation, but jmespath is not installed. You can install it with `pip install jmespath`.zUnknown parser z for schema node: z	x-mappingz6 cannot use x-mapping on non-string content.
Content: zx-mapping-regexz< cannot use x-mapping-regex on non-string content.
Content: 
propertieszVObject node received string content but has no regex or parser to handle it.
Content: defaultadditionalPropertiesz=Expected a dict or str for schema node with type object, got r	   z>Expected a list or regex for schema node with type array, got prefixItemsr   zArray node has z items, but schema only has z prefixItems defined.
Content: z?Array node has no items or prefixItems schema defined.
Schema: )stringintegernumberbooleanz,Expected a string for schema node with type z, got r#   r$   r%   )true1T)false0zInvalid boolean value: zUnsupported schema type z for node: )get
isinstancestr	TypeErrorresearchDOTALLr   finditerdictr   r   loadsJSONDecodeErrorjmespathImportErrorr	   subrecursive_parser
   appendr   zipintfloatlower)node_contentnode_schema	node_type	has_regex
node_regexnode_regex_iteratornode_regex_to_dictr   output_contentmatch_groupsparserparser_argsr   r   parsed_jsonemappingmapping_regexpatternreplacementparsed_schemar   
child_nodechild_node_contentr   itemitem_schemas                              r   r8   r8      s   * +7##  'I[(s,>+,MsQdhsQsIL#6"^ $"m%
 	
 +J%//*<=$)<=YYz<ryyI
&z2&4YK?fgrfstuu !kk*=|SUS\S\]
 J'
 
 % 4YK?ghsgtuvv++&8,biiX 	HJ*:6LlD1U,5NRYamRm %%1N 3*m- 
 3?w2GN<./	H & [ Z(VlC0El^S]^i]jk  &///2>K#4I(__-=uEN"jj6 $#% b  'ook+.FT&Lvh6HVWW k!,,( 4(> *&-) 
 k*7""<0LK',,( 4(> *&-) 
 $$56$1$7$7$9 	W G[66';BIIVL	W HlC( ;.   ,~ .*m- 
 $/|#<#B#B#D <Z%4\;|C\]`Ca%b"%1);M#&< ! d+#.??<#D#J#J#L ?Zj()3G)<M#&L()8c9JJ)WM#&*,)3I)>M#&? &4"."4"4"6 iJC+//,"CC-<UKPfDg-hc*i ! [\h[ijkk	g	Ik!lD1"`am`n opp$ R$$_T;w;O%PQR  k)lD1{=12a7$0>L#&deqdr$stt< CM(B$CC %c,&7%88T;}567 8  ,~ .*m-  &){=7Q%R I!k$$_T;%GHI  _`k_lmnn	@	@,,J9+U[\h[ijkk	!|$$("&&)#!!#}4##%7 #:<.!IJJ  		29+[WXX
L '' !".K$ F  GS  FT  T_  `a  _b  c   s   :V??W W8W33W8)r   zre.Matchreturnz
dict | str)r>   zstr | list | dictr?   r2   )	
__future__r   r   r.   transformers.utilsr   r5   r   r8        r   <module>rY      sA    "  	 4 HQY#QYQYrX   