-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_chat.py
More file actions
48 lines (39 loc) · 1.51 KB
/
Copy pathbasic_chat.py
File metadata and controls
48 lines (39 loc) · 1.51 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
"""
Basic Chat Example using LibreChat Python SDK
"""
import os
from dotenv import load_dotenv
from librechat_client import LibreChatClient
def main():
load_dotenv()
base_url = os.getenv("LIBRECHAT_BASE_URL", "https://spark.kinectrics.com")
refresh_token = os.getenv("LIBRECHAT_REFRESH_TOKEN")
connect_sid = os.getenv("LIBRECHAT_CONNECT_SID")
model = os.getenv("LIBRECHAT_MODEL", None) # e.g. "gpt-4o", "claude-3-5-sonnet", or None
agent_id = os.getenv("LIBRECHAT_AGENT_ID", None)
if not refresh_token or refresh_token == "YOUR_REFRESH_TOKEN_HERE":
print("[!] Please configure LIBRECHAT_REFRESH_TOKEN in your .env file.")
return
# Initialize client with optional default model and agent_id
client = LibreChatClient(
base_url=base_url,
refresh_token=refresh_token,
connect_sid=connect_sid,
default_model=model,
default_agent_id=agent_id
)
print("[+] Sending test request to LibreChat Agent API...")
# 1. Send message to Agent endpoint (/api/agents/chat/agents)
response = client.send_agent_message(
prompt="Explain the difference between GitOps and traditional CI/CD in 2 concise sentences.",
model=model,
agent_id=agent_id
)
print("\n=== LibreChat Response ===")
if isinstance(response, dict):
text_output = response.get("text") or response.get("raw") or str(response)
print(text_output)
else:
print(response)
if __name__ == "__main__":
main()