@@ -102,9 +102,6 @@ def _load_prompt_and_model(source_type: Any = None, api_key: str = None):
102102 "IRREGULAR" : MODEL_CONFIG_NAME ,
103103 }
104104
105- if not api_key :
106- api_key = os .environ .get ("DASHSCOPE_API_KEY" )
107-
108105 models_2_model_and_formatter = {
109106 MODEL_CONFIG_NAME : [
110107 DashScopeChatModel (
@@ -360,16 +357,19 @@ def _wrap_data_response(self, response: Dict[str, Any]) -> Dict[str, Any]:
360357 # they contain tables. Each table contains columns and description
361358 if "tables" in self .data and "tables" in response :
362359 new_schema ["tables" ] = []
363- for i , table in enumerate (self .data ["tables" ]):
364- # Ensure alignment between schema tables and resp tables
365- # TODO: It matches by order, by name would be more robust.
366- if i >= len (response ["tables" ]):
367- # LLM returns less tables than the original schema
368- break
369- assert response ["tables" ][i ]["name" ] == table ["name" ]
360+ # Build a map for response tables and descriptions
361+ res_des_map = {
362+ table ["name" ]: table ["description" ]
363+ for table in response ["tables" ]
364+ }
365+ for table in self .data ["tables" ]:
366+ table_name = table ["name" ]
367+ if table_name not in res_des_map :
368+ continue
370369 new_table = {}
371- new_table ["name" ] = table ["name" ]
372- new_table ["description" ] = response ["tables" ][i ]["description" ]
370+ new_table ["name" ] = table_name
371+ # Retain the desrciption from the LLM response
372+ new_table ["description" ] = res_des_map [table_name ]
373373 if "columns" in table :
374374 new_table ["columns" ] = table ["columns" ]
375375 if "irregular_judgment" in table :
@@ -687,15 +687,20 @@ def _generate_content(self, prompt, data):
687687 Returns:
688688 List containing image and text components for the LLM call
689689 """
690- contents = []
691690 # Convert image paths according to the model requirements
692- contents . append (
691+ contents = [
693692 {
694- "image" : data ,
693+ "text" : prompt ,
694+ "type" : "text" ,
695695 },
696- )
697- # append text
698- contents .append ({"text" : prompt })
696+ {
697+ "source" : {
698+ "url" : data ,
699+ "type" : "url" ,
700+ },
701+ "type" : "image" ,
702+ },
703+ ]
699704 return contents
700705
701706 def _wrap_data_response (self , response : Dict [str , Any ]) -> Dict [str , Any ]:
0 commit comments