cloud-sean commited on
Commit
28dc1ef
·
1 Parent(s): 663ae5c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -10
app.py CHANGED
@@ -272,32 +272,55 @@ with col2:
272
  st.json(st.session_state.r)
273
 
274
 
275
-
276
-
277
 
278
  with col3:
279
  col3.subheader("Copilot Concept")
280
 
281
  question = st.text_input("Ask a question to Copilot:")
282
 
283
- toggle = st.toggle("Grounded", False)
284
 
 
 
 
285
 
286
  ask = st.button("Ask")
287
- if toggle:
288
  if ask:
289
- json_spec = JsonSpec(dict_=st.session_state.r, max_value_length=7000)
290
- json_toolkit = JsonToolkit(spec=json_spec)
 
 
291
 
292
- json_agent_executor = create_json_agent(
293
- llm=AzureChatOpenAI(temperature=0, deployment_name="gpt-4"), toolkit=json_toolkit, verbose=True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
  )
 
295
 
296
- st.write(json_agent_executor.run(question))
 
297
 
298
  elif ask:
299
  response = openai.ChatCompletion.create(
300
- engine="gpt-4",
301
  messages = [{"role":"system","content":"You are an AI assistant that helps people find information."}, {"role": "user", "content" : question}],
302
  temperature=0.7,
303
  max_tokens=800,
 
272
  st.json(st.session_state.r)
273
 
274
 
275
+
 
276
 
277
  with col3:
278
  col3.subheader("Copilot Concept")
279
 
280
  question = st.text_input("Ask a question to Copilot:")
281
 
 
282
 
283
+ grounded = st.selectbox('Would you like to ground the model?', ('Not Grounded', 'Text Analytics for Health', 'Just Text Input', 'Both'))
284
+
285
+ model = st.selectbox("Model", ["gpt-35-turbo", "gpt-4" ])
286
 
287
  ask = st.button("Ask")
288
+ if grounded != 'Not Grounded':
289
  if ask:
290
+ if grounded == 'Text Analytics for Health':
291
+ total_text = str(st.session_state.r_annotated)
292
+ else:
293
+ total_text = str(st.session_state.r) + dax_input
294
 
295
+ print(total_text)
296
+
297
+ from langchain.text_splitter import RecursiveCharacterTextSplitter
298
+
299
+ text_splitter = RecursiveCharacterTextSplitter(
300
+ # Set a really small chunk size, just to show.
301
+ chunk_size = 3000,
302
+ chunk_overlap = 20,
303
+ length_function = len,
304
+ add_start_index = True,
305
+ )
306
+ texts = text_splitter.create_documents([total_text])
307
+
308
+ from langchain.embeddings.openai import OpenAIEmbeddings
309
+ embeddings = OpenAIEmbeddings(
310
+ deployment="text-embedding-ada-002",
311
+ model="text-embedding-ada-002",
312
+ openai_api_base="https://eastus-openai-sean.openai.azure.com/",
313
+ openai_api_type="azure",
314
+ chunk_size=16,
315
  )
316
+ index = VectorstoreIndexCreator(embedding=embeddings).from_documents(texts)
317
 
318
+ st.write(index.query(question, llm=AzureChatOpenAI(temperature=0, deployment_name=model)))
319
+
320
 
321
  elif ask:
322
  response = openai.ChatCompletion.create(
323
+ engine=model,
324
  messages = [{"role":"system","content":"You are an AI assistant that helps people find information."}, {"role": "user", "content" : question}],
325
  temperature=0.7,
326
  max_tokens=800,