Skip to content

Commit

Permalink
Merge pull request #24 from DataUSA/chat-wrapper
Browse files Browse the repository at this point in the history
json any shape comparer + shapes
  • Loading branch information
pippo-sci authored Apr 8, 2024
2 parents 882323f + 74fdb21 commit bc134ec
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 10 deletions.
20 changes: 11 additions & 9 deletions api/setup/json_comparer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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)
80 changes: 80 additions & 0 deletions api/src/wrapper/reflexionWrappper.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion api/src/wrapper_datausa2.json
Original file line number Diff line number Diff line change
Expand Up @@ -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":[
Expand Down

0 comments on commit bc134ec

Please sign in to comment.