-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathinput-lmstudio.py
More file actions
49 lines (37 loc) · 1.53 KB
/
Copy pathinput-lmstudio.py
File metadata and controls
49 lines (37 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from openai import OpenAI
import os
from dotenv import load_dotenv
load_dotenv()
history = []
while True:
user_input = input("Your prompt or questions: ")
if user_input.lower() == "exit":
print("Exiting the program.")
break
history.append({"role": "user", "content": user_input})
api_url = "http://localhost:1234/v1"
token = "lm-studio"
model = "gemma-3-4b-it-qat"
client = OpenAI(api_key=token, base_url=api_url)
response = client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": "You are a helpful, friendly assistant."},
] + history
)
try:
response = client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": "You are a helpful, friendly assistant."},
] + history
)
content = response.choices[0].message.content
print("\nExtracted content:")
print(content)
history.append({"role": "assistant", "content": content})
except Exception as e:
print(f"Error occurred: {e}")
# Your prompt or questions: can you introduce yourself in a few sentences?
# Extracted content:
# Hello there! I’m Gemma, a large language model created by the team at Google DeepMind. I'm an open-weights model, which means I’m available for anyone to use and experiment with – and I’m here to help you with all sorts of tasks, from answering questions to generating creative text formats! 😊