| import sys | |
| import os | |
| sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) | |
| from backend.app.reasoning import reasoning_engine | |
| def test_engine(): | |
| print("Testing ReasoningEngine with Hugging Face...") | |
| print(f"Model: {reasoning_engine.model}") | |
| try: | |
| start = time.time() | |
| answer = reasoning_engine.generate_answer( | |
| "What is the capital of France?", | |
| ["France is a country in Europe. Its capital is Paris."], | |
| [] | |
| ) | |
| print("Answer generated:") | |
| print(answer) | |
| print(f"Time: {time.time() - start:.2f}s") | |
| except Exception as e: | |
| with open("verify.log", "w") as f: | |
| f.write(f"FAILED with Llama 3: {e}\n") | |
| print("\nTesting with public model (gpt2)...") | |
| try: | |
| from huggingface_hub import InferenceClient | |
| from backend.app.config import config | |
| client = InferenceClient(token=config.HUGGINGFACE_API_KEY) | |
| res = client.text_generation("Hello", model="gpt2", max_new_tokens=10) | |
| msg = f"GPT2 Success: {res}\nDiagnosis: Token is valid, but Llama 3 access is denied (403)." | |
| print(msg) | |
| f.write(msg) | |
| except Exception as e2: | |
| msg = f"GPT2 Failed: {e2}\nDiagnosis: Token is invalid or has no inference permissions." | |
| print(msg) | |
| f.write(msg) | |
| import time | |
| if __name__ == "__main__": | |
| test_engine() | |