gemma-sage / tests /test_api_local.py
neuralworm's picture
feat: Agentic Positive Prompting & Scenario Tests
058ae1e
from gradio_client import Client
import json
import os
client = Client("http://127.0.0.1:7860")
def test_chat():
print(">>> Testing Chat Greeting...")
res = client.predict(
message="Hallo",
history=[],
short_answers=False,
api_name="//chat"
)
# res is (chatbot_updated, history_updated)
print("Response received.")
print(f"Chatbot content: {res[0][-1]['content'][:100]}...")
def test_assistant_first():
print("\n>>> Testing Assistant-First History (Role Alternation Fix)...")
welcome_text = "Hello. I am Sage 6.5. I can consult the Oracle for you. Shall I do a reading for today, for a specific date, or do you have a specific topic? What is your name?"
history = [{"role": "assistant", "content": welcome_text}]
res = client.predict(
message="Mein Name ist Julian.",
history=history,
short_answers=False,
api_name="//chat"
)
# This should NOT crash and should return a response
print(f"Response: {res[0][-1]['content'][:100]}...")
if "TemplateError" in str(res):
print("!!! TEST FAILED: TemplateError detected.")
else:
print("✔ Test Passed: No role alternation crash.")
def test_export():
print("\n>>> Testing Export functionality...")
res = client.predict(api_name="/export_chat")
if res and res.endswith(".json"):
print(f"✔ Export successful: {res}")
else:
print("!!! Export failed.")
if __name__ == "__main__":
try:
test_chat()
test_assistant_first()
test_name_detection()
test_export()
except Exception as e:
print(f"!!! Error: {e}")