Files
routstr-core/example.py
T
2025-04-24 11:39:37 +08:00

29 lines
708 B
Python

import os
import openai
client = openai.OpenAI(
api_key=os.environ["CASHU_TOKEN"],
base_url=os.environ.get("ROUTSTR_API_URL", "https://api.routstr.com/v1"),
)
history: list = []
def chat():
while True:
message = input("\nYou: ")
for chunk in client.chat.completions.create(
model=os.environ.get(
"MODEL", "meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8"
),
messages=history + [{"role": "user", "content": message}],
stream=True,
):
if len(chunk.choices) > 0:
print(chunk.choices[0].delta.content, end="", flush=True)
print()
if __name__ == "__main__":
chat()