ishaq101 commited on
Commit
74d7562
·
1 Parent(s): 06c7961

update fast intent

Browse files
src/agents/orchestration.py CHANGED
@@ -46,16 +46,22 @@ class OrchestratorAgent:
46
  ("system", """You are an orchestrator agent. You receive recent conversation history and the user's latest message.
47
 
48
  Your task:
49
- 1. Determine intent: question, greeting, goodbye, or other
50
  2. Decide whether to search the user's documents (needs_search)
51
  3. If search is needed, rewrite the user's message into a STANDALONE search query that incorporates necessary context from conversation history. If the user says "tell me more" or "how many papers?", the search_query must spell out the full topic explicitly from history.
52
  4. If no search needed, provide a short direct_response (plain text only, no markdown formatting).
53
 
54
  Intent Routing:
55
- - question -> needs_search=True, search_query=<standalone rewritten query>
56
- - greeting -> needs_search=False, direct_response="Hello! How can I assist you today?"
57
- - goodbye -> needs_search=False, direct_response="Goodbye! Have a great day!"
58
- - other -> needs_search=True, search_query=<standalone rewritten query>
 
 
 
 
 
 
59
  """),
60
  MessagesPlaceholder(variable_name="history"),
61
  ("user", "{message}")
 
46
  ("system", """You are an orchestrator agent. You receive recent conversation history and the user's latest message.
47
 
48
  Your task:
49
+ 1. Determine intent: question, greeting, thanks, goodbye, or other
50
  2. Decide whether to search the user's documents (needs_search)
51
  3. If search is needed, rewrite the user's message into a STANDALONE search query that incorporates necessary context from conversation history. If the user says "tell me more" or "how many papers?", the search_query must spell out the full topic explicitly from history.
52
  4. If no search needed, provide a short direct_response (plain text only, no markdown formatting).
53
 
54
  Intent Routing:
55
+ - greeting -> ONLY if the message is a pure greeting with no question (e.g. "halo", "hi", "selamat pagi")
56
+ -> needs_search=False, direct_response="Halo! Ada yang bisa saya bantu?"
57
+ - thanks -> if the message is an expression of gratitude (e.g. "terima kasih", "makasih", "thanks", "thank you")
58
+ -> needs_search=False, direct_response="Sama-sama! Ada yang bisa saya bantu lagi?"
59
+ - goodbye -> if the message is a farewell (e.g. "bye", "sampai jumpa", "dadah")
60
+ -> needs_search=False, direct_response="Sampai jumpa! Semoga harimu menyenangkan."
61
+ - question -> if the message contains a question or request for information, EVEN IF it starts with a greeting
62
+ -> needs_search=True, search_query=<standalone rewritten query>
63
+ -> EXAMPLE: "halo, bisa bantu jelaskan data X?" → intent=question
64
+ - other -> needs_search=True, search_query=<standalone rewritten query>
65
  """),
66
  MessagesPlaceholder(variable_name="history"),
67
  ("user", "{message}")
src/api/v1/chat.py CHANGED
@@ -20,18 +20,22 @@ from typing import List, Dict, Any, Optional
20
  import json
21
 
22
  _GREETINGS = frozenset(["hi", "hello", "hey", "halo", "hai", "hei"])
23
- _GOODBYES = frozenset(["bye", "goodbye", "thanks", "thank you", "terima kasih", "sampai jumpa"])
 
24
 
25
 
26
  def _fast_intent(message: str) -> Optional[dict]:
27
- """Bypass LLM orchestrator for obvious greetings and farewells."""
28
  lower = message.lower().strip().rstrip("!.,?")
29
  if lower in _GREETINGS:
30
  return {"intent": "greeting", "needs_search": False,
31
- "direct_response": "Hello! How can I assist you today?", "search_query": ""}
 
 
 
32
  if lower in _GOODBYES:
33
  return {"intent": "goodbye", "needs_search": False,
34
- "direct_response": "Goodbye! Have a great day!", "search_query": ""}
35
  return None
36
 
37
  logger = get_logger("chat_api")
 
20
  import json
21
 
22
  _GREETINGS = frozenset(["hi", "hello", "hey", "halo", "hai", "hei"])
23
+ _THANKS = frozenset(["thanks", "thank you", "terima kasih", "makasih", "thx"])
24
+ _GOODBYES = frozenset(["bye", "goodbye", "sampai jumpa", "dadah", "see you"])
25
 
26
 
27
  def _fast_intent(message: str) -> Optional[dict]:
28
+ """Bypass LLM orchestrator for obvious greetings, thanks, and farewells."""
29
  lower = message.lower().strip().rstrip("!.,?")
30
  if lower in _GREETINGS:
31
  return {"intent": "greeting", "needs_search": False,
32
+ "direct_response": "Halo! Ada yang bisa saya bantu?", "search_query": ""}
33
+ if lower in _THANKS:
34
+ return {"intent": "thanks", "needs_search": False,
35
+ "direct_response": "Sama-sama! Ada yang bisa saya bantu lagi?", "search_query": ""}
36
  if lower in _GOODBYES:
37
  return {"intent": "goodbye", "needs_search": False,
38
+ "direct_response": "Sampai jumpa! Semoga harimu menyenangkan.", "search_query": ""}
39
  return None
40
 
41
  logger = get_logger("chat_api")
src/models/structured_output.py CHANGED
@@ -6,7 +6,7 @@ from pydantic import BaseModel, Field
6
  class IntentClassification(BaseModel):
7
  """Intent classification output."""
8
  intent: str = Field(
9
- description="The user's intent: 'question', 'greeting', 'goodbye', 'other'"
10
  )
11
  needs_search: bool = Field(
12
  description="Whether document search is needed"
 
6
  class IntentClassification(BaseModel):
7
  """Intent classification output."""
8
  intent: str = Field(
9
+ description="The user's intent: 'question', 'greeting', 'thanks', 'goodbye', 'other'"
10
  )
11
  needs_search: bool = Field(
12
  description="Whether document search is needed"