Further enhance and add in advanced meta-awareness with also an advanced command-line…
- User
Further enhance and add in advanced meta-awareness with also an advanced command-line gui and name it into; "Talk to a Catgirl." (it sounds a bit degenerate but yeah.)
codeimport g4f from langchain.prompts import PromptTemplate from langchain.chains import LLMChain # Define your provider (you can change the provider here) provider = g4f.Provider.HuggingFace # Memory to store past conversations conversation_memory = [] # Function to get a response from GPT def get_gpt_response(messages): try: # Send the conversation history to the provider response = g4f.chat.completions.create( messages=messages, model=g4f.models.default, # Use default model or specify ) # Extract the GPT response and return gpt_response = response.choices[0].message.content return gpt_response except Exception as e: return f"An error occurred: {e}" # Incorporating Langchain for advanced chatbot logic template = PromptTemplate.from_template("User says: {user_input}") chain = LLMChain( llm=get_gpt_response, # Using GPT4free as the LLM prompt=template ) # Function to maintain conversation history and context def update_conversation(role, content): conversation_memory.append({"role": role, "content": content}) # Example interaction with memory and context awareness def chatbot_interaction(user_input): # Add the user input to the conversation history update_conversation("user", user_input) # Prepare messages for the conversation, including memory messages = [{"role": msg["role"], "content": msg["content"]} for msg in conversation_memory] # Get response using GPT4free and Langchain response = chain.run(user_input=user_input) # Output the bot's response print(f"Bot: {response}") # Add the bot's response to the conversation memory update_conversation("assistant", response) # Example usage: while True: user_input = input("User: ") if user_input.lower() == "quit": break chatbot_interaction(user_input) - Assistant