Update app.py
Browse files
app.py
CHANGED
|
@@ -120,11 +120,6 @@ function_schema = [
|
|
| 120 |
}
|
| 121 |
]
|
| 122 |
|
| 123 |
-
function_map = {
|
| 124 |
-
"search_csv": search_csv,
|
| 125 |
-
"count_unique": count_unique,
|
| 126 |
-
}
|
| 127 |
-
|
| 128 |
# --- Chat interface
|
| 129 |
st.markdown("### Conversation")
|
| 130 |
for i, msg in enumerate(st.session_state.messages[1:]): # Skip system message for display
|
|
@@ -155,7 +150,7 @@ def send_message():
|
|
| 155 |
"https://api.openai.com/v1/chat/completions",
|
| 156 |
headers=HEADERS,
|
| 157 |
json={
|
| 158 |
-
"model": "gpt-
|
| 159 |
"messages": chat_messages,
|
| 160 |
"functions": function_schema,
|
| 161 |
"function_call": "auto",
|
|
@@ -173,9 +168,11 @@ def send_message():
|
|
| 173 |
func_name = msg["function_call"]["name"]
|
| 174 |
args_json = msg["function_call"]["arguments"]
|
| 175 |
args = json.loads(args_json)
|
| 176 |
-
#
|
| 177 |
-
if func_name
|
| 178 |
-
function_result =
|
|
|
|
|
|
|
| 179 |
else:
|
| 180 |
function_result = {"error": f"Unknown function: {func_name}"}
|
| 181 |
st.session_state.messages.append({
|
|
@@ -193,7 +190,7 @@ def send_message():
|
|
| 193 |
"https://api.openai.com/v1/chat/completions",
|
| 194 |
headers=HEADERS,
|
| 195 |
json={
|
| 196 |
-
"model": "gpt-
|
| 197 |
"messages": followup_messages,
|
| 198 |
"temperature": 0,
|
| 199 |
"max_tokens": 1500,
|
|
|
|
| 120 |
}
|
| 121 |
]
|
| 122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
# --- Chat interface
|
| 124 |
st.markdown("### Conversation")
|
| 125 |
for i, msg in enumerate(st.session_state.messages[1:]): # Skip system message for display
|
|
|
|
| 150 |
"https://api.openai.com/v1/chat/completions",
|
| 151 |
headers=HEADERS,
|
| 152 |
json={
|
| 153 |
+
"model": "gpt-4.1",
|
| 154 |
"messages": chat_messages,
|
| 155 |
"functions": function_schema,
|
| 156 |
"function_call": "auto",
|
|
|
|
| 168 |
func_name = msg["function_call"]["name"]
|
| 169 |
args_json = msg["function_call"]["arguments"]
|
| 170 |
args = json.loads(args_json)
|
| 171 |
+
# --- FIXED: Only pass the expected arg for each function
|
| 172 |
+
if func_name == "search_csv":
|
| 173 |
+
function_result = search_csv(args.get("query", ""))
|
| 174 |
+
elif func_name == "count_unique":
|
| 175 |
+
function_result = count_unique(args.get("column", ""))
|
| 176 |
else:
|
| 177 |
function_result = {"error": f"Unknown function: {func_name}"}
|
| 178 |
st.session_state.messages.append({
|
|
|
|
| 190 |
"https://api.openai.com/v1/chat/completions",
|
| 191 |
headers=HEADERS,
|
| 192 |
json={
|
| 193 |
+
"model": "gpt-4o",
|
| 194 |
"messages": followup_messages,
|
| 195 |
"temperature": 0,
|
| 196 |
"max_tokens": 1500,
|