Joshua Sundance Bailey commited on
Commit
bd1f3d1
·
1 Parent(s): 15442b7
Files changed (1) hide show
  1. langchain-streamlit-demo/app.py +17 -18
langchain-streamlit-demo/app.py CHANGED
@@ -1,4 +1,3 @@
1
- from langchain.agents import load_tools
2
  from datetime import datetime
3
  from typing import Tuple, List, Dict, Any, Union, Optional
4
 
@@ -6,8 +5,11 @@ import anthropic
6
  import langsmith.utils
7
  import openai
8
  import streamlit as st
 
 
9
  from langchain.callbacks import StreamlitCallbackHandler
10
  from langchain.callbacks.base import BaseCallbackHandler
 
11
  from langchain.callbacks.tracers.langchain import LangChainTracer, wait_for_all_tracers
12
  from langchain.callbacks.tracers.run_collector import RunCollectorCallbackHandler
13
  from langchain.memory import ConversationBufferMemory, StreamlitChatMessageHistory
@@ -27,9 +29,8 @@ from llm_resources import (
27
  get_runnable,
28
  get_texts_and_multiretriever,
29
  )
30
- from research_assistant.chain import get_chain as get_research_assistant_chain
31
  from python_coder import get_agent as get_python_agent
32
-
33
 
34
  __version__ = "2.1.4"
35
 
@@ -461,14 +462,11 @@ if st.session_state.llm:
461
  st_callback = StreamlitCallbackHandler(st.container())
462
  callbacks.append(st_callback)
463
 
464
- from langchain.agents.tools import tool
465
- from langchain.callbacks.manager import Callbacks
466
-
467
  @tool("web-research-assistant")
468
  def research_assistant_tool(question: str, callbacks: Callbacks = None):
469
- """this assistant returns a comprehensive report based on web research.
470
- it's slow and relatively expensive, so use it sparingly.
471
- for quick facts, use duckduckgo instead.
472
  """
473
  return research_assistant_chain.invoke(
474
  dict(question=question),
@@ -479,7 +477,10 @@ if st.session_state.llm:
479
 
480
  @tool("python-coder-assistant")
481
  def python_coder_tool(input_str: str, callbacks: Callbacks = None):
482
- """this assistant writes Python code. give it clear instructions and requirements."""
 
 
 
483
  return python_coder_agent.invoke(
484
  dict(input=input_str),
485
  config=get_config(callbacks),
@@ -500,7 +501,7 @@ if st.session_state.llm:
500
 
501
  @tool("user-document-chat")
502
  def doc_chain_tool(input_str: str, callbacks: Callbacks = None):
503
- """this assistant returns a response based on the user's custom context."""
504
  return st.session_state.doc_chain.invoke(
505
  input_str,
506
  config=get_config(callbacks),
@@ -512,19 +513,17 @@ if st.session_state.llm:
512
 
513
  @tool("document-question-tool")
514
  def doc_question_tool(input_str: str, callbacks: Callbacks = None):
515
- """
516
- this assistant answers a question based on the user's custom context.
517
- this assistant responds to fully formed questions.
518
- Do not send anything besides a question. It already has context.
519
- if the user's meaning is unclear, perhaps the answer is here.
520
- generally speaking, try this tool before conducting web research.
521
  """
522
  return doc_chain_agent.invoke(
523
  input_str,
524
  config=get_config(callbacks),
525
  )
526
 
527
- TOOLS = [doc_question_tool, research_assistant_tool] + default_tools
528
 
529
  st.session_state.chain = get_agent(
530
  TOOLS,
 
 
1
  from datetime import datetime
2
  from typing import Tuple, List, Dict, Any, Union, Optional
3
 
 
5
  import langsmith.utils
6
  import openai
7
  import streamlit as st
8
+ from langchain.agents import load_tools
9
+ from langchain.agents.tools import tool
10
  from langchain.callbacks import StreamlitCallbackHandler
11
  from langchain.callbacks.base import BaseCallbackHandler
12
+ from langchain.callbacks.manager import Callbacks
13
  from langchain.callbacks.tracers.langchain import LangChainTracer, wait_for_all_tracers
14
  from langchain.callbacks.tracers.run_collector import RunCollectorCallbackHandler
15
  from langchain.memory import ConversationBufferMemory, StreamlitChatMessageHistory
 
29
  get_runnable,
30
  get_texts_and_multiretriever,
31
  )
 
32
  from python_coder import get_agent as get_python_agent
33
+ from research_assistant.chain import get_chain as get_research_assistant_chain
34
 
35
  __version__ = "2.1.4"
36
 
 
462
  st_callback = StreamlitCallbackHandler(st.container())
463
  callbacks.append(st_callback)
464
 
 
 
 
465
  @tool("web-research-assistant")
466
  def research_assistant_tool(question: str, callbacks: Callbacks = None):
467
+ """This assistant returns a comprehensive report based on web research.
468
+ It's slow and relatively expensive, so use it sparingly.
469
+ Consider using a different tool for quick facts or web queries.
470
  """
471
  return research_assistant_chain.invoke(
472
  dict(question=question),
 
477
 
478
  @tool("python-coder-assistant")
479
  def python_coder_tool(input_str: str, callbacks: Callbacks = None):
480
+ """This assistant writes PYTHON code.
481
+ Give it clear instructions and requirements.
482
+ Do not use it for tasks other than Python.
483
+ """
484
  return python_coder_agent.invoke(
485
  dict(input=input_str),
486
  config=get_config(callbacks),
 
501
 
502
  @tool("user-document-chat")
503
  def doc_chain_tool(input_str: str, callbacks: Callbacks = None):
504
+ """Always use this tool at least once. Input should be a question."""
505
  return st.session_state.doc_chain.invoke(
506
  input_str,
507
  config=get_config(callbacks),
 
513
 
514
  @tool("document-question-tool")
515
  def doc_question_tool(input_str: str, callbacks: Callbacks = None):
516
+ """This tool is an AI assistant with access to the user's uploaded document.
517
+ Input should be one or more questions, requests, instructions, etc.
518
+ If the user's meaning is unclear, perhaps the answer is here.
519
+ Generally speaking, try this tool before conducting web research.
 
 
520
  """
521
  return doc_chain_agent.invoke(
522
  input_str,
523
  config=get_config(callbacks),
524
  )
525
 
526
+ TOOLS = [doc_question_tool] + TOOLS
527
 
528
  st.session_state.chain = get_agent(
529
  TOOLS,