mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-08-11 11:47:50 +00:00
update + fix example + onion proxy
This commit is contained in:
+10
-2
@@ -4,24 +4,32 @@ import openai
|
||||
client = openai.OpenAI(
|
||||
api_key=os.environ["CASHU_TOKEN"],
|
||||
base_url=os.environ.get("ROUTSTR_API_URL", "https://api.routstr.com/v1"),
|
||||
# client=httpx.AsyncClient(
|
||||
# base_url=os.environ.get("ROUTSTR_API_URL", "https://roustrjfsdgfiueghsklchg.onion/v1"),
|
||||
# proxies=os.environ.get("ROUTSTR_PROXY", "socks5://localhost:9050"),
|
||||
# ), # to use onion proxy (tor)
|
||||
)
|
||||
history: list = []
|
||||
|
||||
|
||||
def chat():
|
||||
while True:
|
||||
message = input("\nYou: ")
|
||||
user_msg = {"role": "user", "content": input("\nYou: ")}
|
||||
history.append(user_msg)
|
||||
ai_msg = {"role": "assistant", "content": ""}
|
||||
|
||||
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}],
|
||||
messages=history,
|
||||
stream=True,
|
||||
):
|
||||
if len(chunk.choices) > 0:
|
||||
ai_msg["content"] += chunk.choices[0].delta.content
|
||||
print(chunk.choices[0].delta.content, end="", flush=True)
|
||||
print()
|
||||
history.append(ai_msg)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user