Spaces:
Sleeping
Sleeping
Commit ·
5bb9f76
1
Parent(s): 77bc720
perf: keywords nodes do not use Pydantic structured output
Browse files
app.py
CHANGED
|
@@ -86,16 +86,18 @@ def classify_individual_topic(topic_name: str):
|
|
| 86 |
def node_runner(state: MultiTopicState):
|
| 87 |
llm = ChatOpenAI(model="gpt-4o", temperature=0)
|
| 88 |
# Force strict structured output format
|
| 89 |
-
structured_llm = llm.with_structured_output(KeywordExtraction)
|
| 90 |
target_sub_tree = SUB_TREE_LOOKUP.get(topic_name, "")
|
| 91 |
|
| 92 |
prompt = ChatPromptTemplate.from_messages([
|
| 93 |
-
("system", f"You are a specialist in {topic_name} data mapping. Extract all exact matching keyword pathways present in the provided valid path list. Do not modify or truncate the pathway strings."),
|
|
|
|
| 94 |
("user", "Title: {title}\nAbstract: {abstract}\n\nValid Paths:\n{sub_tree}\n\nExtract matching pathways as a structured array list.")
|
| 95 |
])
|
| 96 |
|
| 97 |
# Enforce JSON list output natively
|
| 98 |
-
result = structured_llm.invoke(prompt.format(title=state["title"], abstract=state["abstract"], sub_tree=target_sub_tree))
|
|
|
|
| 99 |
raw_keywords = [k.strip() for k in result.keywords if k.strip()]
|
| 100 |
|
| 101 |
# Immediate validation pass inside the node branch
|
|
|
|
| 86 |
def node_runner(state: MultiTopicState):
|
| 87 |
llm = ChatOpenAI(model="gpt-4o", temperature=0)
|
| 88 |
# Force strict structured output format
|
| 89 |
+
#structured_llm = llm.with_structured_output(KeywordExtraction)
|
| 90 |
target_sub_tree = SUB_TREE_LOOKUP.get(topic_name, "")
|
| 91 |
|
| 92 |
prompt = ChatPromptTemplate.from_messages([
|
| 93 |
+
#("system", f"You are a specialist in {topic_name} data mapping. Extract all exact matching keyword pathways present in the provided valid path list. Do not modify or truncate the pathway strings."),
|
| 94 |
+
("system", f"You are a specialist in {topic_name} data mapping. Extract exact keyword pathways present in the provided list."),
|
| 95 |
("user", "Title: {title}\nAbstract: {abstract}\n\nValid Paths:\n{sub_tree}\n\nExtract matching pathways as a structured array list.")
|
| 96 |
])
|
| 97 |
|
| 98 |
# Enforce JSON list output natively
|
| 99 |
+
#result = structured_llm.invoke(prompt.format(title=state["title"], abstract=state["abstract"], sub_tree=target_sub_tree))
|
| 100 |
+
result = llm.invoke(prompt.format(title=state["title"], abstract=state["abstract"], sub_tree=target_sub_tree))
|
| 101 |
raw_keywords = [k.strip() for k in result.keywords if k.strip()]
|
| 102 |
|
| 103 |
# Immediate validation pass inside the node branch
|