Spaces:
Running
Running
Update lang_assistant/langhelper.py
Browse files
lang_assistant/langhelper.py
CHANGED
|
@@ -22,11 +22,13 @@ from langchain.chat_models import ChatOpenAI
|
|
| 22 |
from langchain.prompts.chat import SystemMessage, HumanMessagePromptTemplate, HumanMessage, AIMessage
|
| 23 |
from langchain.agents import create_pandas_dataframe_agent
|
| 24 |
|
| 25 |
-
|
| 26 |
|
| 27 |
from dotenv import load_dotenv, find_dotenv
|
| 28 |
_ = load_dotenv(find_dotenv()) # read local .env file
|
| 29 |
|
|
|
|
|
|
|
| 30 |
def summary_extractor_from_df(df:pd.DataFrame)-> str:
|
| 31 |
|
| 32 |
try:
|
|
@@ -62,7 +64,7 @@ def chat_with_df(query, table_name = None):
|
|
| 62 |
df = pd.read_csv(filename)
|
| 63 |
|
| 64 |
agent = create_pandas_dataframe_agent(
|
| 65 |
-
ChatOpenAI(temperature=0, model=
|
| 66 |
df,
|
| 67 |
agent_type=AgentType.OPENAI_FUNCTIONS,
|
| 68 |
verbose=True
|
|
@@ -71,7 +73,7 @@ def chat_with_df(query, table_name = None):
|
|
| 71 |
res_query = agent.run(query)
|
| 72 |
except Exception as e:
|
| 73 |
print(str(e))
|
| 74 |
-
res_query = "ERROR"
|
| 75 |
|
| 76 |
return res_query
|
| 77 |
|
|
@@ -225,12 +227,12 @@ def generate_graphdata(query, table_name = None):
|
|
| 225 |
reference_data=jsondf,
|
| 226 |
format_instructions=format_instructions)
|
| 227 |
|
| 228 |
-
llm = ChatOpenAI(model =
|
| 229 |
response = llm(customer_messages)
|
| 230 |
json_pandassteps_charttype = output_parser.parse(response.content)
|
| 231 |
print("pandas steps and charttype" , json_pandassteps_charttype)
|
| 232 |
agent = create_pandas_dataframe_agent(
|
| 233 |
-
ChatOpenAI(temperature=0, model=
|
| 234 |
df,
|
| 235 |
agent_type=AgentType.OPENAI_FUNCTIONS,
|
| 236 |
verbose=True,
|
|
|
|
| 22 |
from langchain.prompts.chat import SystemMessage, HumanMessagePromptTemplate, HumanMessage, AIMessage
|
| 23 |
from langchain.agents import create_pandas_dataframe_agent
|
| 24 |
|
| 25 |
+
#current_model_id = 'gpt-4o-mini'
|
| 26 |
|
| 27 |
from dotenv import load_dotenv, find_dotenv
|
| 28 |
_ = load_dotenv(find_dotenv()) # read local .env file
|
| 29 |
|
| 30 |
+
current_model_id = os.getenv('model_id')
|
| 31 |
+
|
| 32 |
def summary_extractor_from_df(df:pd.DataFrame)-> str:
|
| 33 |
|
| 34 |
try:
|
|
|
|
| 64 |
df = pd.read_csv(filename)
|
| 65 |
|
| 66 |
agent = create_pandas_dataframe_agent(
|
| 67 |
+
ChatOpenAI(temperature=0, model=current_model_id),
|
| 68 |
df,
|
| 69 |
agent_type=AgentType.OPENAI_FUNCTIONS,
|
| 70 |
verbose=True
|
|
|
|
| 73 |
res_query = agent.run(query)
|
| 74 |
except Exception as e:
|
| 75 |
print(str(e))
|
| 76 |
+
res_query = f"ERROR : {str(e)[:150]}"
|
| 77 |
|
| 78 |
return res_query
|
| 79 |
|
|
|
|
| 227 |
reference_data=jsondf,
|
| 228 |
format_instructions=format_instructions)
|
| 229 |
|
| 230 |
+
llm = ChatOpenAI(model = current_model_id, temperature = 0)
|
| 231 |
response = llm(customer_messages)
|
| 232 |
json_pandassteps_charttype = output_parser.parse(response.content)
|
| 233 |
print("pandas steps and charttype" , json_pandassteps_charttype)
|
| 234 |
agent = create_pandas_dataframe_agent(
|
| 235 |
+
ChatOpenAI(temperature=0, model=current_model_id),
|
| 236 |
df,
|
| 237 |
agent_type=AgentType.OPENAI_FUNCTIONS,
|
| 238 |
verbose=True,
|