You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
985 B
46 lines
985 B
import os
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
from swarms import (
|
|
OpenAIChat,
|
|
Conversation,
|
|
)
|
|
|
|
conv = Conversation(
|
|
time_enabled=True,
|
|
)
|
|
|
|
# Load the environment variables
|
|
load_dotenv()
|
|
|
|
# Get the API key from the environment
|
|
api_key = os.environ.get("OPENAI_API_KEY")
|
|
|
|
# Initialize the language model
|
|
llm = OpenAIChat(openai_api_key=api_key, model_name="gpt-4")
|
|
|
|
|
|
# Run the language model in a loop
|
|
def interactive_conversation(llm):
|
|
conv = Conversation()
|
|
while True:
|
|
user_input = input("User: ")
|
|
conv.add("user", user_input)
|
|
if user_input.lower() == "quit":
|
|
break
|
|
task = (
|
|
conv.return_history_as_string()
|
|
) # Get the conversation history
|
|
out = llm(task)
|
|
conv.add("assistant", out)
|
|
print(
|
|
f"Assistant: {out}",
|
|
)
|
|
conv.display_conversation()
|
|
conv.export_conversation("conversation.txt")
|
|
|
|
|
|
# Replace with your LLM instance
|
|
interactive_conversation(llm)
|