File tree Expand file tree Collapse file tree 3 files changed +60
-0
lines changed Expand file tree Collapse file tree 3 files changed +60
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ """Example script demonstrating an interactive LLM chatbot."""
3
+
4
+ import json
5
+
6
+ import lmstudio as lm
7
+
8
+ class BookSchema (lm .BaseModel ):
9
+ """Structured information about a published book."""
10
+ title : str
11
+ author : str
12
+ year : int
13
+
14
+ model = lm .llm ()
15
+
16
+ result = model .respond ("Tell me about The Hobbit" , response_format = BookSchema )
17
+ book = result .parsed
18
+
19
+ print (json .dumps (book , indent = 2 ))
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ """Example script demonstrating agent use of multiple tools."""
3
+
4
+ import math
5
+ import lmstudio as lm
6
+
7
+ def add (a : int , b : int ) -> int :
8
+ """Given two numbers a and b, returns the sum of them."""
9
+ return a + b
10
+
11
+ def is_prime (n : int ) -> bool :
12
+ """Given a number n, returns True if n is a prime number."""
13
+ if n < 2 :
14
+ return False
15
+ sqrt = int (math .sqrt (n ))
16
+ for i in range (2 , sqrt ):
17
+ if n % i == 0 :
18
+ return False
19
+ return True
20
+
21
+ model = lm .llm ("qwen2.5-7b-instruct" )
22
+ model .act (
23
+ "Is the result of 12345 + 45668 a prime? Think step by step." ,
24
+ [add , is_prime ],
25
+ on_message = print ,
26
+ )
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python
2
+ """Example script demonstrating agent tool use."""
3
+
4
+ import lmstudio as lm
5
+
6
+ def multiply (a : float , b : float ) -> float :
7
+ """Given two numbers a and b. Returns the product of them."""
8
+ return a * b
9
+
10
+ model = lm .llm ("qwen2.5-7b-instruct" )
11
+ model .act (
12
+ "What is the result of 12345 multiplied by 54321?" ,
13
+ [multiply ],
14
+ on_message = print ,
15
+ )
You can’t perform that action at this time.
0 commit comments