Dharma20 commited on
Commit
7e54f17
·
verified ·
1 Parent(s): 1fb047f

Update feasibility_agent.py

Browse files
Files changed (1) hide show
  1. feasibility_agent.py +120 -125
feasibility_agent.py CHANGED
@@ -1,126 +1,121 @@
1
- from setup import *
2
- from langchain_core.messages import AIMessage, HumanMessage, SystemMessage
3
- from pydantic import BaseModel,ValidationError
4
- from typing import List
5
- from langchain_community.tools import TavilySearchResults
6
-
7
-
8
- keyword_search = TavilySearchResults(
9
- max_results=3,
10
- search_depth="advanced",
11
- include_answer=True,
12
- include_raw_content=True,
13
- include_images=True,
14
- )
15
-
16
-
17
- class UseCaseKeywords(BaseModel):
18
- use_case: str
19
- description: str
20
- keyword: str
21
-
22
- def as_dict(self) -> dict:
23
- """Convert the instance to a dictionary using model_dump."""
24
- return self.model_dump()
25
-
26
- class KeywordGenerationResponse(BaseModel):
27
- data: List[UseCaseKeywords]
28
-
29
- def as_list_of_dicts(self) -> List[dict]:
30
- """Convert the list of UseCaseKeywords to a list of dictionaries."""
31
- return [item.as_dict() for item in self.data]
32
-
33
-
34
-
35
- def keyword_generation(report):
36
-
37
- query_generation_sys_prompt = SystemMessage(content='''You are an expert in creating precise and relevant keyword queries to search for datasets. Your task is to generate a keyword query for each use case provided below. These queries should be optimized for searching datasets on platforms such as GitHub, Kaggle, and Hugging Face.
38
-
39
- **Instructions:**
40
- 1. Extract the key concepts from the use case (e.g., objectives, AI application, and domain).
41
- 2. Formulate a concise, descriptive query using relevant terms and synonyms.
42
- 3. Include terms related to data types (e.g., "customer data," "chat logs," "shopping behavior"), AI techniques (e.g., "machine learning," "recommendation systems"), and target domain (e.g., "e-commerce," "retail").
43
- 4. Create a output dictionary with the use case title as the key and the keyword query as the value.
44
-
45
- **Use Cases: Examples**
46
- ## Use Case 1: Personalized Shopping Experiences with GenAI
47
- **Objective/Use Case:** Create tailored shopping experiences for individual customers based on their browsing history, purchasing behavior, and preferences.
48
- **AI Application:** Implement machine learning algorithms that analyze customer data to generate personalized offers, marketing communications, and product recommendations.
49
- **Cross-Functional Benefit:**
50
- - **Marketing:** Increases customer satisfaction and loyalty through targeted marketing efforts.
51
- - **Sales:** Boosts sales by offering relevant products to customers.
52
- - **Customer Service:** Enhances customer experience through personalized support.
53
-
54
- ## Use Case 2: AI-Powered Chatbots for Customer Service
55
- **Objective/Use Case:** Improve in-store customer service by providing instant assistance and directing customers to relevant products.
56
- **AI Application:** Develop GenAI-powered chatbots that analyze customer queries and provide accurate responses, suggesting related products and services.
57
- **Cross-Functional Benefit:**
58
- - **Customer Service:** Reduces wait times and improves customer satisfaction.
59
- - **Sales:** Increases sales by suggesting relevant products to customers.
60
- - **Operations:** Enhances employee productivity by automating routine tasks.
61
-
62
- Example output:
63
- [{'use_case' : "Personalized Shopping Experiences with GenAI" ,
64
- 'description':"AI-driven personalization enhances customer satisfaction through tailored offers, recommendations, and marketing based on individual preferences."
65
- 'keyword': "e-commerce personalized shopping data customer behavior recommendation system offers dataset"},
66
- {'use_case': "AI-Powered Chatbots for Customer Service" ,
67
- 'description': AI chatbots provide instant, accurate assistance, improving customer service, increasing sales, and boosting operational efficiency.
68
- 'keyword': "customer service chatbot dataset customer queries retail e-commerce AI automation"}]''')
69
-
70
- # # Example usage (you will use llm to generate the output)
71
- Keyword_generation_llm = llm.with_structured_output(KeywordGenerationResponse)
72
-
73
- # Your report as input (ensure that this variable is properly formatted and available)
74
- report_msg = HumanMessage(content=f'The usecases are as follows {report}')
75
-
76
- # Invoke the LLM and get the response
77
- output_dict = Keyword_generation_llm.invoke([query_generation_sys_prompt, report_msg])
78
-
79
- # Convert the response to a list of dictionaries
80
- output_list = output_dict.as_list_of_dicts()
81
-
82
- return output_list
83
-
84
-
85
-
86
- def dataset_search(output_list):
87
- for usecase_dict in output_list:
88
- query = usecase_dict['keyword']
89
- query_format = 'kaggle OR github OR huggingface AND ({query})'
90
- links = keyword_search.invoke({'query': query_format})
91
- usecase_dict['links'] = links
92
- print('dataset_search------output_list:',output_list)
93
- return output_list
94
-
95
-
96
-
97
- def grouping_urls(output_list):
98
- for dict_item in output_list:
99
- urls_list = []
100
- for ele in dict_item['links']:
101
- urls_list.append(ele['url'])
102
- dict_item['urls_list'] = urls_list
103
- print('grouping_urls------output_list:',output_list)
104
- return output_list
105
-
106
-
107
-
108
- def delete_columns(output_list):
109
- # Specify the keys you want to include
110
- keys_to_del = ['links', 'keyword']
111
-
112
- for dict_item in output_list:
113
- for key in keys_to_del:
114
- dict_item.pop(key, None)
115
- print('delete_columns------output_list:',output_list)
116
- return output_list
117
-
118
-
119
- def feasibility_agent_func(report):
120
- dict_list = keyword_generation(report)
121
- dict_links = dataset_search(dict_list)
122
- urls_dict = grouping_urls(dict_links)
123
- pd_dict = delete_columns(urls_dict)
124
-
125
- print('feasibility_agent_func------output_list:',pd_dict)
126
  return pd_dict
 
