zenaight commited on
Commit ·
d14240d
1
Parent(s): 0b6571b
Integrate lightweight LLM for extraction tasks in ai_chat.py
Browse files- Added a new lightweight LLM instance (llm_light) in config.py for simpler extraction tasks, optimizing performance with lower temperature and token limits.
- Updated the extract_and_update_persona function to utilize llm_light for persona extraction, enhancing efficiency in processing user inputs.
- ai_chat.py +2 -2
- config.py +8 -0
ai_chat.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
from langgraph.graph import StateGraph, END
|
| 2 |
from langchain_core.runnables import RunnableLambda
|
| 3 |
from typing import TypedDict
|
| 4 |
-
from config import llm, OPENAI_API_KEY
|
| 5 |
from database import get_session_messages, save_message, update_user_persona, update_user_intent, search_properties, end_session
|
| 6 |
import re
|
| 7 |
|
|
@@ -304,7 +304,7 @@ async def extract_and_update_persona(state):
|
|
| 304 |
"""
|
| 305 |
|
| 306 |
# c. Call the LLM
|
| 307 |
-
response = await
|
| 308 |
import json
|
| 309 |
import re
|
| 310 |
extracted = {}
|
|
|
|
| 1 |
from langgraph.graph import StateGraph, END
|
| 2 |
from langchain_core.runnables import RunnableLambda
|
| 3 |
from typing import TypedDict
|
| 4 |
+
from config import llm, llm_light, OPENAI_API_KEY
|
| 5 |
from database import get_session_messages, save_message, update_user_persona, update_user_intent, search_properties, end_session
|
| 6 |
import re
|
| 7 |
|
|
|
|
| 304 |
"""
|
| 305 |
|
| 306 |
# c. Call the LLM
|
| 307 |
+
response = await llm_light.ainvoke([{"role":"user","content":extraction_prompt}])
|
| 308 |
import json
|
| 309 |
import re
|
| 310 |
extracted = {}
|
config.py
CHANGED
|
@@ -25,6 +25,14 @@ else:
|
|
| 25 |
# --- OpenAI Client Setup ---
|
| 26 |
llm = ChatOpenAI(openai_api_key=OPENAI_API_KEY, model="gpt-4o-mini")
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
# Initialize LLM only if API key is available
|
| 29 |
if not OPENAI_API_KEY:
|
| 30 |
print("Warning: OPENAI_API_KEY not set. AI functionality will be limited.")
|
|
|
|
| 25 |
# --- OpenAI Client Setup ---
|
| 26 |
llm = ChatOpenAI(openai_api_key=OPENAI_API_KEY, model="gpt-4o-mini")
|
| 27 |
|
| 28 |
+
# Lightweight LLM for simple extraction tasks (persona, classification, etc.)
|
| 29 |
+
llm_light = ChatOpenAI(
|
| 30 |
+
openai_api_key=OPENAI_API_KEY,
|
| 31 |
+
model="gpt-4.1-nano",
|
| 32 |
+
temperature=0.1, # Lower temperature for more consistent extraction
|
| 33 |
+
max_tokens=200 # Lower token limit for simple tasks
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
# Initialize LLM only if API key is available
|
| 37 |
if not OPENAI_API_KEY:
|
| 38 |
print("Warning: OPENAI_API_KEY not set. AI functionality will be limited.")
|