diff --git a/api/setup/json_comparer.py b/api/setup/json_comparer.py index 33e8afc..ca50ee0 100644 --- a/api/setup/json_comparer.py +++ b/api/setup/json_comparer.py @@ -16,7 +16,7 @@ def get_children(node, parent_id): return None -def repath_json(goal, alternaive, visited): +def repath_json(goal, alternative, visited): """ Rebuild the route to any goal leaf in a JSON * goal: node_id of goal node @@ -32,7 +32,7 @@ def repath_json(goal, alternaive, visited): parent, position = visited[parent] #rebuild the path in the alternetive json - query = alternaive + query = alternative while path: current = path.pop() query = query[current] @@ -53,24 +53,26 @@ def json_iterator(json, json_compare): ids += 1 visited[ids] = (parent_id, position) children = get_children(node, ids) + alt_node = repath_json(ids, json_compare, visited) + if children: + #check shape + if len(node) != len(alt_node): + print(node, alt_node) queue += children else: # is leaf - # follow path to value of alternative json - value = repath_json(ids, json_compare, visited) - - if node != value: - print('Old value: {}, New value: {}'.format(node, value)) + #alt_node = repath_json(ids, json_compare, visited) + if node != alt_node: + print('Old value: {}, New value: {}'.format(node, alt_node)) if __name__ == '__main__': - with open(f'../src/wrapper_datausa.json') as f: to_parse = json.load(f) - with open(f'../src/wrapper_datausa2.json') as f: + with open(f'../src/wrapper_datausa2.json') as f: to_compare = json.load(f) json_iterator(to_parse, to_compare) \ No newline at end of file diff --git a/api/src/wrapper/reflexionWrappper.py b/api/src/wrapper/reflexionWrappper.py new file mode 100644 index 0000000..b3d98af --- /dev/null +++ b/api/src/wrapper/reflexionWrappper.py @@ -0,0 +1,80 @@ +from langchain_community.llms import Ollama +from langchain_community.chat_message_histories import ChatMessageHistory +from langchain_core.prompts import PromptTemplate +from langchain_core.runnables import RunnableSequence, RunnablePassthrough, RunnableLambda, RunnableParallel, chain +from langchain_core.output_parsers import JsonOutputParser +from wrapper.logsHandlerCallback import logsHandler +from langchain.globals import set_debug, set_verbose +from os import getenv +import json +from operator import itemgetter + + +TABLES_PATH = getenv('TABLES_PATH') +OLLAMA_URL = 'https://caleuche-ollama.datawheel.us' +CONFIG_FILE_NAME = 'wrapper_datausa.json' + +model = Ollama( + base_url= OLLAMA_URL, + model= "llama2:7b-chat-q8_0", + temperature= 0, + ).with_config( + seed= 123, + run_name= 'basic_llama', + ) + +model_adv = Ollama( + base_url= OLLAMA_URL, + model= 'mixtral:8x7b-instruct-v0.1-q4_K_M',#'gemma:7b-instruct-q4_K_M',// + system= '', + temperature= 0, +).with_config( + seed= 123, + run_name= 'advance_mixtral', +) + +# LLM Summary chat history + # Summary question + # route to question/no question/new question/complement question + +summary_sys_prompt = """ +You are an expert analyzing chat from questions. +""" + +summary_prompt = """ +Summarize the following chat history + +Output format: + +{{ + +}} + +""" +@chain +def route_question(info): + pass + + +# Use table_table selection +from ..table_selection.table_selector import get_relevant_tables_from_database + +# LLM Classification + # rerank RAG answer pick a cube + + + +# Call Schema Json to build Form JSON + + +# LLM validation + # Extract variables + # Route ask missing variables + # Offer members for missing variables + + + +# Build Chain + + +# Export function \ No newline at end of file diff --git a/api/src/wrapper_datausa2.json b/api/src/wrapper_datausa2.json index 1cbfb0d..8427d6d 100644 --- a/api/src/wrapper_datausa2.json +++ b/api/src/wrapper_datausa2.json @@ -9,7 +9,7 @@ }, { "name":"House election", - "metrics": ["number of votes"], + "metrics": ["number of votes","dogs"], "vars": ["political party", "US state", " candidate name"], "optional_vars": ["year"], "examples":[