Update notebooks/demo_notebook.ipynb
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061622345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210364656667{"cells": [{"cell_type": "markdown","metadata": {},"source": ["# Shasha Demo Notebook\n","This notebook shows how to programmatically invoke our AI inference pipeline, run sentiment analysis, and generate code examples."]},{"cell_type": "code","execution_count": null,"metadata": {},"outputs": [],"source": ["# 1. Setup inference client\n","from hf_client import get_inference_client\n","# Initialize client for Qwen3-32B (fallback on Groq if unavailable)\n","client = get_inference_client('Qwen/Qwen3-32B', provider='auto')\n","# Example chat completion request\n","resp = client.chat.completions.create(\n"," model='Qwen/Qwen3-32B',\n"," messages=[{'role':'user','content':'Write a Python function to reverse a string.'}]\n",")\n","print(resp.choices[0].message.content)"]},{"cell_type": "code","execution_count": null,"metadata": {},"outputs": [],"source": ["# 2. Sentiment Analysis with Transformers.js (Python demo)\n","from transformers import pipeline\n","# Using OpenAI provider for sentiment\n","sentiment = pipeline('sentiment-analysis', model='openai/gpt-4', trust_remote_code=True)\n","print(sentiment('I love building AI-powered tools!'))"]},{"cell_type": "markdown","metadata": {},"source": ["---\n","## Next steps:\n","- Try different models (Gemini Pro, Fireworks AI) by changing the model= parameter.\n","- Explore custom plugins via plugins.py to integrate with Slack or GitHub.\n","- Use auth.py to load private files from Google Drive."]}],"metadata": {"kernelspec": {"display_name": "Python 3","language": "python","name": "python3"},"language_info": {"name": "python","version": "3.x" "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# AnyCoder Demo Notebook\n", "\n", "This notebook illustrates how to:\n", "\n", "1. **Instantiate** the unified `hf_client` with automatic provider routing.\n", "2. **Call** a chat completion (Groq → OpenAI → Gemini fall‑back).\n", "3. **Trigger** the FastAPI `/predict` endpoint served by *app.py*.\n", "4. **Run** a quick sentiment‑analysis pipeline using your preferred provider." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 1. Setup inference client\n", "from hf_client import get_inference_client\n", "\n", "# Choose a model (will route to best provider according to prefix rules)\n", "model_id = 'openai/gpt-4' # try 'gemini/pro' or any HF model path\n", "client = get_inference_client(model_id, provider='auto')\n", "\n", "# Simple chat completion\n", "resp = client.chat.completions.create(\n", " model=model_id,\n", " messages=[{'role': 'user', 'content': 'Write a Python function to reverse a string.'}]\n", ")\n", "print(resp.choices[0].message.content)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 2. Sentiment analysis via HF Inference Providers (OpenAI GPT‑4)\n", "from transformers import pipeline\n", "\n", "sentiment = pipeline(\n", " 'sentiment-analysis', \n", " model='openai/gpt-4', # could be 'gemini/pro' etc.\n", " trust_remote_code=True\n", ")\n", "sentiment('I love building AI‑powered tools!')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# 3. Call the FastAPI /predict endpoint exposed by app.py\n", "import json, requests\n", "\n", "payload = {\n", " 'prompt': 'Generate a minimal HTML page.',\n", " 'model_id': 'gemini/pro',\n", " 'language': 'html',\n", " 'web_search': False\n", "}\n", "\n", "r = requests.post('http://localhost:7860/predict', json=payload)\n", "print('Status:', r.status_code)\n", "print(json.loads(r.text)['code'][:400])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "---\n", "## Next steps\n", "\n", "* Switch `model_id` to **`'gemini/pro'`**, **`'fireworks-ai/fireworks-v1'`**, or any HF model (e.g. `Qwen/Qwen3-32B`)—routing will adjust automatically.\n", "* Explore **`plugins.py`** for Slack / GitHub integrations.\n", "* Use **`auth.py`** helpers to pull private Google Drive docs into the pipeline.\n", "* Extend `/predict` with temperature, max‑tokens, or stream support." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "name": "python", "version": "3.x" } }, "nbformat": 4, "nbformat_minor": 5}},"nbformat": 4,"nbformat_minor": 5}notebooks/demo_notebook.ipynb+101-65