# Define a dictionary of intents and responses intents = { 'greeting': { 'patterns': ['hello', 'hi', 'hey'], 'responses': ['Hi there!', 'Hello!', 'Hey, how\'s it going?'] }, 'goodbye': { 'patterns': ['bye', 'see you later', 'goodbye'], 'responses': ['See you later!', 'Bye for now!', 'Have a great day!'] }, 'thanks': { 'patterns': ['thanks', 'thank you', 'appreciate it'], 'responses': ['You\'re welcome!', 'No problem!', 'Glad I could help!'] } }
def get_response(intent): """Get a response for the matched intent""" if intent is not None: return random.choice(intents[intent]['responses']) else: return 'I didn\'t quite understand that. Can you try again?' Character AI Bot Script
def main(): print('Welcome to the character AI bot!') while True: user_input = input('User: ') intent = match_intent(user_input) response = get_response(intent) print('Bot:', response) if intent == 'goodbye': break # Define a dictionary of intents and responses
def match_intent(message): """Match the user's message to a predefined intent""" for intent, data in intents.items(): for pattern in data['patterns']: if pattern in message.lower(): return intent return None Script import random
Overview This script provides a basic implementation of a character AI bot that can engage in conversations with users. The bot uses a simple text-based interface and responds to user input based on a predefined set of intents and responses. Script import random