Spaces:
Sleeping
Sleeping
version bump
Browse files- agent.py +9 -9
- requirements.txt +1 -1
- st_app.py +2 -2
agent.py
CHANGED
|
@@ -8,15 +8,16 @@ load_dotenv(override=True)
|
|
| 8 |
|
| 9 |
from pydantic import Field, BaseModel
|
| 10 |
from vectara_agentic.agent import Agent
|
|
|
|
| 11 |
from vectara_agentic.tools import ToolsFactory, VectaraToolFactory
|
| 12 |
-
from vectara_agentic.tools_catalog import
|
| 13 |
|
| 14 |
teaching_styles = ['Inquiry-based', 'Socratic', 'traditional']
|
| 15 |
languages = {'English': 'en', 'Spanish': 'es', 'French': 'fr', 'German': 'de', 'Arabic': 'ar', 'Chinese': 'zh-cn',
|
| 16 |
'Hebrew': 'he', 'Hindi': 'hi', 'Italian': 'it', 'Japanese': 'ja', 'Korean': 'ko', 'Portuguese': 'pt'}
|
| 17 |
initial_prompt = "How can I help you today?"
|
| 18 |
|
| 19 |
-
def create_assistant_tools(cfg):
|
| 20 |
|
| 21 |
def adjust_response_to_student(
|
| 22 |
text: str = Field(description='the text to adjust. may include citations in markdown format.'),
|
|
@@ -41,15 +42,14 @@ def create_assistant_tools(cfg):
|
|
| 41 |
.replace("{language}", cfg.language) \
|
| 42 |
.replace("{student_age}", str(cfg.student_age))
|
| 43 |
|
|
|
|
| 44 |
return rephrase_text(text, instructions)
|
| 45 |
|
| 46 |
|
| 47 |
class JusticeHarvardArgs(BaseModel):
|
| 48 |
query: str = Field(..., description="The user query.")
|
| 49 |
|
| 50 |
-
vec_factory = VectaraToolFactory(vectara_api_key=cfg.api_key,
|
| 51 |
-
vectara_customer_id=cfg.customer_id,
|
| 52 |
-
vectara_corpus_id=cfg.corpus_id)
|
| 53 |
summarizer = 'vectara-summary-ext-24-05-med-omni'
|
| 54 |
query_tool = vec_factory.create_rag_tool(
|
| 55 |
tool_name = "ask_about_justice_harvard",
|
|
@@ -91,9 +91,10 @@ def initialize_agent(_cfg, agent_progress_callback=None):
|
|
| 91 |
- Response in a concise and clear manner, and provide the most relevant information to the student.
|
| 92 |
- Never discuss politics, and always respond politely.
|
| 93 |
"""
|
| 94 |
-
|
| 95 |
agent = Agent(
|
| 96 |
-
|
|
|
|
| 97 |
topic="justice, morality, politics, and philosophy",
|
| 98 |
custom_instructions=bot_instructions,
|
| 99 |
agent_progress_callback=agent_progress_callback
|
|
@@ -103,8 +104,7 @@ def initialize_agent(_cfg, agent_progress_callback=None):
|
|
| 103 |
|
| 104 |
def get_agent_config() -> OmegaConf:
|
| 105 |
cfg = OmegaConf.create({
|
| 106 |
-
'
|
| 107 |
-
'corpus_id': str(os.environ['VECTARA_CORPUS_ID']),
|
| 108 |
'api_key': str(os.environ['VECTARA_API_KEY']),
|
| 109 |
'examples': os.environ.get('QUERY_EXAMPLES', None),
|
| 110 |
'demo_name': "Justice-Harvard",
|
|
|
|
| 8 |
|
| 9 |
from pydantic import Field, BaseModel
|
| 10 |
from vectara_agentic.agent import Agent
|
| 11 |
+
from vectara_agentic.agent_config import AgentConfig
|
| 12 |
from vectara_agentic.tools import ToolsFactory, VectaraToolFactory
|
| 13 |
+
from vectara_agentic.tools_catalog import ToolsCatalog
|
| 14 |
|
| 15 |
teaching_styles = ['Inquiry-based', 'Socratic', 'traditional']
|
| 16 |
languages = {'English': 'en', 'Spanish': 'es', 'French': 'fr', 'German': 'de', 'Arabic': 'ar', 'Chinese': 'zh-cn',
|
| 17 |
'Hebrew': 'he', 'Hindi': 'hi', 'Italian': 'it', 'Japanese': 'ja', 'Korean': 'ko', 'Portuguese': 'pt'}
|
| 18 |
initial_prompt = "How can I help you today?"
|
| 19 |
|
| 20 |
+
def create_assistant_tools(cfg, agent_config):
|
| 21 |
|
| 22 |
def adjust_response_to_student(
|
| 23 |
text: str = Field(description='the text to adjust. may include citations in markdown format.'),
|
|
|
|
| 42 |
.replace("{language}", cfg.language) \
|
| 43 |
.replace("{student_age}", str(cfg.student_age))
|
| 44 |
|
| 45 |
+
rephrase_text = ToolsCatalog(agent_config).rephrase_text
|
| 46 |
return rephrase_text(text, instructions)
|
| 47 |
|
| 48 |
|
| 49 |
class JusticeHarvardArgs(BaseModel):
|
| 50 |
query: str = Field(..., description="The user query.")
|
| 51 |
|
| 52 |
+
vec_factory = VectaraToolFactory(vectara_api_key=cfg.api_key,vectara_corpus_key=cfg.corpus_key)
|
|
|
|
|
|
|
| 53 |
summarizer = 'vectara-summary-ext-24-05-med-omni'
|
| 54 |
query_tool = vec_factory.create_rag_tool(
|
| 55 |
tool_name = "ask_about_justice_harvard",
|
|
|
|
| 91 |
- Response in a concise and clear manner, and provide the most relevant information to the student.
|
| 92 |
- Never discuss politics, and always respond politely.
|
| 93 |
"""
|
| 94 |
+
agent_config = AgentConfig()
|
| 95 |
agent = Agent(
|
| 96 |
+
agent_config=agent_config,
|
| 97 |
+
tools=create_assistant_tools(_cfg, agent_config=agent_config),
|
| 98 |
topic="justice, morality, politics, and philosophy",
|
| 99 |
custom_instructions=bot_instructions,
|
| 100 |
agent_progress_callback=agent_progress_callback
|
|
|
|
| 104 |
|
| 105 |
def get_agent_config() -> OmegaConf:
|
| 106 |
cfg = OmegaConf.create({
|
| 107 |
+
'corpus_key': str(os.environ['VECTARA_CORPUS_KEY']),
|
|
|
|
| 108 |
'api_key': str(os.environ['VECTARA_API_KEY']),
|
| 109 |
'examples': os.environ.get('QUERY_EXAMPLES', None),
|
| 110 |
'demo_name': "Justice-Harvard",
|
requirements.txt
CHANGED
|
@@ -6,4 +6,4 @@ streamlit_feedback==0.1.3
|
|
| 6 |
uuid==1.30
|
| 7 |
langdetect==1.0.9
|
| 8 |
langcodes==3.4.0
|
| 9 |
-
vectara-agentic==0.
|
|
|
|
| 6 |
uuid==1.30
|
| 7 |
langdetect==1.0.9
|
| 8 |
langcodes==3.4.0
|
| 9 |
+
vectara-agentic==0.2.0
|
st_app.py
CHANGED
|
@@ -154,8 +154,8 @@ async def launch_bot():
|
|
| 154 |
if st.session_state.prompt:
|
| 155 |
with st.chat_message("assistant", avatar='🤖'):
|
| 156 |
st.session_state.status = st.status('Processing...', expanded=False)
|
| 157 |
-
|
| 158 |
-
res = escape_dollars_outside_latex(
|
| 159 |
message = {"role": "assistant", "content": res, "avatar": '🤖'}
|
| 160 |
st.session_state.messages.append(message)
|
| 161 |
st.markdown(res)
|
|
|
|
| 154 |
if st.session_state.prompt:
|
| 155 |
with st.chat_message("assistant", avatar='🤖'):
|
| 156 |
st.session_state.status = st.status('Processing...', expanded=False)
|
| 157 |
+
response = st.session_state.agent.chat(st.session_state.prompt)
|
| 158 |
+
res = escape_dollars_outside_latex(response.response)
|
| 159 |
message = {"role": "assistant", "content": res, "avatar": '🤖'}
|
| 160 |
st.session_state.messages.append(message)
|
| 161 |
st.markdown(res)
|