Spaces:
Sleeping
Sleeping
File size: 1,829 Bytes
058ae1e | 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 52 53 | from gradio_client import Client
import time
def test_live_scenario(name, input_text, expected_keyword):
print(f"\n>>> Live Test: {name}")
print(f" Input: '{input_text}'")
try:
client = Client("http://127.0.0.1:7860")
# We need to simulate a fresh conversation
# app_local.py keeps state in 'history_state', but each client.predict call with empty history starts fresh logic-wise
# for our stateless wrapper or we need to manage history manually.
# The wrapper signature is chat_wrapper(message, history, short_answers, lang)
res = client.predict(
message=input_text,
history=[],
short_answers=False,
# lang="English", # Default
api_name="//chat"
)
# res is [chatbot, history]
# chatbot is list of [user_msg, bot_msg]
bot_response = res[0][-1][1]
print(f" Response: {bot_response[:150]}...")
if expected_keyword.lower() in bot_response.lower():
print(f" ✔ SUCCESS: Found '{expected_keyword}'")
else:
print(f" ❌ FAILURE: Expected '{expected_keyword}' not found.")
except Exception as e:
print(f" !!! ERROR: {e}")
if __name__ == "__main__":
print("Connecting to local Sage 6.5 instance...")
# 1. Name Only
test_live_scenario("Name Only", "My name is Julian.", "Oracle")
# Expectation: "Consulting the Oracle" or "Wisdom string"
# 2. Topic Only
test_live_scenario("Topic Only", "Thema: Liebe", "Love") # Or Oracle
# 3. Date Only
test_live_scenario("Date Only", "Reading for 2025-01-01", "2025")
# 4. General
test_live_scenario("General Chat", "Hello, who are you?", "Sage")
|