ofermend commited on
Commit
ae6a3d9
1 Parent(s): 6eab5e8
Files changed (1) hide show
  1. app.py +4 -10
app.py CHANGED
@@ -8,7 +8,6 @@ from translate import Translator
8
 
9
 
10
  from llama_index.indices.managed.vectara import VectaraIndex
11
- from llama_index.indices.managed.vectara.query import VectaraQueryEngine
12
  from llama_index.core.agent import ReActAgent
13
  from llama_index.llms.openai import OpenAI
14
  from llama_index.core.tools import QueryEngineTool, ToolMetadata
@@ -24,17 +23,13 @@ def launch_bot():
24
  cfg = st.session_state.cfg
25
  llm = OpenAI(model="gpt-4o", temperature=0)
26
  tr_prompt = Translator(to_lang=languages[cfg.language]).translate(initial_prompt)
27
- print(tr_prompt)
28
  st.session_state.messages = [{"role": "assistant", "content": tr_prompt, "avatar": "🦖"}]
29
  vectara = VectaraIndex(vectara_api_key=cfg.api_key,
30
  vectara_customer_id=cfg.customer_id,
31
  vectara_corpus_id=cfg.corpus_id)
32
- vectara_retriever = vectara.as_retriever(n_sentences_before=5, n_sentences_after=10,
33
- lambda_val=0.005, similarity_top_k=10)
34
  vectara_tool = QueryEngineTool(
35
- query_engine = VectaraQueryEngine.from_args(retriever=vectara_retriever, summary_enabled=True,
36
- summary_num_results=5, summary_response_lang = languages[cfg.language],
37
- summary_prompt_name="vectara-summary-ext-24-05-large"),
38
  metadata = ToolMetadata(name="Vectara",
39
  description="Vectara Query Engine that is able to answer any questions about the Justice Harvard class."),
40
  )
@@ -42,9 +37,8 @@ def launch_bot():
42
  st.session_state.agent = ReActAgent.from_tools(
43
  tools=[vectara_tool], llm=llm,
44
  context = f'''
45
- You are a teacher assistant at Justice Harvard course. You are helping a student with his questions.
46
- The student is {cfg.student_age} years old, so make sure to adapt your response as appropriate to that age.
47
- You respond in the {cfg.style} style.
48
  ''',
49
  verbose=True
50
  )
 
8
 
9
 
10
  from llama_index.indices.managed.vectara import VectaraIndex
 
11
  from llama_index.core.agent import ReActAgent
12
  from llama_index.llms.openai import OpenAI
13
  from llama_index.core.tools import QueryEngineTool, ToolMetadata
 
23
  cfg = st.session_state.cfg
24
  llm = OpenAI(model="gpt-4o", temperature=0)
25
  tr_prompt = Translator(to_lang=languages[cfg.language]).translate(initial_prompt)
 
26
  st.session_state.messages = [{"role": "assistant", "content": tr_prompt, "avatar": "🦖"}]
27
  vectara = VectaraIndex(vectara_api_key=cfg.api_key,
28
  vectara_customer_id=cfg.customer_id,
29
  vectara_corpus_id=cfg.corpus_id)
 
 
30
  vectara_tool = QueryEngineTool(
31
+ query_engine = vectara.as_query_engine(summary_enabled=True, summary_num_results=5, summary_response_lang = languages[cfg.language],
32
+ summary_prompt_name="vectara-summary-ext-24-05-large"),
 
33
  metadata = ToolMetadata(name="Vectara",
34
  description="Vectara Query Engine that is able to answer any questions about the Justice Harvard class."),
35
  )
 
37
  st.session_state.agent = ReActAgent.from_tools(
38
  tools=[vectara_tool], llm=llm,
39
  context = f'''
40
+ You are a teacher assistant for the Justice Harvard course, helping a {cfg.student_age} years old student with his or her questions.
41
+ Evaluate the response from tools and respond in the {cfg.style} learning style.
 
42
  ''',
43
  verbose=True
44
  )