mgbam commited on
Commit
d73f096
·
verified ·
1 Parent(s): 065cfda

Update notebooks/demo_notebook.ipynb

Browse files
Files changed (1) hide show
  1. notebooks/demo_notebook.ipynb +101 -65
notebooks/demo_notebook.ipynb CHANGED
@@ -1,67 +1,103 @@
1
  {
2
- "cells": [
3
- {
4
- "cell_type": "markdown",
5
- "metadata": {},
6
- "source": [
7
- "# Shasha Demo Notebook\n",
8
- "This notebook shows how to programmatically invoke our AI inference pipeline, run sentiment analysis, and generate code examples."
9
- ]
10
- },
11
- {
12
- "cell_type": "code",
13
- "execution_count": null,
14
- "metadata": {},
15
- "outputs": [],
16
- "source": [
17
- "# 1. Setup inference client\n",
18
- "from hf_client import get_inference_client\n",
19
- "# Initialize client for Qwen3-32B (fallback on Groq if unavailable)\n",
20
- "client = get_inference_client('Qwen/Qwen3-32B', provider='auto')\n",
21
- "# Example chat completion request\n",
22
- "resp = client.chat.completions.create(\n",
23
- " model='Qwen/Qwen3-32B',\n",
24
- " messages=[{'role':'user','content':'Write a Python function to reverse a string.'}]\n",
25
- ")\n",
26
- "print(resp.choices[0].message.content)"
27
- ]
28
- },
29
- {
30
- "cell_type": "code",
31
- "execution_count": null,
32
- "metadata": {},
33
- "outputs": [],
34
- "source": [
35
- "# 2. Sentiment Analysis with Transformers.js (Python demo)\n",
36
- "from transformers import pipeline\n",
37
- "# Using OpenAI provider for sentiment\n",
38
- "sentiment = pipeline('sentiment-analysis', model='openai/gpt-4', trust_remote_code=True)\n",
39
- "print(sentiment('I love building AI-powered tools!'))"
40
- ]
41
- },
42
- {
43
- "cell_type": "markdown",
44
- "metadata": {},
45
- "source": [
46
- "---\n",
47
- "## Next steps:\n",
48
- "- Try different models (Gemini Pro, Fireworks AI) by changing the model= parameter.\n",
49
- "- Explore custom plugins via plugins.py to integrate with Slack or GitHub.\n",
50
- "- Use auth.py to load private files from Google Drive."
51
- ]
52
- }
53
- ],
54
- "metadata": {
55
- "kernelspec": {
56
- "display_name": "Python 3",
57
- "language": "python",
58
- "name": "python3"
59
- },
60
- "language_info": {
61
- "name": "python",
62
- "version": "3.x"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  }
64
- },
65
- "nbformat": 4,
66
- "nbformat_minor": 5
67
- }
 
1
  {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# AnyCoder Demo Notebook\n",
8
+ "\n",
9
+ "This notebook illustrates how to:\n",
10
+ "\n",
11
+ "1. **Instantiate** the unified `hf_client` with automatic provider routing.\n",
12
+ "2. **Call** a chat completion (Groq → OpenAI → Gemini fall‑back).\n",
13
+ "3. **Trigger** the FastAPI `/predict` endpoint served by *app.py*.\n",
14
+ "4. **Run** a quick sentiment‑analysis pipeline using your preferred provider."
15
+ ]
16
+ },
17
+ {
18
+ "cell_type": "code",
19
+ "execution_count": null,
20
+ "metadata": {},
21
+ "outputs": [],
22
+ "source": [
23
+ "# 1. Setup inference client\n",
24
+ "from hf_client import get_inference_client\n",
25
+ "\n",
26
+ "# Choose a model (will route to best provider according to prefix rules)\n",
27
+ "model_id = 'openai/gpt-4' # try 'gemini/pro' or any HF model path\n",
28
+ "client = get_inference_client(model_id, provider='auto')\n",
29
+ "\n",
30
+ "# Simple chat completion\n",
31
+ "resp = client.chat.completions.create(\n",
32
+ " model=model_id,\n",
33
+ " messages=[{'role': 'user', 'content': 'Write a Python function to reverse a string.'}]\n",
34
+ ")\n",
35
+ "print(resp.choices[0].message.content)"
36
+ ]
37
+ },
38
+ {
39
+ "cell_type": "code",
40
+ "execution_count": null,
41
+ "metadata": {},
42
+ "outputs": [],
43
+ "source": [
44
+ "# 2. Sentiment analysis via HF Inference Providers (OpenAI GPT‑4)\n",
45
+ "from transformers import pipeline\n",
46
+ "\n",
47
+ "sentiment = pipeline(\n",
48
+ " 'sentiment-analysis', \n",
49
+ " model='openai/gpt-4', # could be 'gemini/pro' etc.\n",
50
+ " trust_remote_code=True\n",
51
+ ")\n",
52
+ "sentiment('I love building AI‑powered tools!')"
53
+ ]
54
+ },
55
+ {
56
+ "cell_type": "code",
57
+ "execution_count": null,
58
+ "metadata": {},
59
+ "outputs": [],
60
+ "source": [
61
+ "# 3. Call the FastAPI /predict endpoint exposed by app.py\n",
62
+ "import json, requests\n",
63
+ "\n",
64
+ "payload = {\n",
65
+ " 'prompt': 'Generate a minimal HTML page.',\n",
66
+ " 'model_id': 'gemini/pro',\n",
67
+ " 'language': 'html',\n",
68
+ " 'web_search': False\n",
69
+ "}\n",
70
+ "\n",
71
+ "r = requests.post('http://localhost:7860/predict', json=payload)\n",
72
+ "print('Status:', r.status_code)\n",
73
+ "print(json.loads(r.text)['code'][:400])"
74
+ ]
75
+ },
76
+ {
77
+ "cell_type": "markdown",
78
+ "metadata": {},
79
+ "source": [
80
+ "---\n",
81
+ "## Next steps\n",
82
+ "\n",
83
+ "* Switch `model_id` to **`'gemini/pro'`**, **`'fireworks-ai/fireworks-v1'`**, or any HF model (e.g. `Qwen/Qwen3-32B`)—routing will adjust automatically.\n",
84
+ "* Explore **`plugins.py`** for Slack / GitHub integrations.\n",
85
+ "* Use **`auth.py`** helpers to pull private Google Drive docs into the pipeline.\n",
86
+ "* Extend `/predict` with temperature, max‑tokens, or stream support."
87
+ ]
88
+ }
89
+ ],
90
+ "metadata": {
91
+ "kernelspec": {
92
+ "display_name": "Python 3",
93
+ "language": "python",
94
+ "name": "python3"
95
+ },
96
+ "language_info": {
97
+ "name": "python",
98
+ "version": "3.x"
99
+ }
100
+ },
101
+ "nbformat": 4,
102
+ "nbformat_minor": 5
103
  }