Skip to content

Instantly share code, notes, and snippets.

@up1
Last active May 21, 2025 15:37
Show Gist options
  • Save up1/28c8965e2de7c4c6b3b4328d7f769457 to your computer and use it in GitHub Desktop.
Save up1/28c8965e2de7c4c6b3b4328d7f769457 to your computer and use it in GitHub Desktop.
Demo with Foundry Local
# 1. ติดตั้ง
$brew tap microsoft/foundrylocal
$brew install foundrylocal
# 2. ดู Model ที่สนับสนุน
$foundry model list
🟢 Service is Started on http://localhost:5273, PID 28974!
Alias Device Task File Size License Model ID
-----------------------------------------------------------------------------------------------
phi-4 GPU chat-completion 8.37 GB MIT Phi-4-generic-gpu
CPU chat-completion 10.16 GB MIT Phi-4-generic-cpu
--------------------------------------------------------------------------------------------------------
mistral-7b-v0.2 GPU chat-completion 4.07 GB apache-2.0 mistralai-Mistral-7B-Instruct-v0-2-generic-gpu
CPU chat-completion 4.07 GB apache-2.0 mistralai-Mistral-7B-Instruct-v0-2-generic-cpu
-------------------------------------------------------------------------------------------------------------------------------------
phi-3.5-mini GPU chat-completion 2.16 GB MIT Phi-3.5-mini-instruct-generic-gpu
CPU chat-completion 2.53 GB MIT Phi-3.5-mini-instruct-generic-cpu
------------------------------------------------------------------------------------------------------------------------
phi-3-mini-128k GPU chat-completion 2.13 GB MIT Phi-3-mini-128k-instruct-generic-gpu
CPU chat-completion 2.54 GB MIT Phi-3-mini-128k-instruct-generic-cpu
---------------------------------------------------------------------------------------------------------------------------
phi-3-mini-4k GPU chat-completion 2.13 GB MIT Phi-3-mini-4k-instruct-generic-gpu
CPU chat-completion 2.53 GB MIT Phi-3-mini-4k-instruct-generic-cpu
-------------------------------------------------------------------------------------------------------------------------
phi-4-mini-reasoning GPU chat-completion 3.15 GB MIT Phi-4-mini-reasoning-generic-gpu
CPU chat-completion 4.52 GB MIT Phi-4-mini-reasoning-generic-cpu
-----------------------------------------------------------------------------------------------------------------------
qwen2.5-0.5b GPU chat-completion 0.68 GB apache-2.0 qwen2.5-0.5b-instruct-generic-gpu
CPU chat-completion 0.80 GB apache-2.0 qwen2.5-0.5b-instruct-generic-cpu
------------------------------------------------------------------------------------------------------------------------
qwen2.5-coder-0.5b GPU chat-completion 0.52 GB apache-2.0 qwen2.5-coder-0.5b-instruct-generic-gpu
CPU chat-completion 0.80 GB apache-2.0 qwen2.5-coder-0.5b-instruct-generic-cpu
------------------------------------------------------------------------------------------------------------------------------
qwen2.5-1.5b GPU chat-completion 1.51 GB apache-2.0 qwen2.5-1.5b-instruct-generic-gpu
CPU chat-completion 1.78 GB apache-2.0 qwen2.5-1.5b-instruct-generic-cpu
------------------------------------------------------------------------------------------------------------------------
qwen2.5-7b GPU chat-completion 5.20 GB apache-2.0 qwen2.5-7b-instruct-generic-gpu
CPU chat-completion 6.16 GB apache-2.0 qwen2.5-7b-instruct-generic-cpu
----------------------------------------------------------------------------------------------------------------------
qwen2.5-coder-1.5b GPU chat-completion 1.25 GB apache-2.0 qwen2.5-coder-1.5b-instruct-generic-gpu
CPU chat-completion 1.78 GB apache-2.0 qwen2.5-coder-1.5b-instruct-generic-cpu
------------------------------------------------------------------------------------------------------------------------------
qwen2.5-coder-7b GPU chat-completion 4.73 GB apache-2.0 qwen2.5-coder-7b-instruct-generic-gpu
CPU chat-completion 6.16 GB apache-2.0 qwen2.5-coder-7b-instruct-generic-cpu
----------------------------------------------------------------------------------------------------------------------------
qwen2.5-14b GPU chat-completion 9.30 GB apache-2.0 qwen2.5-14b-instruct-generic-gpu
CPU chat-completion 11.06 GB apache-2.0 qwen2.5-14b-instruct-generic-cpu
-----------------------------------------------------------------------------------------------------------------------
qwen2.5-coder-14b GPU chat-completion 8.79 GB apache-2.0 qwen2.5-coder-14b-instruct-generic-gpu
CPU chat-completion 11.06 GB apache-2.0 qwen2.5-coder-14b-instruct-generic-cpu
# 1. ใช้งาน qwen2.5-coder-0.5b
$foundry model run qwen2.5-coder-0.5b
foundry model run qwen2.5-coder-0.5b
Downloading model...
[####################################] 100.00 % [Time remaining: about 0s] 5.7 MB/s/s
🕗 Loading model...
🟢 Model qwen2.5-coder-0.5b-instruct-generic-gpu loaded successfully
Interactive Chat. Enter /? or /help for help.
Interactive mode, please enter your prompt
# 2. ทดสอบใช้งาน
>generate bubble source in golang
🤖 Here's a Go program that generates a Bubble sort algorithm:
```go
package main
import (
"fmt"
)
func bubbleSort(arr []int) {
n := len(arr)
for i := 0; i < n-1; i++ {
// Traverse the array from 0 to n-i-1
for j := 0; j < n-i-1; j++ {
// Swap if arr[i] is greater than arr[j]
if arr[i] > arr[j] {
arr[i], arr[j] = arr[j], arr[i]
}
}
}
}
func main() {
arr := []int{64, 34, 25, 12, 22, 11, 90}
fmt.Println("Original array:")
fmt.Println(arr)
bubbleSort(arr)
fmt.Println("\nSorted array:")
fmt.Println(arr)
}
```
When you run this program, it will print the original array and then execute the Bubble sort algorithm on it. The output will be:
```
Original array:
[64 34 25 12 22 11 90]
Sorted array:
[11 22 34 12 64 90 25]
```
The Bubble sort algorithm works by repeatedly stepping through the list, comparing adjacent elements, and swapping them if they are in the wrong order. This process is repeated until the list is sorted.
$python demo.py
```go
package main
import "fmt"
func bubbleSort(arr []int) {
n := len(arr)
for i := 0; i < n-1; i++ {
for j := 0; j < n-i-1; j++ {
if arr[j] > arr[j+1] {
arr[j], arr[j+1] = arr[j+1], arr[j]
}
}
}
}
func main() {
arr := []int{64, 34, 25, 12, 22, 11, 90}
bubbleSort(arr)
fmt.Println("Sorted array is:", arr)
}
```
from openai import OpenAI
from foundry_local import FoundryLocalManager
model = "qwen2.5-coder-0.5b"
manager = FoundryLocalManager(model)
openai_client = OpenAI(
base_url=manager.endpoint,
api_key=manager.api_key,
)
def talk(query):
messages = [
{
"role": "system",
"content": "You are a helpful expert golang developer assistant. Your users are asking questions about golang code And Response must have only code and not additional information."
},
{
"role": "assistant",
"content": "Response must have only golang source code and not additional information."
},
{"role": "user", "content": f"Question: {query}"}
]
response = openai_client.chat.completions.create(
model=manager.get_model_info(model).id,
messages=messages,
max_tokens=512,
)
content = response.choices[0].message.content
return content
if __name__ == "__main__":
query = "Generate code for bubble sort"
answer = talk(query)
print(answer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment