diff --git a/README.md b/README.md index 0041eb8..7a825dc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # DualMind: AI Conversation Simulator -DualMind is an innovative AI conversation simulator that facilitates engaging dialogues between two AI models using the Ollama API. It offers both a command-line interface (CLI) and a Streamlit-based web interface for immersive and customizable AI interactions. +DualMind is an innovative AI conversation simulator that facilitates engaging dialogues between two AI models using the Ollama API. It offers a command-line interface (CLI) for immersive and customizable AI interactions.  @@ -8,15 +8,13 @@ DualMind is an innovative AI conversation simulator that facilitates engaging di - 🤖 Dual-model conversation: Engage two different AI models in a thought-provoking dialogue - 🎭 Customizable system prompts: Tailor the behavior and personality of each AI model -- 🖥️ Multiple interface options: - - Command-line interface for quick interactions - - Streamlit web interface for a user-friendly experience +- 🖥️ Command-line interface for quick interactions - 🛠️ Conversation customization: - Adjust the number of exchanges - Modify the initial prompt - Select different AI models -- 💾 Save and download conversation logs -- 🎨 Responsive and visually appealing design +- 💾 Save conversation logs +- 🔢 Token count display and limit: Monitor the token usage for each message and limit the conversation to a specified number of tokens. ## Prerequisite: Ollama @@ -46,6 +44,7 @@ Please refer to [Ollama](https://ollama.com/download) to install Ollama on your MODEL_1=llama2 MODEL_2=mistral INITIAL_PROMPT="Let's discuss the future of AI. What are your thoughts on its potential impact on society?" + MAX_TOKENS=8000 ``` Feel free to use the env.example file as a template. @@ -54,42 +53,29 @@ Please refer to [Ollama](https://ollama.com/download) to install Ollama on your ## Usage -### Command-line Interface - To run DualMind in CLI mode: ```sh ./run_cli.sh ``` -### Streamlit Web Interface - -To run DualMind in Streamlit mode: - -```sh -./run_streamlit.sh -``` - -Then, open your web browser and navigate to the URL provided in the terminal (usually `http://localhost:8501`). - ## Customization ### System Prompts You can customize the system prompts for each AI model by editing the `system_prompt_1.txt` and `system_prompt_2.txt` files in the project root. -### Styling +### Options + +You can customize the options for the conversation by editing the `options.json` file in the project root. -The appearance of the Streamlit interface can be customized by modifying the `style/custom.css` file. ## Project Structure - `main.py`: Entry point of the application - `ai_conversation.py`: Core logic for AI conversations -- `streamlit_app.py`: Streamlit web interface implementation -- `style/custom.css`: Custom styles for the web interface - `run_cli.sh`: Shell script to run the CLI version -- `run_streamlit.sh`: Shell script to run the Streamlit version + ## Contributing @@ -102,4 +88,3 @@ This project is open source and available under the [MIT License](LICENSE). ## Acknowledgements - This project uses the [Ollama](https://ollama.ai/) API for AI model interactions. -- The web interface is built with [Streamlit](https://streamlit.io/). diff --git a/ai_conversation.py b/ai_conversation.py index f25b96a..16b9cc5 100644 --- a/ai_conversation.py +++ b/ai_conversation.py @@ -11,7 +11,7 @@ class AIConversation: system_prompt_1, system_prompt_2, ollama_endpoint, - max_tokens=4000, + max_tokens=4000, ): # Initialize conversation parameters and Ollama client self.model_1 = model_1 @@ -41,7 +41,7 @@ class AIConversation: break # Avoid removing the system message return messages - def start_conversation(self, initial_message, num_exchanges=0): + def start_conversation(self, initial_message, num_exchanges=0, options=None): # Main conversation loop current_message = initial_message color_1, color_2 = "cyan", "yellow" @@ -78,10 +78,7 @@ class AIConversation: response = self.client.chat( model=self.current_model, messages=messages, - options={ - "temperature": 0.7, # Control randomness - "repeat_penalty": 1.2, # Penalize repetition - }, + options=options, ) response_content = response["message"]["content"] diff --git a/main.py b/main.py index e1b81fc..6a3bfe7 100644 --- a/main.py +++ b/main.py @@ -1,5 +1,5 @@ import os -import argparse +import json from dotenv import load_dotenv, set_key from ai_conversation import AIConversation @@ -8,6 +8,11 @@ def load_system_prompt(filename): with open(filename, "r") as file: return file.read().strip() +def load_options_from_json(filename): + """Load options from a JSON file.""" + with open(filename, "r") as file: + return json.load(file) + def main(): # Load environment variables load_dotenv() @@ -25,38 +30,24 @@ def main(): max_tokens = int(os.getenv("MAX_TOKENS", 4000)) print(f"Max tokens: {max_tokens}") + # Load options from JSON file + options = load_options_from_json("options.json") + print(f"Options: {options}") + # Initialize the AI conversation object conversation = AIConversation( model_1, model_2, system_prompt_1, system_prompt_2, ollama_endpoint, max_tokens ) - # Set up command-line argument parser - parser = argparse.ArgumentParser(description="AI Conversation") - parser.add_argument("--cli", action="store_true", help="Run in CLI mode") - parser.add_argument( - "--streamlit", action="store_true", help="Run in Streamlit mode" - ) - args = parser.parse_args() # Run the appropriate interface based on command-line arguments - if args.cli: - run_cli(conversation, initial_prompt) - elif args.streamlit: - run_streamlit(conversation, initial_prompt) - else: - print("Please specify either --cli or --streamlit mode.") + run_cli(conversation, initial_prompt, options) -def run_cli(conversation, initial_prompt): +def run_cli(conversation, initial_prompt, options): """Run the conversation in command-line interface mode.""" load_dotenv() - conversation.start_conversation(initial_prompt, num_exchanges=0) + conversation.start_conversation(initial_prompt, num_exchanges=0, options=options) -def run_streamlit(conversation, initial_prompt): - """Run the conversation in Streamlit interface mode.""" - import streamlit as st - from streamlit_app import streamlit_interface - - streamlit_interface(conversation, initial_prompt) if __name__ == "__main__": main() diff --git a/options.json b/options.json new file mode 100644 index 0000000..a408d37 --- /dev/null +++ b/options.json @@ -0,0 +1,8 @@ +{ + "temperature": 0.8, + "top_k": 40, + "top_p": 0.9, + "repeat_penalty": 1.1, + "presence_penalty": 0.5, + "frequency_penalty": 0.5 + } \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 4abe148..fa64992 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ python-dotenv requests termcolor -streamlit Pillow -tiktoken \ No newline at end of file +tiktoken +ollama \ No newline at end of file diff --git a/start_gui.sh b/start_gui.sh deleted file mode 100755 index 2decbfb..0000000 --- a/start_gui.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -streamlit run main.py -- --streamlit diff --git a/streamlit_app.py b/streamlit_app.py deleted file mode 100644 index 80ca962..0000000 --- a/streamlit_app.py +++ /dev/null @@ -1,246 +0,0 @@ -import streamlit as st -import os -import datetime -from dotenv import load_dotenv - - -# Function to load and apply custom CSS -def load_css(file_name): - with open(file_name, "r") as f: - st.markdown(f"", unsafe_allow_html=True) - - -# Function to set page configuration -def set_page_config(): - st.set_page_config( - page_title="DualMind", - page_icon="🤖", - layout="wide", - initial_sidebar_state="expanded", - ) - - -def streamlit_interface(conversation, initial_prompt): - set_page_config() - load_css("style/custom.css") - - st.markdown( - '