Skip to content

Commit b3ab3e9

Browse files
authored
Added Ollama osmosis structure (#92)
* ollama osmosis structure * format
1 parent 36ae572 commit b3ab3e9

File tree

4 files changed

+128
-0
lines changed

4 files changed

+128
-0
lines changed

ollama/.beamignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Generated by Beam SDK
2+
.beamignore
3+
pyproject.toml
4+
.git
5+
.idea
6+
.python-version
7+
.vscode
8+
.venv
9+
venv
10+
__pycache__
11+
.DS_Store
12+
.config
13+
drive/MyDrive
14+
.coverage
15+
.pytest_cache
16+
.ipynb
17+
.ruff_cache
18+
.dockerignore
19+
.ipynb_checkpoints
20+
.env.local
21+
.envrc
22+
**/__pycache__/
23+
**/.pytest_cache/
24+
**/node_modules/
25+
**/.venv/
26+
*.pyc
27+
.next/
28+
.circleci

ollama/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Ollama Osmosis-Structure-0.6B
2+
3+
1. Install [Beam](https://beam.cloud) on your computer
4+
2. Clone this repo
5+
3. Deploy the Osmosis-Structure-0.6B: `beam deploy app.py:generate`
6+
7+
Once deployed, you can access the API through your browser, or via API. `test.py` shows an example API call to the Osmosis-Structure-0.6B model.

ollama/app.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from beam import endpoint, Image
2+
from pydantic import BaseModel
3+
4+
5+
class Answer(BaseModel):
6+
json: dict
7+
8+
9+
image = (
10+
Image(python_version="python3.11")
11+
.add_python_packages(
12+
[
13+
"git+https://github.com/huggingface/transformers",
14+
"numpy<2",
15+
"fastapi[standard]==0.115.4",
16+
"pydantic==2.9.2",
17+
"starlette==0.41.2",
18+
"torch==2.4.0",
19+
"ollama",
20+
]
21+
)
22+
.add_commands(
23+
[
24+
"curl -fsSL https://ollama.com/install.sh | sh",
25+
]
26+
)
27+
)
28+
29+
30+
def load_model():
31+
import subprocess
32+
import time
33+
34+
subprocess.Popen(["ollama", "serve"])
35+
time.sleep(5)
36+
subprocess.run(["ollama", "pull", "Osmosis/Osmosis-Structure-0.6B"], check=True)
37+
38+
39+
@endpoint(
40+
name="ollamap-osmosis-structure",
41+
image=image,
42+
cpu=12,
43+
memory="32Gi",
44+
gpu="A10G",
45+
on_start=load_model,
46+
)
47+
def generate(**inputs):
48+
from ollama import chat
49+
50+
messages = inputs.get("messages", "")
51+
52+
response = chat(
53+
messages=messages,
54+
model="Osmosis/Osmosis-Structure-0.6B",
55+
format=Answer.model_json_schema(),
56+
)
57+
58+
answer = Answer.model_validate_json(response.message.content)
59+
print(answer)
60+
return {"answer": answer.json}

ollama/test.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import requests
2+
3+
AUTH_TOKEN = "YOUR_BEAM_AUTH_TOKEN" # Replace with your actual Beam auth token
4+
5+
url = "https://78f2e172-6ae5-4cef-b43a-9823238f.app.beam.cloud"
6+
7+
headers = {
8+
"Connection": "keep-alive",
9+
"Content-Type": "application/json",
10+
"Authorization": f"Bearer {AUTH_TOKEN}",
11+
}
12+
13+
reasoning_trace = """
14+
Product ID: P-001
15+
Product Name: Wireless Ergonomic Mouse
16+
Price: $29.99
17+
In Stock: Yes
18+
Features: Adjustable DPI, Rechargeable Battery, Silent Clicks
19+
Compatible OS: Windows, macOS, Linux
20+
"""
21+
22+
data = {
23+
"messages": [
24+
{
25+
"role": "system",
26+
"content": "You are a helpful assistant that understands and translates text to JSON format",
27+
},
28+
{"role": "user", "content": reasoning_trace},
29+
]
30+
}
31+
32+
response = requests.post(url, headers=headers, json=data)
33+
print(response.text)

0 commit comments

Comments
 (0)