Add AI chat demo with prompt-based embedding ad targeting#1187
Draft
ericholscher wants to merge 4 commits intomainfrom
Draft
Add AI chat demo with prompt-based embedding ad targeting#1187ericholscher wants to merge 4 commits intomainfrom
ericholscher wants to merge 4 commits intomainfrom
Conversation
Introduces a chat prototype that sends prompts to OpenAI (gpt-4o-mini) and simultaneously passes the prompt to the ethical ads decision API. The backend generates an embedding from the prompt text and uses cosine similarity against advertiser content embeddings for niche ad targeting. - Add `prompt` field to AdDecisionSerializer for embedding-based targeting - Create chatdemo app with embedding utility, views, and jQuery frontend - Wire prompt embeddings into ProbabilisticFlightBackend for niche targeting - Add ChatCompletionProxyView to keep OpenAI API key server-side - Frontend at /chat/ shows chat + contextual ad sidebar https://claude.ai/code/session_01YGtppBeFRZNHxdEguYKxnY
A convenience script that wires up existing model instances (or creates minimal ones) so the /chat/ demo can request and display ads locally. https://claude.ai/code/session_01YGtppBeFRZNHxdEguYKxnY
Publishes total queue depth (celery + analyzer + priority) to CloudWatch every minute as EthicalAds/Celery/QueueDepth. Used by the celery ASG target tracking autoscaling policy in the ops repo.
Run ruff --fix on scripts/prep_chat_demo_db.py to resolve 8 lint errors (unused imports, f-strings without placeholders). Add comprehensive tests for the chatdemo embedding utilities, views, and the publish_celery_queue_depth task to bring coverage back above the 94% threshold.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Prototype of an AI chat interface that targets ethical ads based on conversation context using embeddings.
/chat/sends user prompts to OpenAI (gpt-4o-mini) for responsespromptfieldtext-embedding-3-small) from the prompt text and computes cosine similarity against advertiser content embeddingsniche_targetingset in theirtargeting_parametersare filtered by this similarity scoreethicalads_ext.embeddingis used as a fallbackTargeting approach
text-embedding-3-smallmodel and cached for 1 hourniche_targetingthreshold (lower distance = better match)Local setup
The prep script grabs the first existing Publisher, Advertiser, Campaign, Flight, Advertisement, and AdType, then patches them to be live and wired together for the demo.
Test plan
python manage.py shell < scripts/prep_chat_demo_db.pyon a fresh DB and verify it creates all needed objects/chat/, send a message, verify chat response appearspromptandkeywordsparamsOPENAI_API_KEYunset: chat returns error, ad API still works via keyword targetingcurl 'http://localhost:8000/api/v1/decision/?publisher=SLUG&div_ids=ad1&ad_types=AD_TYPE&prompt=python+web+development'https://claude.ai/code/session_01YGtppBeFRZNHxdEguYKxnY