hra commited on
Commit
54d8e93
1 Parent(s): c548d52

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -13
app.py CHANGED
@@ -38,8 +38,10 @@ def get_learning_curriculum(openapikey,topic):
38
 
39
  os.environ['OPENAI_API_KEY'] = str(openapikey)
40
 
41
- prompt='You are a training center AI. Give me a detailed curriculum to learn about "{topicforquery}" using search. The curriculum will be a series of learning tasks to be achieved. Give output as a python list of jsons with "task name", "search keyword" to search to complete the task. Donot repeat the taks. For each task name also add a list of "questions" to ask the search results data to select specific articles and complete the curriculum. Remember the search list will be a dataframe of titles & body of the searched article and you may not be able to go through the full article hence these questions should be of types "Which article best suits a learning curriculum?", "Which article is learning oriented?. To reiterate output should be in json with keys task name ex: get beginner training articles for painting, search keyword ex: beginner painting & questions ex: What are top articles for painting?'.format(topicforquery=topic)
42
 
 
 
 
43
  openai.api_key = os.getenv("OPENAI_API_KEY")
44
  resp=openai.ChatCompletion.create(
45
  model="gpt-3.5-turbo",
@@ -51,6 +53,7 @@ def get_learning_curriculum(openapikey,topic):
51
 
52
  llm = ChatOpenAI(temperature=0)
53
 
 
54
  def research_search(search_keyword,question_to_ask,topic):
55
  llm_predictor = LLMPredictor(llm=OpenAIChat(temperature=0, model_name="gpt-3.5-turbo"))
56
  service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor)
@@ -73,25 +76,20 @@ def get_learning_curriculum(openapikey,topic):
73
  print("Search response: ",respstr)
74
  return respstr
75
 
76
- finallist=[]
77
  list1=[]
78
  list2=[]
79
  list3=[]
80
  for i in range(len(tasklist)):
81
  taskstuff=tasklist[i]
82
  search_keyword=taskstuff['search keyword']
83
- print('Task Name: '+taskstuff['task name'])
84
- finallist.append('Task Name: '+taskstuff['task name'])
85
-
86
  for question in taskstuff['questions']:
87
- response_string=research_search(search_keyword,question,topic)
88
- finallist.append(" Question: "+question)
89
- finallist.append(" "+response_string)
90
-
91
  list1.append(taskstuff['task name'])
92
  list2.append(question)
93
  list3.append(response_string)
94
-
 
95
  outputdf=pd.DataFrame()
96
  outputdf['Task']=list1
97
  outputdf['Question']=list2
@@ -102,7 +100,7 @@ def get_learning_curriculum(openapikey,topic):
102
  with gr.Blocks() as demo:
103
  gr.Markdown("<h1><center>BabyAGI creates Learning Curriculum</center></h1>")
104
  gr.Markdown(
105
- """What are the sectors with positive momentum? What are the macro trends? Which companies have momentum? Sector summaries and much more. \n\nThis is a demo & showcases ChatGPT integrated with real data. It shows how to get real-time data and marry it with ChatGPT capabilities. This demonstrates 'Chain of Thought' thinking using ChatGPT.\n\n4 snapshots are provided for illustration (trends, sector outlook, news summary email, macro trends email)\n\nNote: llama-index & gpt-3.5-turbo are used. The analysis takes roughly 120 secs & may not always be consistent. If ChatGPT API is overloaded you will get an error\n ![visitors](https://visitor-badge.glitch.me/badge?page_id=hra.chatgpt-stock-news-snapshots)"""
106
  )
107
 
108
  with gr.Row() as row:
@@ -121,8 +119,6 @@ with gr.Blocks() as demo:
121
  label="Learning Curriculum",
122
  )
123
 
124
-
125
  btn.click(get_learning_curriculum, inputs=[textboxopenapi,textboxtopic],outputs=[table1])
126
 
127
-
128
  demo.launch(debug=True)
 
38
 
39
  os.environ['OPENAI_API_KEY'] = str(openapikey)
40
 
 
41
 
42
+ ###Task Creation Agent
43
+
44
+ prompt='You are a training center AI. Give me a detailed curriculum to learn about "{topicforquery}" using search. The curriculum will be a series of learning tasks to be achieved. Give output as a python list of jsons with "task name", "search keyword" to search to complete the task. Donot repeat the taks. For each task name also add a list of "questions" to ask the search results data to select specific articles and complete the curriculum. Remember the search list will be a dataframe of titles & body of the searched article and you may not be able to go through the full article hence these questions should be of types "Which article best suits a learning curriculum?", "Which article is learning oriented?. To reiterate output should be in json with keys task name ex: get beginner training articles for painting, search keyword ex: beginner painting & questions ex: What are top articles for painting?'.format(topicforquery=topic)
45
  openai.api_key = os.getenv("OPENAI_API_KEY")
46
  resp=openai.ChatCompletion.create(
47
  model="gpt-3.5-turbo",
 
53
 
54
  llm = ChatOpenAI(temperature=0)
55
 
56
+ ###Function to search the internet using Duck-Duck-Go exposed as a tool
57
  def research_search(search_keyword,question_to_ask,topic):
58
  llm_predictor = LLMPredictor(llm=OpenAIChat(temperature=0, model_name="gpt-3.5-turbo"))
59
  service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor)
 
76
  print("Search response: ",respstr)
77
  return respstr
78
 
79
+ ###Task Execution Agent loop
80
  list1=[]
81
  list2=[]
82
  list3=[]
83
  for i in range(len(tasklist)):
84
  taskstuff=tasklist[i]
85
  search_keyword=taskstuff['search keyword']
 
 
 
86
  for question in taskstuff['questions']:
87
+ response_string=research_search(search_keyword,question,topic)
 
 
 
88
  list1.append(taskstuff['task name'])
89
  list2.append(question)
90
  list3.append(response_string)
91
+
92
+ ###Create dataframe to display
93
  outputdf=pd.DataFrame()
94
  outputdf['Task']=list1
95
  outputdf['Question']=list2
 
100
  with gr.Blocks() as demo:
101
  gr.Markdown("<h1><center>BabyAGI creates Learning Curriculum</center></h1>")
102
  gr.Markdown(
103
+ """ This is the first step of an experiment using BabyAGI as a "framework" to construct focused use cases (ex: learning curriculums). The flow uses two AI agents 1) Task creation agent: to create a task list & questions 2) Task execution agent: to execute the tasks & find answers to the questions. Unlike original BabyAGI concept, this is not open-ended. \n\nNote: LangChain agents, llama-index & gpt-3.5-turbo are used. The analysis takes roughly 120 secs & may not always be consistent. An error occurs when the OpenAI Api key is not provided/ ChatGPT API is overloaded/ChatGPT is unable to correctly decipher & format the output\n\n Future directions: 1) Make the task creation more open ended or longer. 2) Discover multiple learning paths and make ChatGPT introspect on it before finalizing the optimal one 3)Learn from the answers and change the curriculum![visitors](https://visitor-badge.glitch.me/badge?page_id=hra/Curriculum-BabyAGI)"""
104
  )
105
 
106
  with gr.Row() as row:
 
119
  label="Learning Curriculum",
120
  )
121
 
 
122
  btn.click(get_learning_curriculum, inputs=[textboxopenapi,textboxtopic],outputs=[table1])
123
 
 
124
  demo.launch(debug=True)