From 0e37fd1b1f9114421483651499203c10ea6bb803 Mon Sep 17 00:00:00 2001 From: Shroominic Date: Thu, 24 Apr 2025 11:39:37 +0800 Subject: [PATCH] simple example --- example.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 example.py diff --git a/example.py b/example.py new file mode 100644 index 00000000..e4bf2c03 --- /dev/null +++ b/example.py @@ -0,0 +1,28 @@ +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()