Spaces:
Build error
Build error
Create nodes/title_generator.py
Browse files- nodes/title_generator.py +36 -0
nodes/title_generator.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Dict, Any
|
| 2 |
+
from langchain_core.prompts import ChatPromptTemplate
|
| 3 |
+
from langsmith.run_helpers import traceable
|
| 4 |
+
|
| 5 |
+
patent_title_prompt = ChatPromptTemplate.from_messages([
|
| 6 |
+
("system", """
|
| 7 |
+
You are a patent attorney drafting formal, concise patent titles.
|
| 8 |
+
|
| 9 |
+
Guidelines:
|
| 10 |
+
- Focus on the key technical aspect of the invention.
|
| 11 |
+
- Use terms like "System", "Method", "Apparatus", etc.
|
| 12 |
+
- Do NOT use marketing terms (e.g., "novel", "innovative", "unraveling", "unveiling").
|
| 13 |
+
- Max 15 words.
|
| 14 |
+
"""),
|
| 15 |
+
("user", """
|
| 16 |
+
Generate a formal patent title for the following invention:
|
| 17 |
+
|
| 18 |
+
Invention Topic:
|
| 19 |
+
{topic}
|
| 20 |
+
|
| 21 |
+
Research Summary:
|
| 22 |
+
{research_results}
|
| 23 |
+
""")
|
| 24 |
+
])
|
| 25 |
+
|
| 26 |
+
@traceable(name="patent_title_node")
|
| 27 |
+
def generate_patent_title(state: Dict[str, Any], llm) -> Dict[str, Any]:
|
| 28 |
+
title_chain = patent_title_prompt | llm
|
| 29 |
+
|
| 30 |
+
title = title_chain.invoke({
|
| 31 |
+
"topic": state["topic"],
|
| 32 |
+
"research_results": state["research_results"]
|
| 33 |
+
})
|
| 34 |
+
|
| 35 |
+
state["title"] = title
|
| 36 |
+
return state
|