mirror of
https://github.com/zenlm/engine.git
synced 2026-10-30 15:00:05 +00:00
* Add model * Update loader * Fix llama config usage * Docs * Fix config no_rope_layers * Fix tie_word_embeddings default * Add chat template * Embed the chat templates * Fix embedding template * enable_thinking default true * Update examples * XML tools for smollm3 * Add smollm3 docs * Fix openai examples * Clippy --------- Co-authored-by: Eric Buehler <[email protected]>
29 lines
733 B
Python
29 lines
733 B
Python
import sys
|
|
from openai import OpenAI
|
|
|
|
client = OpenAI(api_key="foobar", base_url="http://localhost:1234/v1/")
|
|
|
|
messages = []
|
|
prompt = input("Enter system prompt >>> ")
|
|
if len(prompt) > 0:
|
|
messages.append({"role": "system", "content": prompt})
|
|
|
|
|
|
while True:
|
|
prompt = input(">>> ")
|
|
messages.append({"role": "user", "content": prompt})
|
|
resp = ""
|
|
response = client.chat.completions.create(
|
|
model="default",
|
|
messages=messages,
|
|
max_tokens=256,
|
|
stream=True,
|
|
)
|
|
for chunk in response:
|
|
delta = chunk.choices[0].delta.content
|
|
print(delta, end="")
|
|
sys.stdout.flush()
|
|
resp += delta
|
|
messages.append({"role": "assistant", "content": resp})
|
|
print()
|