Delete test_.py
Browse files
test_.py
DELETED
|
@@ -1,60 +0,0 @@
|
|
| 1 |
-
import requests
|
| 2 |
-
from dotenv import load_dotenv
|
| 3 |
-
import os
|
| 4 |
-
import json
|
| 5 |
-
|
| 6 |
-
# Replace with your actual key
|
| 7 |
-
API_KEY = "key-7tuMkwH-5vxn9Jy4DkULrebJ1ojqfTYtBrNYp5qyveTKv5oGI"
|
| 8 |
-
DOMAIN_AGENT = "https://api.staging.ctxl.dev/v1"
|
| 9 |
-
|
| 10 |
-
# Function to generate responses using the API - exact copy
|
| 11 |
-
def generate(params: dict):
|
| 12 |
-
headers = {"authorization": f"Bearer {API_KEY}", "content-type": "application/json", "accept": "application/json"}
|
| 13 |
-
try:
|
| 14 |
-
r = requests.post(DOMAIN_AGENT + "/generate", json=params, headers=headers)
|
| 15 |
-
if r.status_code != 200:
|
| 16 |
-
print(f"API error status code: {r.status_code}")
|
| 17 |
-
print(f"API error response: {r.text[:200]}")
|
| 18 |
-
return {"error": f"API returned status code {r.status_code}"}
|
| 19 |
-
return r.json()
|
| 20 |
-
except Exception as e:
|
| 21 |
-
print(f"Exception in API call: {str(e)}")
|
| 22 |
-
return {"error": f"Exception: {str(e)}"}
|
| 23 |
-
|
| 24 |
-
# Function to call GLM internal_v4 model - exact copy
|
| 25 |
-
def call_glm_internal_v4(user_input):
|
| 26 |
-
params = {
|
| 27 |
-
"model": "internal_v4",
|
| 28 |
-
"messages": [{"role": "user", "content": user_input}],
|
| 29 |
-
"knowledge": [],
|
| 30 |
-
"avoid_commentary": True
|
| 31 |
-
}
|
| 32 |
-
print("Calling GLM internal_v4 model...")
|
| 33 |
-
result = generate(params)
|
| 34 |
-
if "error" in result:
|
| 35 |
-
return f"Error: {result['error']}"
|
| 36 |
-
elif "response" in result:
|
| 37 |
-
return result["response"]
|
| 38 |
-
else:
|
| 39 |
-
return f"Error: No response field in returned JSON."
|
| 40 |
-
|
| 41 |
-
# Test function
|
| 42 |
-
def test_api():
|
| 43 |
-
print(f"Using API key: {API_KEY[:4]}...{API_KEY[-4:]}")
|
| 44 |
-
print(f"API key length: {len(API_KEY)}")
|
| 45 |
-
|
| 46 |
-
test_input = "This is a test message"
|
| 47 |
-
print(f"Testing with input: '{test_input}'")
|
| 48 |
-
|
| 49 |
-
response = call_glm_internal_v4(test_input)
|
| 50 |
-
print(f"Response: {response}")
|
| 51 |
-
|
| 52 |
-
if not response.startswith("Error:"):
|
| 53 |
-
print("SUCCESS! API call worked.")
|
| 54 |
-
return True
|
| 55 |
-
else:
|
| 56 |
-
print("FAILED! API call returned an error.")
|
| 57 |
-
return False
|
| 58 |
-
|
| 59 |
-
# Run the test
|
| 60 |
-
test_api()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|