-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_sambanova.py
More file actions
51 lines (42 loc) · 1.62 KB
/
Copy pathtest_sambanova.py
File metadata and controls
51 lines (42 loc) · 1.62 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
49
50
51
import os
import requests
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
# Get API key from environment
api_key = os.getenv("SAMBANOVA_API_KEY")
if not api_key:
raise ValueError("SAMBANOVA_API_KEY environment variable not set")
# SambaNova API settings
api_url = "https://api.sambanova.ai/v1/chat/completions"
model = "DeepSeek-R1" # The model you're using for complex queries
# Sample messages
messages = [
{"role": "system", "content": "You are a helpful assistant who answers database queries."},
{
"role": "user",
"content": "Analyze the profit trends across different customer segments over the last 12 months and identify the top performing cohorts.",
},
]
# API request payload
payload = {"model": model, "messages": messages, "temperature": 0.0, "max_tokens": 512}
# Headers
headers = {"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"}
# Make the API request
print(f"Testing SambaNova API with model: {model}")
print(f"Request payload: {payload}")
print("Sending request...")
try:
response = requests.post(api_url, headers=headers, json=payload)
# Check response
if response.status_code == 200:
result = response.json()
print("\nAPI call successful!")
print("\nResponse:")
print(f"Status code: {response.status_code}")
print(f"Generated text: {result['choices'][0]['message']['content'][:200]}...")
else:
print(f"\nAPI call failed with status code: {response.status_code}")
print(f"Error message: {response.text}")
except Exception as e:
print(f"\nException occurred: {str(e)}")