NGUYEN, Xuan Phi commited on
Commit
98804a5
1 Parent(s): 3d92189
multipurpose_chatbot/demos/__init__.py CHANGED
@@ -7,4 +7,5 @@ from .multimodal_chat_interface import *
7
  from .text_completion import *
8
  from .batch_inference import *
9
  from .multimodal_preference_interface import *
10
- from .mm_chat_interface import *
 
 
7
  from .text_completion import *
8
  from .batch_inference import *
9
  from .multimodal_preference_interface import *
10
+ from .mm_chat_interface import *
11
+ from .websearch_chat_interface import *
multipurpose_chatbot/demos/langchain_web_search.py CHANGED
@@ -453,16 +453,19 @@ Let's begin! Below is the question from the user.
453
 
454
 
455
 
456
- def create_web_search_engine():
457
- from ..globals import MODEL_ENGINE
458
  # from langchain_community.tools.tavily_search import TavilySearchResults
 
 
 
 
459
  from langchain_core.utils.function_calling import (
460
  convert_to_openai_function,
461
  convert_to_openai_tool,
462
  )
463
  from langchain_core.exceptions import OutputParserException
464
  from langchain_core.agents import AgentAction, AgentFinish
465
- web_search_llm = AnyEnginePipeline.from_engine(MODEL_ENGINE)
466
  web_search_chat_model = ChatAnyEnginePipeline(llm=web_search_llm)
467
  if "TAVILY_API_KEY" not in os.environ:
468
  raise ValueError(f'TAVILY_API_KEY is not found to use websearch, please `export TAVILY_API_KEY=YOUR_TAVILY_API_KEY`')
 
453
 
454
 
455
 
456
+ def create_web_search_engine(model_engine=None):
 
457
  # from langchain_community.tools.tavily_search import TavilySearchResults
458
+ if model_engine is None:
459
+ from ..globals import MODEL_ENGINE
460
+ model_engine = MODEL_ENGINE
461
+
462
  from langchain_core.utils.function_calling import (
463
  convert_to_openai_function,
464
  convert_to_openai_tool,
465
  )
466
  from langchain_core.exceptions import OutputParserException
467
  from langchain_core.agents import AgentAction, AgentFinish
468
+ web_search_llm = AnyEnginePipeline.from_engine(model_engine)
469
  web_search_chat_model = ChatAnyEnginePipeline(llm=web_search_llm)
470
  if "TAVILY_API_KEY" not in os.environ:
471
  raise ValueError(f'TAVILY_API_KEY is not found to use websearch, please `export TAVILY_API_KEY=YOUR_TAVILY_API_KEY`')
multipurpose_chatbot/demos/websearch_chat_interface.py CHANGED
@@ -104,7 +104,9 @@ def chat_web_search_response_stream_multiturn_engine(
104
  system_prompt: Optional[str] = SYSTEM_PROMPT,
105
  ):
106
  # global web_search_engine, web_search_llm, web_search_chat_model, web_search_agent, MODEL_ENGINE
107
- global web_search_llm, web_search_chat_model, agent_executor, MODEL_ENGINE
 
 
108
  temperature = float(temperature)
109
  # ! remove frequency_penalty
110
  # frequency_penalty = float(frequency_penalty)
@@ -166,7 +168,7 @@ class WebSearchChatInterfaceDemo(BaseDemo):
166
  description: str | None = None,
167
  **kwargs
168
  ) -> gr.Blocks:
169
- global web_search_llm, web_search_chat_model, agent_executor
170
  system_prompt = kwargs.get("system_prompt", SYSTEM_PROMPT)
171
  max_tokens = kwargs.get("max_tokens", MAX_TOKENS)
172
  temperature = kwargs.get("temperature", TEMPERATURE)
@@ -176,7 +178,7 @@ class WebSearchChatInterfaceDemo(BaseDemo):
176
  # create_web_search_engine()
177
  description = description or "At the moment, Web search is only **SINGLE TURN**, only works well in **English** and may respond unnaturally!"
178
 
179
- web_search_llm, web_search_chat_model, agent_executor = create_web_search_engine()
180
 
181
  demo_chat = CustomizedChatInterface(
182
  chat_web_search_response_stream_multiturn_engine,
 
104
  system_prompt: Optional[str] = SYSTEM_PROMPT,
105
  ):
106
  # global web_search_engine, web_search_llm, web_search_chat_model, web_search_agent, MODEL_ENGINE
107
+ # global web_search_llm, web_search_chat_model, agent_executor, MODEL_ENGINE
108
+ global MODEL_ENGINE
109
+ web_search_llm, web_search_chat_model, agent_executor = create_web_search_engine(model_engine=MODEL_ENGINE)
110
  temperature = float(temperature)
111
  # ! remove frequency_penalty
112
  # frequency_penalty = float(frequency_penalty)
 
168
  description: str | None = None,
169
  **kwargs
170
  ) -> gr.Blocks:
171
+ # global web_search_llm, web_search_chat_model, agent_executor
172
  system_prompt = kwargs.get("system_prompt", SYSTEM_PROMPT)
173
  max_tokens = kwargs.get("max_tokens", MAX_TOKENS)
174
  temperature = kwargs.get("temperature", TEMPERATURE)
 
178
  # create_web_search_engine()
179
  description = description or "At the moment, Web search is only **SINGLE TURN**, only works well in **English** and may respond unnaturally!"
180
 
181
+ # web_search_llm, web_search_chat_model, agent_executor = create_web_search_engine()
182
 
183
  demo_chat = CustomizedChatInterface(
184
  chat_web_search_response_stream_multiturn_engine,