| from duckduckgo_search import DDGS |
| from openai import OpenAI |
| import os |
|
|
| openai_client = OpenAI(api_key=os.getenv("OPENAI_API_KEY")) |
|
|
| def web_search(topic, max_results=3): |
| try: |
| with DDGS() as ddgs: |
| results = list(ddgs.text(topic, max_results=max_results)) |
| return str(results) |
| except Exception as e: |
| return f"Search Error: {str(e)}" |
|
|
| def summarize_content(text): |
| try: |
| response = openai_client.chat.completions.create( |
| model="gpt-4o", |
| messages=[ |
| {"role": "system", "content": "You are an expert summarizer. Provide concise, high-value insights."}, |
| {"role": "user", "content": f"Summarize the following content: {text}"} |
| ] |
| ) |
| return response.choices[0].message.content |
| except Exception as e: |
| return f"Summarization Error: {str(e)}" |
|
|
| def analyze_product_trends(category): |
| try: |
| with DDGS() as ddgs: |
| |
| results = list(ddgs.text(f"high margin top selling products in {category} 2026", max_results=5)) |
| |
| |
| prompt = f"Analyze these search results for {category} products and identify high-margin, top-selling potential items: {results}" |
| response = openai_client.chat.completions.create( |
| model="gpt-4o", |
| messages=[ |
| {"role": "system", "content": "You are a product trend analyst. Identify high-margin, top-selling products based on search data."}, |
| {"role": "user", "content": prompt} |
| ] |
| ) |
| return response.choices[0].message.content |
| except Exception as e: |
| return f"Analysis Error: {str(e)}" |
|
|