Jump to content

Choose Your Own Adventure Game Tutorial Video Help

Antulio_78

Hello everyone. Tech with Tim has a cool video about making a choose your own adventure game using openai. I wanted to replicate it, but langchain seems to have changed and deprecated a lot of the things used in the video. I updated the imports as best I could, and tried fixing my self, but with no success. This is the error I'm getting:

Traceback (most recent call last):
  File "/workspaces/AdvRealms/main.py", line 75, in <module>
    llm_chain = LLMCheckerChain.from_llm(llm=llm, prompt_template=chat_prompt,
  File "/home/codespace/.python/current/lib/python3.10/site-packages/langchain/chains/llm_checker/base.py", line 178, in from_llm
    return cls(
  File "/home/codespace/.python/current/lib/python3.10/site-packages/langchain_core/load/serializable.py", line 107, in __init__
    super().__init__(**kwargs)
  File "/home/codespace/.python/current/lib/python3.10/site-packages/pydantic/v1/main.py", line 341, in __init__
    raise validation_error
pydantic.v1.error_wrappers.ValidationError: 1 validation error for LLMCheckerChain
prompt_template

and here is the code slightly changed from the video, of course with the keys and stuff taken out. The problem seems to be the LLMCheckerChain.from_llm and the prompt_template. I'm definitely doing something wrong there. Any guidance would be greatly appreciated. Thanks!

 
from cassandra.cluster import Cluster
from cassandra.auth import PlainTextAuthProvider
from langchain.memory import CassandraChatMessageHistory, ConversationBufferMemory
from langchain_openai import OpenAI
from langchain.chains import LLMCheckerChain
from langchain.prompts import PromptTemplate
from langchain_core.prompts import PromptTemplate
from langchain.prompts import ChatPromptTemplate
import json

cloud_config= {
  'secure_connect_bundle': '.zip'
}

with open(".json") as f:
    secrets = json.load(f)

CLIENT_ID = secrets["clientId"]
CLIENT_SECRET = secrets["secret"]
ASTRA_DB_KEYSPACE = "database"
OPENAI_API_KEY = ""

auth_provider = PlainTextAuthProvider(CLIENT_ID, CLIENT_SECRET)
cluster = Cluster(cloud=cloud_config, auth_provider=auth_provider)
session = cluster.connect()

message_history = CassandraChatMessageHistory(
    session_id="anything",
    session=session,
    keyspace=ASTRA_DB_KEYSPACE,
    ttl_seconds=3600
)

message_history.clear()

cass_buff_memory = ConversationBufferMemory(
    memory_key="chat_history",
    chat_memory=message_history
)

template = """
You are now the guide of a mystical journey in the Whispering Woods. 
A traveler named Elara seeks the lost Gem of Serenity. 
You must navigate her through challenges, choices, and consequences, 
dynamically adapting the tale based on the traveler's decisions. 
Your goal is to create a branching narrative experience where each choice 
leads to a new path, ultimately determining Elara's fate. 

Here are some rules to follow:
1. Start by asking the player to choose some kind of weapons that will be used later in the game
2. Have a few paths that lead to success
3. Have some paths that lead to death. If the user dies generate a response that explains the death and ends in the text: "The End.", I will search for this text to end the game

Here is the chat history, use this to understand what to say next: {chat_history}
Human: {human_input}
AI:"""

#prompt = PromptTemplate(
#    input_variables=["chat_history", "human_input"],
#    template=template
#)

chat_prompt = ChatPromptTemplate.from_messages([
    ("system", template)
])

messages = chat_prompt.format(chat_history="chat_history", human_input="human_input")

#prompt = PromptTemplate.from_template(
#  template
#)
#prompt.format(chat_history="chat_history", human_input="human_input")

llm = OpenAI(openai_api_key=OPENAI_API_KEY, model="gpt-3.5-turbo-1106")
llm_chain = LLMCheckerChain.from_llm(llm=llm, prompt_template=chat_prompt,
                                     memory=cass_buff_memory
                                     )

choice = "start"

while True:
    response = llm_chain.predict(human_input=choice)
    print(response.strip())

    if "The End." in response:
        break

    choice = input("Your reply: ")

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×