Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions Class1/class1/.mcp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"mcpServers": {
"filesystem": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/Users/ming/Desktop/Learning/MLE_in_Gen_AI-Course/Class1/class1"
]
},
"sequential-thinking": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-sequential-thinking"
]
},
"puppeteer": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-puppeteer"
]
},
"brave-search": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-brave-search"
],
"env": {
"BRAVE_API_KEY": "YOUR_BRAVE_API_KEY"
}
},
"github": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-github"
],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "YOUR_GITHUB_PERSONAL_ACCESS_TOKEN"
}
},
"notion": {
"type": "http",
"url": "https://mcp.notion.com/mcp"
}
}
}
197 changes: 188 additions & 9 deletions Class1/class1/Class 1 Homework.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,16 @@
},
{
"cell_type": "raw",
"metadata": {},
"metadata": {
"vscode": {
"languageId": "raw"
}
},
"source": [
"curl http://localhost:11434/v1/chat/completions \\\n",
" -H \"Content-Type: application/json\" \\\n",
" -d '{\n",
" \"model\": \"llama2\",\n",
" \"model\": \"gemma4:26b\",\n",
" \"messages\": [\n",
" {\n",
" \"role\": \"system\",\n",
Expand All @@ -146,9 +150,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The 2020 World Series was played at **Globe Life Field** in Arlington, Texas. \n",
"\n",
"Because of the COVID-19 pandemic, Major League Baseball decided to host the entire postseason at a single site to minimize travel and reduce the risk of virus transmission.\n"
]
}
],
"source": [
"from openai import OpenAI\n",
"\n",
Expand All @@ -158,7 +172,7 @@
")\n",
"\n",
"response = client.chat.completions.create(\n",
" model=\"llama2\",\n",
" model=\"gemma4:26b\",\n",
" messages=[\n",
" {\"role\": \"system\", \"content\": \"You are a helpful assistant.\"},\n",
" {\"role\": \"user\", \"content\": \"Who won the world series in 2020?\"},\n",
Expand All @@ -169,6 +183,69 @@
"print(response.choices[0].message.content)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Note\n",
"# `base_url` 筆記\n",
"## 1. 把 `base_url` 拆成四段看\n",
"```python\n",
"base_url=\"http://localhost:11434/v1\"\n",
"```\n",
"可以拆成:\n",
"```text\n",
"http://localhost:11434/v1\n",
"│ │ │ │\n",
"│ │ │ └─ OpenAI-compatible API 路徑\n",
"│ │ └────── Ollama 預設 port\n",
"│ └──────────────── 你的本機電腦\n",
"└─────────────────────── HTTP 協定\n",
"```\n",
"意思是:這段網址不是連到 OpenAI 官方 API,而是連到你自己電腦上正在執行的 Ollama server。\n",
"\n",
"## 2. `base_url` 像是模型倉庫的地址\n",
"可以把:\n",
"```python\n",
"base_url=\"http://localhost:11434/v1\"\n",
"```\n",
"想成「模型倉庫的地址」。而:\n",
"\n",
"```python\n",
"model=\"gemma4:26b\"\n",
"model=\"qwen3.6:35b\"\n",
"```\n",
"\n",
"則是「你要叫哪一個模型出來工作」。\n",
"所以如果 `gemma4:26b` 和 `qwen3.6:35b` 都在同一個 Ollama 裡面,只需要一個 `base_url`:\n",
"```python\n",
"client = OpenAI(\n",
" base_url=\"http://localhost:11434/v1\",\n",
" api_key=\"ollama\",\n",
")\n",
"```\n",
"\n",
"每次呼叫時,只要換 `model` 名稱就好:\n",
"```python\n",
"response = client.chat.completions.create(\n",
" model=\"gemma4:26b\",\n",
" messages=[{\"role\": \"user\", \"content\": \"Hello!\"}],\n",
")\n",
"\n",
"response = client.chat.completions.create(\n",
" model=\"qwen3.6:35b\",\n",
" messages=[{\"role\": \"user\", \"content\": \"Hello!\"}],\n",
")\n",
"```\n",
"\n",
"## 3. 核心觀念\n",
"\n",
"* 同一個 Ollama server 裡有多個模型時,通常只需要一個 `base_url`。\n",
"* `base_url` 決定要連到哪一個模型服務。\n",
"* `model` 決定要使用該服務裡面的哪一個模型。\n",
"* 只有當模型放在不同服務或不同機器上時,才需要不同的 `base_url`。\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -220,9 +297,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"User prompt: 'What is the capital of Germany?'\n",
"Model answer: The capital of Germany is **Berlin**.\n"
]
}
],
"source": [
"# Example: Using LCEL to reproduce a \"Basic Prompting\" scenario\n",
"from langchain_core.prompts import PromptTemplate\n",
Expand All @@ -236,7 +322,7 @@
")\n",
"\n",
"# 3. Define the model\n",
"model = ChatOllama(model = [\"llama2\"]) # Using Ollama \n",
"model = ChatOllama(model = \"gemma4:26b\") # Using Ollama \n",
"\n",
"# 4. Chain the components together using LCEL\n",
"chain = (\n",
Expand All @@ -253,6 +339,85 @@
"print(\"Model answer:\", result)\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"#%pip install -U langchain-ollama\n",
"#%pip show langchain langchain-core langchain-community langchain-ollama"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"* Running on local URL: http://127.0.0.1:7862\n",
"* To create a public link, set `share=True` in `launch()`.\n"
]
},
{
"data": {
"text/html": [
"<div><iframe src=\"http://127.0.0.1:7862/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/plain": []
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import gradio as gr\n",
"from langchain_ollama import ChatOllama\n",
"from langchain_core.messages import HumanMessage\n",
"\n",
"llm = ChatOllama(\n",
" model=\"gemma4:26b\",\n",
" base_url=\"http://localhost:11434\",\n",
" temperature=0.7\n",
")\n",
"\n",
"def chat_with_ollama(user_input):\n",
" try:\n",
" if not user_input.strip():\n",
" return \"Please enter a message.\"\n",
"\n",
" response = llm.invoke([\n",
" HumanMessage(content=user_input)\n",
" ])\n",
"\n",
" return response.content\n",
"\n",
" except Exception as e:\n",
" return f\"Error: {type(e).__name__}\\n\\n{str(e)}\"\n",
"\n",
"demo = gr.Interface(\n",
" fn=chat_with_ollama,\n",
" inputs=gr.Textbox(lines=5, label=\"Your prompt\"),\n",
" outputs=gr.Textbox(lines=10, label=\"Ollama response\"),\n",
" title=\"Ollama + LangChain + Gradio\"\n",
")\n",
"\n",
"demo.launch()"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -266,8 +431,22 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "llm_course_env",
"language": "python",
"name": "python3"
},
"language_info": {
"name": "python"
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.11"
}
},
"nbformat": 4,
Expand Down
Binary file added Class1/class1/hw_output/brave.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Class1/class1/hw_output/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Class1/class1/hw_output/github.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions Class1/class1/hw_output/hello.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello MCP!
1 change: 1 addition & 0 deletions Class1/class1/hw_output/notion.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://www.notion.so/MCP-Automation-Test-36970be48b76812fbfeaca71d47e808d?source=copy_link
Binary file added Class1/class1/hw_output/ollama.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions Class1/class1/hw_output/table_no_outline_h2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Day,Time,Location
Wednesday,3-6 pm,Cal Poly Campus (follow U-Pick Signs)
Thursday,2:30-5pm,Morro Bay Farmer's Market
Thursday,6:10-9pm,Downtown SLO Farmer's Market
Saturday,8-10:30am,Farmer's Market new Embassy Suites
Saturday,11am-2pm,Cal Poly Campus (follow U-Pick signs)
13 changes: 13 additions & 0 deletions Class1/class1/hw_output/table_no_outline_h2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Table No Outline - H2

> **Source:** https://afd.calpoly.edu/web/sample-tables
> **Caption:** No Style Table Listing
> **Extracted by:** Puppeteer MCP — 2026-05-23

| Day | Time | Location |
|-----|------|----------|
| Wednesday | 3-6 pm | Cal Poly Campus (follow U-Pick Signs) |
| Thursday | 2:30-5pm | Morro Bay Farmer's Market |
| Thursday | 6:10-9pm | Downtown SLO Farmer's Market |
| Saturday | 8-10:30am | Farmer's Market new Embassy Suites |
| Saturday | 11am-2pm | Cal Poly Campus (follow U-Pick signs) |
Binary file added Class1/class1/hw_output/thinking.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.