forked from HeyChriss/SumAI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
86 lines (69 loc) · 3.13 KB
/
test.py
File metadata and controls
86 lines (69 loc) · 3.13 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Test the integration
import os
import logging
import asyncio
from typing import Dict, List, Callable
from uuid import uuid4
from dotenv import load_dotenv
from stream_handler import StreamingCallbackHandler
from langchain_openai import ChatOpenAI
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage
from langchain.memory import ConversationBufferMemory
from langchain.chains import ConversationChain
from web_crawler import scrape_and_crawl_website
from open_ai_modules import ChromeExtensionAssistant
if __name__ == "__main__":
import asyncio
# Configure logging
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
# Create an instance of the assistant
assistant = ChromeExtensionAssistant()
# Sample websites for testing
websites = [
"https://heychriss.com/",
"https://www.anthropic.com/",
"https://docs.anthropic.com/",
]
async def test_assistant():
print("\n🚀 Testing the Chrome extension assistant with multiple websites...")
# Initialize with the first website
result = await assistant.create_or_update_thread(websites[0])
if "error" in result:
print("❌ Error:", result["error"])
return
thread_id = result["thread_id"]
print(f"✅ Created thread: {thread_id} for {websites[0]}\n")
# Function to handle streaming tokens
def handle_token(token: str) -> None:
print(token, end="", flush=True)
# Chat with the assistant on the first website
print(f"\n💬 Now chatting about {websites[0]}")
user_input = input("\nYou: ")
print("Assistant: ", end="", flush=True)
assistant.chat_stream(thread_id, user_input, handle_token)
# Navigate to the second website (using the same thread)
print(f"\n\n🌐 Navigating to {websites[1]}...")
result = await assistant.create_or_update_thread(websites[1])
if "error" in result:
print("❌ Error:", result["error"])
return
print(f"✅ Updated thread with new website content\n")
# Chat with the assistant on the second website
print(f"\n💬 Now chatting about {websites[1]}")
user_input = input("\nYou: ")
print("Assistant: ", end="", flush=True)
assistant.chat_stream(thread_id, user_input, handle_token)
# Navigate to the third website (using the same thread)
print(f"\n\n🌐 Navigating to {websites[2]}...")
result = await assistant.create_or_update_thread(websites[2])
if "error" in result:
print("❌ Error:", result["error"])
return
print(f"✅ Updated thread with new website content\n")
# Chat with the assistant on the third website
print(f"\n💬 Now chatting about {websites[2]}")
user_input = input("\nYou: ")
print("Assistant: ", end="", flush=True)
assistant.chat_stream(thread_id, user_input, handle_token)
print("\n\n✨ Testing complete!")
asyncio.run(test_assistant())