1
+ from setup import *
2
+ from langchain_core.messages import AIMessage, HumanMessage, SystemMessage
3
+ from pydantic import BaseModel,ValidationError
4
+ from typing import List
5
+ from langchain_community.tools import TavilySearchResults
6
+
7
+
8
+ keyword_search = TavilySearchResults(
9
+ max_results=3,
10
+ search_depth="advanced",
11
+ include_answer=True,
12
+ include_raw_content=True,
13
+ include_images=True,
14
+ )
15
+
16
+
17
+ class UseCaseKeywords(BaseModel):
18
+ use_case: str
19
+ description: str
20
+ keyword: str
21
+
22
+ def as_dict(self) -> dict:
23
+ """Convert the instance to a dictionary using model_dump."""
24
+ return self.model_dump()
25
+
26
+ class KeywordGenerationResponse(BaseModel):
27
+ data: List[UseCaseKeywords]
28
+
29
+ def as_list_of_dicts(self) -> List[dict]:
30
+ """Convert the list of UseCaseKeywords to a list of dictionaries."""
31
+ return [item.as_dict() for item in self.data]
32
+
33
+
34
+
35
+ def keyword_generation(report):
36
+
37
+ query_generation_sys_prompt = SystemMessage(content='''You are an expert in creating precise and relevant keyword queries to search for datasets. Your task is to generate a keyword query for each use case provided below. These queries should be optimized for searching datasets on platforms such as GitHub, Kaggle, and Hugging Face.
38
+
39
+ **Instructions:**
40
+ 1. Extract the key concepts from the use case (e.g., objectives, AI application, and domain).
41
+ 2. Formulate a concise, descriptive query using relevant terms and synonyms.
42
+ 3. Include terms related to data types (e.g., "customer data," "chat logs," "shopping behavior"), AI techniques (e.g., "machine learning," "recommendation systems"), and target domain (e.g., "e-commerce," "retail").
43
+ 4. Create a output dictionary with the use case title as the key and the keyword query as the value.
44
+
45
+ **Use Cases: Examples**
46
+ ## Use Case 1: Personalized Shopping Experiences with GenAI
47
+ **Objective/Use Case:** Create tailored shopping experiences for individual customers based on their browsing history, purchasing behavior, and preferences.
48
+ **AI Application:** Implement machine learning algorithms that analyze customer data to generate personalized offers, marketing communications, and product recommendations.
49
+ **Cross-Functional Benefit:**
50
+ - **Marketing:** Increases customer satisfaction and loyalty through targeted marketing efforts.
51
+ - **Sales:** Boosts sales by offering relevant products to customers.
52
+ - **Customer Service:** Enhances customer experience through personalized support.
53
+
54
+ ## Use Case 2: AI-Powered Chatbots for Customer Service
55
+ **Objective/Use Case:** Improve in-store customer service by providing instant assistance and directing customers to relevant products.
56
+ **AI Application:** Develop GenAI-powered chatbots that analyze customer queries and provide accurate responses, suggesting related products and services.
57
+ **Cross-Functional Benefit:**
58
+ - **Customer Service:** Reduces wait times and improves customer satisfaction.
59
+ - **Sales:** Increases sales by suggesting relevant products to customers.
60
+ - **Operations:** Enhances employee productivity by automating routine tasks.
61
+
62
+ Example output:
63
+ [{'use_case' : "Personalized Shopping Experiences with GenAI" ,
64
+ 'description':"AI-driven personalization enhances customer satisfaction through tailored offers, recommendations, and marketing based on individual preferences."
65
+ 'keyword': "e-commerce personalized shopping data customer behavior recommendation system offers dataset"},
66
+ {'use_case': "AI-Powered Chatbots for Customer Service" ,
67
+ 'description': AI chatbots provide instant, accurate assistance, improving customer service, increasing sales, and boosting operational efficiency.
68
+ 'keyword': "customer service chatbot dataset customer queries retail e-commerce AI automation"}]''')
69
+
70
+ # # Example usage (you will use llm to generate the output)
71
+ Keyword_generation_llm = llm.with_structured_output(KeywordGenerationResponse)
72
+
73
+ # Your report as input (ensure that this variable is properly formatted and available)
74
+ report_msg = HumanMessage(content=f'The usecases are as follows {report}')
75
+
76
+ # Invoke the LLM and get the response
77
+ output_dict = Keyword_generation_llm.invoke([query_generation_sys_prompt, report_msg])
78
+
79
+ # Convert the response to a list of dictionaries
80
+ output_list = output_dict.as_list_of_dicts()
81
+
82
+ return output_list
83
+
84
+
85
+
86
+ def dataset_search(output_list):
87
+ for usecase_dict in output_list:
88
+ query = usecase_dict['keyword']
89
+ query_format = 'kaggle OR github OR huggingface AND ({query})'
90
+ links = keyword_search.invoke({'query': query_format})
91
+ usecase_dict['links'] = links
92
+ return output_list
93
+
94
+
95
+
96
+ def grouping_urls(output_list):
97
+ for dict_item in output_list:
98
+ urls_list = []
99
+ for ele in dict_item['links']:
100
+ urls_list.append(ele['url'])
101
+ dict_item['urls_list'] = urls_list
102
+ return output_list
103
+
104
+
105
+
106
+ def delete_columns(output_list):
107
+ # Specify the keys you want to include
108
+ keys_to_del = ['links', 'keyword']
109
+
110
+ for dict_item in output_list:
111
+ for key in keys_to_del:
112
+ dict_item.pop(key, None)
113
+ return output_list
114
+
115
+
116
+ def feasibility_agent_func(report):
117
+ dict_list = keyword_generation(report)
118
+ dict_links = dataset_search(dict_list)
119
+ urls_dict = grouping_urls(dict_links)
120
+ pd_dict = delete_columns(urls_dict)
 
 
 
 
 
121
  return pd_dict