Skip to content
Merged
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
19 changes: 19 additions & 0 deletions examples/structured-response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python
"""Example script demonstrating an interactive LLM chatbot."""

import json

import lmstudio as lm

class BookSchema(lm.BaseModel):
"""Structured information about a published book."""
title: str
author: str
year: int

model = lm.llm()

result = model.respond("Tell me about The Hobbit", response_format=BookSchema)
book = result.parsed

print(json.dumps(book, indent=2))
26 changes: 26 additions & 0 deletions examples/tool-use-multiple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env python
"""Example script demonstrating agent use of multiple tools."""

import math
import lmstudio as lm

def add(a: int, b: int) -> int:
"""Given two numbers a and b, returns the sum of them."""
return a + b

def is_prime(n: int) -> bool:
"""Given a number n, returns True if n is a prime number."""
if n < 2:
return False
sqrt = int(math.sqrt(n))
for i in range(2, sqrt):
if n % i == 0:
return False
return True

model = lm.llm("qwen2.5-7b-instruct")
model.act(
"Is the result of 12345 + 45668 a prime? Think step by step.",
[add, is_prime],
on_message=print,
)
15 changes: 15 additions & 0 deletions examples/tool-use.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python
"""Example script demonstrating agent tool use."""

import lmstudio as lm

def multiply(a: float, b: float) -> float:
"""Given two numbers a and b. Returns the product of them."""
return a * b

model = lm.llm("qwen2.5-7b-instruct")
model.act(
"What is the result of 12345 multiplied by 54321?",
[multiply],
on_message=print,
)