-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidator.py
More file actions
41 lines (31 loc) · 1.23 KB
/
Copy pathvalidator.py
File metadata and controls
41 lines (31 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from langchain_openai import ChatOpenAI
from langchain_core.prompts import PromptTemplate
from dotenv import load_dotenv
import json
load_dotenv()
def get_market_guardrails(product_name, country_config):
llm = ChatOpenAI(model="gpt-4o", temperature=0)
currency = country_config.get('currency_symbol', '$')
country = country_config.get('country_full', 'Unknown')
template = """
You are a Market Calibration Engine.
Product: "{product_name}"
Target Market: {country}
Currency: {currency}
TASK: Determine the REALISTIC price range for one unit of this product in {currency}.
Exclude cheap accessories.
EXAMPLES:
- Smart Ring (India/₹) -> min: 3000, max: 35000
- Smart Ring (UK/£) -> min: 40, max: 400
OUTPUT JSON ONLY:
{{
"min_price": 50,
"max_price": 400
}}
"""
prompt = PromptTemplate(input_variables=["product_name", "country", "currency"], template=template)
try:
res = llm.invoke(prompt.format(product_name=product_name, country=country, currency=currency))
return json.loads(res.content.replace("```json", "").replace("```", "").strip())
except:
return {"min_price": 10, "max_price": 1000000}