Timmyafolami commited on
Commit
1754a9e
1 Parent(s): bd0c0d1

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +108 -108
utils.py CHANGED
@@ -1,108 +1,108 @@
1
- import os
2
- from dotenv import load_dotenv
3
- from langchain_groq import ChatGroq
4
- from langchain_core.prompts.prompt import PromptTemplate
5
- from langchain_core.output_parsers import StrOutputParser
6
- import time
7
- load_dotenv()
8
-
9
-
10
-
11
- os.environ["GROQ_API_KEY"] = os.getenv("GROQ_API_KEY")
12
-
13
- model = ChatGroq(temperature=0.5, model_name="llama3-groq-8b-8192-tool-use-preview")
14
-
15
- Forecasted_price = 2500
16
- today = time.strftime("%d/%m/%Y")
17
- today_rate = 1650
18
- profit_margin = 50
19
- def ai_markerter(product_data: list, forecasted_value: float, date:str, today_rate:float, profit_margin:float) -> str:
20
- model = ChatGroq(temperature=0.5, model_name="llama3-groq-70b-8192-tool-use-preview")
21
- ai_markerter_prompt = PromptTemplate(
22
- template="""<|begin_of_text|><|start_header_id|>system<|end_header_id|>
23
- You are the best marketing and sales expert in the world. You are excellent at, data analysis, statistics, and forecasting, you also have a lot of experience of market strategies with even little information. \n
24
- You are hired by a client to help revolitionlize his business. His company's name is Cinuc. They are a laboratory equipment supplier. \n
25
- One issue this client has is that he lacks data. He has some data. \n
26
-
27
- In his data he has the product name, the category, the unit price, the cinuc price, the exchange rate and the date. \n Note that Cinuc Price is his selling price. \n The unit price is the price he buys the product. \n
28
-
29
- Based on his business structure, he buys in bulk. Then he gives a fixed price to his customers for at least 2 years. \n One challenge here is that, the exchange rate of naira to dollar, it's no stable. \n
30
- This issues makes tha market unstbale. \n Whenever he's making a sale and his unit price is more than the Cinuc Price, he makes a loss. \n This means he will spend more when buying again. \n A huge loss. \n
31
-
32
- He needs your help to halp with price prediction. \n As a way of preparing, he create a model to predict the exchange rate for the next 6 months. \n Then he's also providing today's date and today's exchange rate. \n
33
-
34
- As an expert, you are to analyze the data, the date in the data and the exchange rate. Then you are to make good recommendation based on what the forecasted exchange rate is. \n
35
- He will also provide you with a profit margin. \n Always make sure to analyse the data and exchange rate very well. \n
36
-
37
- You need to consider that whatever price you guve will be what he will give his customers for the next 1 year, and he needs to make profit. So youre giving something that will make him profit even after two years. \n
38
-
39
- Provide a good price recommendation, also provide a short explanation of your strategy to get to that price. \n
40
- Please always check you calculation to ensure you're giving the right figures. Your price should be in Naira\n
41
-
42
- Keep the following in mind: \n
43
- 1. Profit Margin is important. It will be given in the range of 0-100. \n
44
- 2. Always use a smart strategy to get to the price. \n
45
- 3. Predicted price should not exceed six digits. \n
46
-
47
- <|eot_id|><|start_header_id|>user<|end_header_id|>
48
- PRODUCT_DATA: {product_data} \n\n
49
- FORECASTED_EXCHANGE_RATE: {forecasted_value} \n\n
50
- TODAY: {date} \n\n
51
- Today's Exchange Rate: {today_rate} \n\n
52
- profit_margin: {profit_margin} \n\n
53
-
54
- <|eot_id|><|start_header_id|>assistant<|end_header_id|>""",
55
- input_variables=["product_data","forecasted_value", "date", 'today_rate', 'profit_margin'],
56
- )
57
-
58
- ai_markerter_chain = ai_markerter_prompt | model | StrOutputParser()
59
- output = ai_markerter_chain.invoke({"product_data":product_data, "forecasted_value":forecasted_value, "date":date, 'today_rate':today_rate, 'profit_margin':profit_margin})
60
- return output
61
-
62
-
63
- # creating a market validator, to validate the output
64
- def market_validator(product_data:list, forecasted_value: float, date: str, today_rate: float, model_response: str, profit_margin: float) -> str:
65
- model = ChatGroq(temperature=0.1, model_name="llama-3.1-8b-instant")
66
- ai_price_validator_prompt = PromptTemplate(
67
- template="""<|begin_of_text|><|start_header_id|>system<|end_header_id|>
68
- You are the best marketing and sales expert in the world, known for your meticulous attention to detail and your ability to validate and adjust financial predictions with precision. \n
69
- You have received a price recommendation from a model, along with the necessary data to verify its accuracy. \n
70
- Your task is to validate the model's output to ensure it is correct and aligns with the client's requirements. \n
71
-
72
- Here's what you need to consider:
73
- 1. The predicted value must be higher than the current Cinuc Price. \n
74
- 2. The predicted price must not exceed six figures. \n
75
- 3. The price should align with the forecasted exchange rate, especially when comparing it to the current rate. \n
76
- 4. The final price must ensure profitability over the next 1-2 years, even with potential fluctuations in the exchange rate. \n
77
- 5. Provide a smart and logical adjustment if needed, ensuring the final recommendation is optimal for the client. \n
78
- 6. Include a brief explanation for any adjustments or validations made. \n
79
- 7. The final price must be smart, correct, and profitable for the client. The price must be profitable!!!!! \n
80
- 8. Check all information again and again to ensure accuracy. \n
81
-
82
- Give the final price recommendation and provide a brief explanation of your validation process as the only output!!. \n
83
-
84
- <|eot_id|><|start_header_id|>user<|end_header_id|>
85
-
86
- PRODUCT_DATA: {product_data} \n\n
87
- FORECASTED_EXCHANGE_RATE: {forecasted_value} \n\n
88
- TODAY: {date} \n\n
89
- Today's Exchange Rate: {today_rate} \n\n
90
- profit_margin: {profit_margin} \n\n
91
- INITIAL_MODEL_RESPONSE: {model_response} \n\n
92
-
93
- <|eot_id|><|start_header_id|>assistant<|end_header_id|>
94
- """,
95
- input_variables=["product_data", "forecasted_value", "date", "today_rate", "model_response", "profit_margin"],
96
- )
97
- ai_price_validator = ai_price_validator_prompt | model | StrOutputParser()
98
- new_output = ai_price_validator.invoke({"product_data":product_data, "forecasted_value":forecasted_value, "date":date, 'today_rate':today_rate, 'model_response':model_response, 'profit_margin':profit_margin})
99
- return new_output
100
-
101
-
102
-
103
-
104
- # product_data = [{'Product': "Field's stain B 100ml", 'Category': 'MICROBIOLOGY AND LABORATORY REAGENTS', 'Unit Price': '4950', 'Cinuc Price': '4950', 'Exchange Rate': 775.0, 'Date': '31/07/2023'},
105
- # {'Product': "Field's stain B 100ml", 'Category': 'MICROBIOLOGY AND LABORATORY REAGENTS', 'Unit Price': 2000, 'Cinuc Price': 2000, 'Exchange Rate': 462.0, 'Date': '29/03/2023'}]
106
- # output = ai_markerter(product_data, Forecasted_price, today, today_rate, profit_margin)
107
- # new_output = market_validator(product_data, Forecasted_price, today, today_rate, output, profit_margin)
108
- # print(new_output)
 
