Spaces:
Sleeping
Sleeping
Atishay Jain commited on
Commit ·
1e6d041
1
Parent(s): 025f14a
llms working
Browse files- test_llm.py +39 -0
test_llm.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from openai import OpenAI
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
def main():
|
| 6 |
+
api_base_url = os.getenv("API_BASE_URL")
|
| 7 |
+
model_name = os.getenv("MODEL_NAME")
|
| 8 |
+
hf_token = os.getenv("HF_TOKEN")
|
| 9 |
+
|
| 10 |
+
if not api_base_url or not model_name or not hf_token:
|
| 11 |
+
print("ERROR: Missing one or more environment variables. Ensure API_BASE_URL, MODEL_NAME, and HF_TOKEN are set.")
|
| 12 |
+
sys.exit(1)
|
| 13 |
+
|
| 14 |
+
print("Status: Environment variables confirmed securely retrieved.")
|
| 15 |
+
|
| 16 |
+
try:
|
| 17 |
+
client = OpenAI(
|
| 18 |
+
base_url=api_base_url,
|
| 19 |
+
api_key=hf_token
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
print(f"Testing connectivity to model: {model_name}...")
|
| 23 |
+
|
| 24 |
+
response = client.chat.completions.create(
|
| 25 |
+
model=model_name,
|
| 26 |
+
messages=[{"role": "user", "content": "Say hello in one sentence."}],
|
| 27 |
+
max_tokens=20
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
print("\n=== Model Response ===")
|
| 31 |
+
print(response.choices[0].message.content.strip())
|
| 32 |
+
print("======================\n")
|
| 33 |
+
print("Success: Connectivity verified securely.")
|
| 34 |
+
|
| 35 |
+
except Exception as e:
|
| 36 |
+
print(f"Error encountered during API call: {e}")
|
| 37 |
+
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
main()
|