Got this error when i restart: Traceback (most recent call last): File…
- User
Got this error when i restart: Traceback (most recent call last): File "C:\Users\BARATHI\Documents\unnamed\test.py", line 77, in first_ai_response = bot.chat(first_prompt, conversationId="3384baf3-e6fa-41b5-ade7-33349d415472")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\BARATHI\Documents\unnamed\test.py", line 59, in chat ai_response = response[0][self.chat_counter][1] ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^ IndexError: list index out of rangeCurrent code:
from gradio_client import Client import uuid import sqlite3
class ChatBot: def init(self, model_name: str): self.client = Client(model_name) self.db_connection = sqlite3.connect('conversations.db') self.create_table() self.chatbot = [] self.chat_counter = 0 self.conversation_id = None
def create_table(self): with self.db_connection: self.db_connection.execute(''' CREATE TABLE IF NOT EXISTS conversations ( id TEXT, prompt TEXT, response TEXT, PRIMARY KEY (id, prompt) ) ''') def reset_textbox(self): self.client.predict(api_name="/reset_textbox") def save_conversation(self, conversation_id: str, prompt: str, response: str): with self.db_connection: try: self.db_connection.execute(''' INSERT INTO conversations (id, prompt, response) VALUES (?, ?, ?) ''', (conversation_id, prompt, response)) except sqlite3.IntegrityError: pass def chat(self, prompt: str, conversationId: str = None): if conversationId is not None: self.conversation_id = conversationId self.chatbot = self.load_conversation(conversationId) self.chat_counter = len(self.chatbot) else: self.reset_textbox() self.conversation_id = str(uuid.uuid4()) self.chatbot = [] self.chat_counter = 0 inputs = { 'inputs': prompt, 'top_p': 1, 'temperature': 1, 'chat_counter': self.chat_counter, 'chatbot': self.chatbot, 'api_name': "/predict" } response = self.client.predict(**inputs) ai_response = response[0][self.chat_counter][1] self.chatbot.append([prompt, ai_response]) self.save_conversation(self.conversation_id, prompt, ai_response) return ai_response, self.conversation_id def load_conversation(self, conversation_id: str): with self.db_connection: cursor = self.db_connection.execute(''' SELECT prompt, response FROM conversations WHERE id = ? ''', (conversation_id,)) return cursor.fetchall()if name == "main": bot = ChatBot("yuntian-deng/ChatGPT4")
first_prompt = "So what is my name?" first_ai_response = bot.chat(first_prompt, conversationId="3384baf3-e6fa-41b5-ade7-33349d415472") # first_ai_response, conversation_id = bot.chat(first_prompt) print(f"AI: {first_ai_response} (Conversation ID: 3384baf3-e6fa-41b5-ade7-33349d415472)") # second_prompt = "My name is icmecodes. Do you think it's cool?" # second_ai_response, _ = bot.chat(second_prompt, conversationId=conversation_id) # continue conversation # print(f"AI: {second_ai_response}") # third_prompt = "Whats my name?" # third_ai_response, _ = bot.chat(third_prompt, conversationId=conversation_id) # continue conversation # print(f"AI: {third_ai_response}") # fourth_prompt = "Is that a cool name?" # fourth_ai_response, _ = bot.chat(fourth_prompt, conversationId=conversation_id) # continue conversation # print(f"AI: {fourth_ai_response}") - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.