1
+ import os
2
+ from dotenv import load_dotenv
3
+ from langchain_groq import ChatGroq
4
+ from langchain_core.prompts.prompt import PromptTemplate
5
+ from langchain_core.output_parsers import StrOutputParser
6
+ import time
7
+ load_dotenv()
8
+
9
+
10
+
11
+ os.environ["GROQ_API_KEY"] = os.getenv("GROQ_API_KEY")
12
+
13
+ model = ChatGroq(temperature=0.5, model_name="llama3-groq-8b-8192-tool-use-preview")
14
+
15
+ Forecasted_price = 2500
16
+ today = time.strftime("%d/%m/%Y")
17
+ today_rate = 1650
18
+ profit_margin = 50
19
+ def ai_markerter(product_data: list, forecasted_value: float, date:str, today_rate:float, profit_margin:float) -> str:
20
+ model = ChatGroq(temperature=0, model_name="llama3-groq-8b-8192-tool-use-preview")
21
+ ai_markerter_prompt = PromptTemplate(
22
+ template="""<|begin_of_text|><|start_header_id|>system<|end_header_id|>
23
+ You are the best marketing and sales expert in the world. You are excellent at, data analysis, statistics, and forecasting, you also have a lot of experience of market strategies with even little information. \n
24
+ You are hired by a client to help revolitionlize his business. His company's name is Cinuc. They are a laboratory equipment supplier. \n
25
+ One issue this client has is that he lacks data. He has some data. \n
26
+
27
+ In his data he has the product name, the category, the unit price, the cinuc price, the exchange rate and the date. \n Note that Cinuc Price is his selling price. \n The unit price is the price he buys the product. \n
28
+
29
+ Based on his business structure, he buys in bulk. Then he gives a fixed price to his customers for at least 2 years. \n One challenge here is that, the exchange rate of naira to dollar, it's no stable. \n
30
+ This issues makes tha market unstbale. \n Whenever he's making a sale and his unit price is more than the Cinuc Price, he makes a loss. \n This means he will spend more when buying again. \n A huge loss. \n
31
+
32
+ He needs your help to halp with price prediction. \n As a way of preparing, he create a model to predict the exchange rate for the next 6 months. \n Then he's also providing today's date and today's exchange rate. \n
33
+
34
+ As an expert, you are to analyze the data, the date in the data and the exchange rate. Then you are to make good recommendation based on what the forecasted exchange rate is. \n
35
+ He will also provide you with a profit margin. \n Always make sure to analyse the data and exchange rate very well. \n
36
+
37
+ You need to consider that whatever price you guve will be what he will give his customers for the next 1 year, and he needs to make profit. So youre giving something that will make him profit even after two years. \n
38
+
39
+ Provide a good price recommendation, also provide a short explanation of your strategy to get to that price. \n
40
+ Please always check you calculation to ensure you're giving the right figures. Your price should be in Naira\n
41
+
42
+ Keep the following in mind: \n
43
+ 1. Profit Margin is important. It will be given in the range of 0-100. \n
44
+ 2. Always use a smart strategy to get to the price. \n
45
+ 3. Predicted price should not exceed six digits. \n
46
+
47
+ <|eot_id|><|start_header_id|>user<|end_header_id|>
48
+ PRODUCT_DATA: {product_data} \n\n
49
+ FORECASTED_EXCHANGE_RATE: {forecasted_value} \n\n
50
+ TODAY: {date} \n\n
51
+ Today's Exchange Rate: {today_rate} \n\n
52
+ profit_margin: {profit_margin} \n\n
53
+
54
+ <|eot_id|><|start_header_id|>assistant<|end_header_id|>""",
55
+ input_variables=["product_data","forecasted_value", "date", 'today_rate', 'profit_margin'],
56
+ )
57
+
58
+ ai_markerter_chain = ai_markerter_prompt | model | StrOutputParser()
59
+ output = ai_markerter_chain.invoke({"product_data":product_data, "forecasted_value":forecasted_value, "date":date, 'today_rate':today_rate, 'profit_margin':profit_margin})
60
+ return output
61
+
62
+
63
+ # creating a market validator, to validate the output
64
+ def market_validator(product_data:list, forecasted_value: float, date: str, today_rate: float, model_response: str, profit_margin: float) -> str:
65
+ model = ChatGroq(temperature=0.7, model_name="llama-3.1-8b-instant")
66
+ ai_price_validator_prompt = PromptTemplate(
67
+ template="""<|begin_of_text|><|start_header_id|>system<|end_header_id|>
68
+ You are the best marketing and sales expert in the world, known for your meticulous attention to detail and your ability to validate and adjust financial predictions with precision. \n
69
+ You have received a price recommendation from a model, along with the necessary data to verify its accuracy. \n
70
+ Your task is to validate the model's output to ensure it is correct and aligns with the client's requirements. \n
71
+
72
+ Here's what you need to consider:
73
+ 1. The predicted value must be higher than the current Cinuc Price. \n
74
+ 2. The predicted price must not exceed six figures. \n
75
+ 3. The price should align with the forecasted exchange rate, especially when comparing it to the current rate. \n
76
+ 4. The final price must ensure profitability over the next 1-2 years, even with potential fluctuations in the exchange rate. \n
77
+ 5. Provide a smart and logical adjustment if needed, ensuring the final recommendation is optimal for the client. \n
78
+ 6. Include a brief explanation for any adjustments or validations made. \n
79
+ 7. The final price must be smart, correct, and profitable for the client. The price must be profitable!!!!! \n
80
+ 8. Check all information again and again to ensure accuracy. \n
81
+
82
+ Give the final price recommendation and provide a brief explanation of your validation process as the only output!!. \n
83
+
84
+ <|eot_id|><|start_header_id|>user<|end_header_id|>
85
+
86
+ PRODUCT_DATA: {product_data} \n\n
87
+ FORECASTED_EXCHANGE_RATE: {forecasted_value} \n\n
88
+ TODAY: {date} \n\n
89
+ Today's Exchange Rate: {today_rate} \n\n
90
+ profit_margin: {profit_margin} \n\n
91
+ INITIAL_MODEL_RESPONSE: {model_response} \n\n
92
+
93
+ <|eot_id|><|start_header_id|>assistant<|end_header_id|>
94
+ """,
95
+ input_variables=["product_data", "forecasted_value", "date", "today_rate", "model_response", "profit_margin"],
96
+ )
97
+ ai_price_validator = ai_price_validator_prompt | model | StrOutputParser()
98
+ new_output = ai_price_validator.invoke({"product_data":product_data, "forecasted_value":forecasted_value, "date":date, 'today_rate':today_rate, 'model_response':model_response, 'profit_margin':profit_margin})
99
+ return new_output
100
+
101
+
102
+
103
+
104
+ # product_data = [{'Product': "Field's stain B 100ml", 'Category': 'MICROBIOLOGY AND LABORATORY REAGENTS', 'Unit Price': '4950', 'Cinuc Price': '4950', 'Exchange Rate': 775.0, 'Date': '31/07/2023'},
105
+ # {'Product': "Field's stain B 100ml", 'Category': 'MICROBIOLOGY AND LABORATORY REAGENTS', 'Unit Price': 2000, 'Cinuc Price': 2000, 'Exchange Rate': 462.0, 'Date': '29/03/2023'}]
106
+ # output = ai_markerter(product_data, Forecasted_price, today, today_rate, profit_margin)
107
+ # new_output = market_validator(product_data, Forecasted_price, today, today_rate, output, profit_margin)
108
+ # print(new_output)