DEV Community

shashank ms
shashank ms

Posted on

Applications of LLM in Social Media Analysis

We are building a social-media analysis agent that reads raw post and comment text, extracts structured insights, and returns a ranked summary. It helps community managers and product teams track sentiment and emerging topics without manually reading thousands of messages. We will wire it to Oxlo.ai so the cost stays flat per request, which matters when you are stuffing long comment threads into the context window.

What you'll need

You need Python 3.10+, the OpenAI SDK, and an Oxlo.ai API key from https://portal.oxlo.ai. Install the SDK with pip.

pip install openai

Step 1: Define the system prompt

I start by locking the model into a structured analyst role. The prompt enforces a strict JSON schema so we can parse the result with the standard library.

SYSTEM_PROMPT = """You are a social-media analyst. You receive a batch of raw post titles and comments. Analyze them and return a single JSON object with exactly these keys:

- overall_sentiment: one of Positive, Neutral, Negative
- top_topics: array of up to 5 topics discussed, each with a topic string and mention_count integer
- pain_points: array of up to 5 complaints or frustrations
- action_items: array of up to 3 concrete recommendations for the product team

Be concise. Do not wrap the JSON in markdown fences."""

Step 2: Initialize the Oxlo.ai client

We point the OpenAI SDK at Oxlo.ai. I use llama-3.3-70b because it handles long context reliably, and with Oxlo.ai the price is flat per request regardless of how many comments we pack in. See https://oxlo.ai/pricing for current plans.

from openai import OpenAI
import json

client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")

def analyze_social_media(posts: list[str]):
    # Number posts so the model can reference them if needed
    content = "\n\n".join(f"[{i+1}] {p}" for i, p in enumerate(posts))

    response = client.chat.completions.create(
        model="llama-3.3-70b",
        messages=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": content},
        ],
    )

    raw = response.choices[0].message.content
    return json.loads(raw)

Step 3: Prepare raw social data

For this demo I hardcode a list of comments from a fictional product launch thread. In production you would stream these from Reddit, X, or your Discord export.

RAW_POSTS = [
    "The new export feature is a lifesaver, but it crashes on files over 500MB.",
    "Love the UI refresh. Dark mode finally looks consistent.",
    "Can we get keyboard shortcuts? Clicking through menus is exhausting.",
    "Export crash is still there in v2.1. Makes the app unusable for video.",
    "Dark mode is nice, but the contrast on the settings page is rough.",
    "Customer support never answers. I have been waiting three days.",
    "Keyboard shortcuts would speed up my workflow so much.",
    "The pricing page is confusing. I cannot tell what plan I need.",
    "Export issue is a dealbreaker. Switching to competitor until fixed.",
    "Export hangs every time I try 4K. This is basic functionality.",
]

Step 4: Add a reporting helper

I like to wrap the raw JSON in a small printer so the CLI output is readable during daily standups.

def print_report(data: dict):
    print(f"Sentiment: {data['overall_sentiment']}")
    print("\nTop Topics:")
    for t in data.get("top_topics", []):
        print(f"  - {t['topic']} ({t['mention_count']} mentions)")
    print("\nPain Points:")
    for p in data.get("pain_points", []):
        print(f"  - {p}")
    print("\nAction Items:")
    for a in data.get("action_items", []):
        print(f"  - {a}")

if __name__ == "__main__":
    result = analyze_social_media(RAW_POSTS)
    print_report(result)

Run it

Save the file as social_analyzer.py, replace YOUR_OXLO_API_KEY with your key from https://portal.oxlo.ai, and run it. You should see structured output in under a few seconds.

$ python social_analyzer.py
Sentiment: Negative

Top Topics:
  - Export crash (4 mentions)
  - UI / Dark mode (2 mentions)
  - Keyboard shortcuts (2 mentions)
  - Customer support (1 mentions)
  - Pricing page (1 mentions)

Pain Points:
  - Export crashes on large files and persists in v2.1
  - Lack of keyboard shortcuts slows workflow
  - Customer support response times are too long
  - Pricing page is confusing and hard to understand
  - Stability issues causing users to switch to competitors

Action Items:
  - Prioritize fixing the export crash for files over 500MB
  - Implement keyboard shortcuts to improve navigation efficiency
  - Improve customer support response times and pricing page clarity

Next steps

That gives you a working social media analysis agent in under fifty lines. To push it further, wire the RAW_POSTS list to the Reddit or X API so the feed is live, or switch the model to kimi-k2.6 on Oxlo.ai if you want deeper reasoning over longer comment threads. You can also add a second Oxlo.ai call that drafts a public response to the top pain points, keeping the whole pipeline on flat per-request pricing.

Top comments (0)