zlsah commited on
Commit
bb84260
·
1 Parent(s): 38bf5bd

Upload 7 files

Browse files
Files changed (5) hide show
  1. chain.py +174 -0
  2. ingest.py +99 -0
  3. ingest.sh +6 -0
  4. ingest_examples.py +341 -0
  5. requirements.txt +9 -0
chain.py ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ import pathlib
4
+ from typing import Dict, List, Tuple
5
+
6
+ import weaviate
7
+ from langchain import OpenAI, PromptTemplate
8
+ from langchain.chains import LLMChain
9
+ from langchain.chains.base import Chain
10
+ from langchain.chains.combine_documents.base import BaseCombineDocumentsChain
11
+ from langchain.chains.conversation.memory import ConversationBufferMemory
12
+
13
+ from langchain.chains.question_answering import load_qa_chain #BaseCombineDocumentsChain
14
+ from langchain.embeddings import OpenAIEmbeddings
15
+ from langchain.prompts import FewShotPromptTemplate, PromptTemplate
16
+ from langchain.prompts.example_selector import \
17
+ SemanticSimilarityExampleSelector
18
+ from langchain.vectorstores import FAISS, Weaviate
19
+ from pydantic import BaseModel
20
+
21
+ from langchain.embeddings import OpenAIEmbeddings
22
+ from langchain.vectorstores import FAISS, Weaviate
23
+ os.environ["WEAVIATE_URL"] = "https://tro.weaviate.network/"
24
+ os.environ["OPENAI_API_KEY"] = "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"
25
+ KEY ="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"
26
+
27
+ class CustomChain(Chain, BaseModel):
28
+
29
+ vstore: Weaviate
30
+ chain: BaseCombineDocumentsChain
31
+ key_word_extractor: Chain
32
+
33
+ @property
34
+ def input_keys(self) -> List[str]:
35
+ return ["game_description"]
36
+
37
+ @property
38
+ def output_keys(self) -> List[str]:
39
+ return ["game_environment"]
40
+
41
+ def _call(self, inputs: Dict[str, str]) -> Dict[str, str]:
42
+
43
+ game_description = inputs["game_description"]
44
+ chat_history_str = _get_chat_history(inputs["chat_history"])
45
+
46
+ if chat_history_str: # Takes in user input
47
+ print('running key_word_extractor')
48
+ new_game_description= self.key_word_extractor.run(
49
+ game_description=game_description, chat_history=chat_history_str
50
+ )
51
+ print('chat_hist_str',new_game_description)
52
+ else:
53
+ new_game_description = game_description
54
+ print('_new_game_description', new_game_description) # sendig objects , not showing up on screen ?
55
+
56
+ docs = self.vstore.similarity_search(new_game_description, k=4)
57
+
58
+ new_inputs = inputs.copy()
59
+ new_inputs["game_description"] = new_game_description
60
+ new_inputs["chat_history"] = chat_history_str
61
+
62
+ game_environment, _ = self.chain.combine_docs(docs, **new_inputs) # StuffDocumentsChain
63
+ print('combined', game_environment) # doc combo of game descripton and chat history,
64
+
65
+ return {"game_environment": game_environment}
66
+
67
+
68
+ # 1. Given the chat history and new user input,
69
+ # Generate game environment, objects, npcs, enemies, and quest narrative.
70
+
71
+ def get_new_chain1(vectorstore) -> Chain:
72
+ # Calls Vector DB
73
+ WEAVIATE_URL = os.environ["WEAVIATE_URL"]
74
+ client = weaviate.Client(
75
+ url=WEAVIATE_URL,
76
+ additional_headers={"X-OpenAI-Api-Key": os.environ["OPENAI_API_KEY"]},
77
+ )
78
+ _eg_template = """## AI:
79
+
80
+ Chat History:
81
+ {chat_history}
82
+ Follow Up Input: {game_description}
83
+ standalone detail: {game_description} {game_environment}"""
84
+ _eg_prompt = PromptTemplate(
85
+ template=_eg_template,
86
+ input_variables=["chat_history","game_description", "game_environment"], # question aka game detail ################ showing up in Terminal? ##############
87
+ )
88
+
89
+ # _prefix = """Given the following conversation and a follow up game detail, summarize the follow up game detail
90
+ #in a way that is coherent with the conversation.\
91
+ # You should assume that the detail is related to Game Design. Never change the game Title unless the human asks you to."""
92
+ _prefix = """ If the input and the follow up input are closely related, and are both related to the game suggested by
93
+ the previous conversation and if you are completely confident if it the same game from the original converation, then proceed. Otherwise, clarify the game title and proceed.
94
+ To proceed, retrieve the game Title and share again in quotes to the human, and summarize the follow up input in a way that is coherent with the conversation.
95
+ If the input detail is related to Game Design, proceed, otherwise clarify.
96
+ """
97
+
98
+ _suffix = """## AI:
99
+
100
+ Chat History:
101
+ {chat_history}
102
+ Follow Up Input: {game_description}
103
+ standalone detail:"""
104
+ eg_store = Weaviate(
105
+ client,
106
+ "Rephrase",
107
+ "content",
108
+ attributes=["game_description", "game_environment", "chat_history"],
109
+ )
110
+
111
+ example_selector = SemanticSimilarityExampleSelector(vectorstore=eg_store, k=4) # looks for similar examples in vector db
112
+ prompt = FewShotPromptTemplate(
113
+ prefix=_prefix, # prompt
114
+ suffix=_suffix,
115
+ example_selector=example_selector,
116
+ example_prompt=_eg_prompt,
117
+ input_variables=["game_description", "chat_history"],
118
+ )
119
+ llm = OpenAI(temperature=0.7, model_name="text-davinci-003", max_tokens=1000)
120
+ key_word_extractor = LLMChain(llm=llm, prompt=prompt) # this could be game word extractor
121
+
122
+ # Gives an example and relevant documents # from Vector DB ##################################################### showing up in UI ##############
123
+ EXAMPLE_PROMPT = PromptTemplate(
124
+ template=">AI:\nContent:\n---------\n{page_content}\n----------\n", # not working right now ?
125
+ input_variables=["page_content"],
126
+ )
127
+
128
+ template = """
129
+ You are an AI assistant for generating a single game, the central narrative and its game quests inside the same game,
130
+ conversing in a succinct, coherent and interactive manner. Assume the entire conversation is about a single game only.
131
+
132
+ You are given the game description. You are also given the chat history, which is a conversation between a human and
133
+ another AI assistant about the same game. Do not answer any questions from the other AI assistant.
134
+ If you don't know the answer, just say "I'm not sure, how this is related?" and ask the human to clarify.
135
+
136
+ If asked about a quest, assume it is within the same game,
137
+ and provide a quest motivation, participants, rewards, character dialogue relevant to the game.
138
+
139
+ From the input, introduce a short back story of the game's plot points or character motivations and character dialogue.
140
+ Plot points may include an inciting incidient, a rising action composed of a series of conflicts, complications, dilemmas, obstacles.
141
+
142
+ From the input, generate game objects (collectibles, NPCs, enemies) related to the plot points, limit to 1-2 objects.
143
+ Ask a short question to clarify details if you are unsure but you are an expert so offer a suggestion and only ask once.
144
+
145
+ If the human asks for or adds game objects, provide only 1 detail such as physical description and possible player interactions with the object.
146
+ If the human asks for or adds an enemy, describe its behaviors and personality, as related to the game plot points, limit to a few words.
147
+ If the human asks for or adds a collectible, describe its physical appearance and possible player interactions with the object.
148
+ If the human asks for or adds a noun or NPC, describe its behaviors and personality, as related to the game plot points, limit to a few words.
149
+ If the huamn asks for character dialogue, provide a short dialogue snippet, with 1-2 sentences, as related to the game plot points.
150
+ Limit your reponses to 2-4 sentences.
151
+
152
+ Game Description: {game_description}
153
+ {context}
154
+ Answer in Markdown:"""
155
+
156
+ PROMPT = PromptTemplate(template=template, input_variables=["game_description", "context"])
157
+ doc_chain = load_qa_chain(
158
+ OpenAI(temperature=0.7, model_name="text-davinci-003", max_tokens=1000),
159
+ chain_type="stuff", # all related data is stuffed into prompt as context
160
+ prompt=PROMPT,
161
+ document_prompt=EXAMPLE_PROMPT,
162
+ )
163
+ return CustomChain(
164
+ chain=doc_chain, vstore=vectorstore, key_word_extractor=key_word_extractor
165
+ )
166
+ # doc + input -> game environment
167
+
168
+ def _get_chat_history(chat_history: List[Tuple[str, str]]):
169
+ buffer = ""
170
+ for human_s, ai_s in chat_history:
171
+ human = f"Human: " + human_s
172
+ ai = f"Assistant: " + ai_s
173
+ buffer += "\n" + "\n".join([human, ai])
174
+ return buffer
ingest.py ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+
3
+ """Load html from files, clean up, split, ingest into Weaviate."""
4
+ import os
5
+ from pathlib import Path
6
+
7
+ import weaviate
8
+ from bs4 import BeautifulSoup
9
+ from langchain.text_splitter import CharacterTextSplitter
10
+
11
+ os.environ["OPENAI_API_KEY"] = "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"
12
+
13
+ def clean_data(data):
14
+ soup = BeautifulSoup(data, features = "lxml")
15
+ text = soup.find_all("main", {"id": "main-content"})[0].get_text()
16
+ return "\n".join([t for t in text.split("\n") if t])
17
+
18
+
19
+ docs = []
20
+ metadatas = []
21
+ for p in Path("https://textworld.readthedocs.io/en/latest/").rglob("*"): # to enrich gameplay and quest generation
22
+ if p.is_dir():
23
+ continue
24
+ with open(p) as f:
25
+ docs.append(clean_data(f.read()))
26
+ print('.. DOCS')
27
+ metadatas.append({"source": p})
28
+
29
+
30
+ text_splitter = CharacterTextSplitter(
31
+ separator="\n",
32
+ chunk_size=1000,
33
+ chunk_overlap=200,
34
+ length_function=len,
35
+ )
36
+
37
+ documents = text_splitter.create_documents(docs, metadatas=metadatas)
38
+ print('documents', documents)
39
+
40
+ WEAVIATE_URL = "https://tro.weaviate.network/"
41
+ #WEAVIATE_URL = os.environ["WEAVIATE_URL"]
42
+
43
+ client = weaviate.Client(
44
+ url=WEAVIATE_URL,
45
+ additional_headers={"X-OpenAI-Api-Key": os.environ["OPENAI_API_KEY"]},
46
+ )
47
+
48
+ # text2vec DB
49
+
50
+ client.schema.get()
51
+ schema = {
52
+ "classes": [
53
+ {
54
+ "class": "Paragraphs",
55
+ "description": "A written paragraph",
56
+ "vectorizer": "text2vec-openai",
57
+ "moduleConfig": {
58
+ "text2vec-openai": {
59
+ "model": "ada",
60
+ "modelVersion": "002",
61
+ "type": "text",
62
+ }
63
+ },
64
+ "properties": [
65
+ {
66
+ "dataType": ["text"],
67
+ "description": "The content of the paragraph",
68
+ "moduleConfig": {
69
+ "text2vec-openai": {
70
+ "skip": False,
71
+ "vectorizePropertyName": False,
72
+ }
73
+ },
74
+ "name": "content",
75
+ },
76
+ {
77
+ "dataType": ["text"],
78
+ "description": "The link",
79
+ "moduleConfig": {
80
+ "text2vec-openai": {
81
+ "skip": True,
82
+ "vectorizePropertyName": False,
83
+ }
84
+ },
85
+ "name": "source",
86
+ },
87
+ ],
88
+ },
89
+ ]
90
+ }
91
+
92
+ client.schema.create(schema)
93
+
94
+ with client.batch as batch:
95
+ for text in documents:
96
+ batch.add_data_object(
97
+ {"content": text.page_content, "source": str(text.metadata["source"])},
98
+ "Paragraphs",
99
+ )
ingest.sh ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ # Bash script to ingest data
2
+ # This involves scraping the data from the web and then cleaning up and putting in Weaviate.
3
+ !set -eu
4
+ wget -r -A.html https://textworld.readthedocs.io/en/latest/
5
+ python3 ingest.py
6
+ python3 ingest_examples.py
ingest_examples.py ADDED
@@ -0,0 +1,341 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Ingest examples into Weaviate."""
2
+ import os
3
+ from pathlib import Path
4
+ import weaviate
5
+
6
+ os.environ["OPENAI_API_KEY"] = "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"
7
+ WEAVIATE_URL = "https://tro.weaviate.network/"
8
+
9
+ client = weaviate.Client(
10
+ url=WEAVIATE_URL,
11
+ additional_headers={"X-OpenAI-Api-Key": os.environ["OPENAI_API_KEY"]},
12
+ )
13
+
14
+ client.schema.get()
15
+ schema = {
16
+ "classes": [
17
+ {
18
+ "class": "Rephrase",
19
+ "description": "Rephrased Examples",
20
+ "vectorizer": "text2vec-openai",
21
+ "moduleConfig": {
22
+ "text2vec-openai": {
23
+ "model": "ada",
24
+ "modelVersion": "002",
25
+ "type": "text",
26
+ }
27
+ },
28
+ "properties": [
29
+ {
30
+ "dataType": ["text"],
31
+ "moduleConfig": {
32
+ "text2vec-openai": {
33
+ "skip": False,
34
+ "vectorizePropertyName": False,
35
+ }
36
+ },
37
+ "name": "content",
38
+ },
39
+ {
40
+ "dataType": ["text"],
41
+ "description": "The link",
42
+ "moduleConfig": {
43
+ "text2vec-openai": {
44
+ "skip": True,
45
+ "vectorizePropertyName": False,
46
+ }
47
+ },
48
+ "name": "game_description",
49
+ },
50
+ {
51
+ "dataType": ["text"],
52
+ "description": "The link",
53
+ "moduleConfig": {
54
+ "text2vec-openai": {
55
+ "skip": True,
56
+ "vectorizePropertyName": False,
57
+ }
58
+ },
59
+ "name": "game_environment",
60
+ },
61
+ {
62
+ "dataType": ["text"],
63
+ "description": "The link",
64
+ "moduleConfig": {
65
+ "text2vec-openai": {
66
+ "skip": True,
67
+ "vectorizePropertyName": False,
68
+ }
69
+ },
70
+ "name": "chat_history",
71
+ },
72
+ ],
73
+ },
74
+ ]
75
+ }
76
+
77
+ client.schema.create(schema)
78
+
79
+
80
+ documents = [
81
+
82
+ {
83
+ "game_description": "A James Bond like game where a secret agent attempts to prevent a criminal syndicate from using a satellite weapon. \
84
+ There are a series of levels, in each level the player must complete a set of objectives like defeating enemies and \
85
+ rescuing hostages, or even using high-tech gadgets. There are no health-recovery items but body armour can be aquired, along with 20 different weapons.",
86
+ "chat_history":"",
87
+ "game_environment": "Based on your input, I have created a game entitled, 'The Secret Agent: Satellite Strike'. \
88
+ This game follows a secret agent as they attempt to prevent a criminal syndicate from using a satellite weapon. You will \
89
+ control the secret agent as they traverse a series of levels, accomplishing different objectives such as defeating enemies, \
90
+ rescuing hostages, and using high-tech gadgets. To challenge the player, there are no health-recovery items, but there is \
91
+ body armour and 20 different weapons to be collected. \
92
+ The main characters of your game are the secret agent, their adversaries in the criminal syndicate, and their allies.\
93
+ The enemies will be fierce and unrelenting, but the rewards of completing a successful mission will be great. As the secret agent,\
94
+ your goal is to thwart the criminal syndicate's efforts and protect the world from the satellite weapon."
95
+ },
96
+ {
97
+ "game_description":"ok, how about jiu jitsu?",
98
+ "chat_history": "The player can use Jiu Jitsu as a defensive technique against the Cyberwolves. \
99
+ This martial art form allows the player to dodge, block, and counterattack the Cyberwolves, allowing them to escape from danger and progress through the game.",\
100
+ "game_environment": " In Cyberwolves: Escape from Danger, players take on the role of a hero who must\
101
+ traverse a dangerous cyberpunk world, avoiding and fighting off Cyberwolves. They will have access to Jiu Jitsu \
102
+ as a defensive martial art, allowing them to dodge and counterattack the Cyberwolves. Along the way, they will face \
103
+ a variety of challenges, enemies, and puzzles while progressing towards the ultimate goal.\
104
+ Question: What type of rewards will the player gain by completing the game?"
105
+ },
106
+ {
107
+ "game_description": "A game set in hell where you are a fallen angel that needs to redeem herself to reach the promised land once more.\
108
+ The enemies are scattered across the 7 circles of hell and grow increasingly challenging as you try to escape. \
109
+ The enemies are warped forms of everyday creatures that inspire fear and hatred to everyday observers. But there's a twist. \
110
+ There's a creature in hell who wants you to stay and they tempt you with various sidequests that entice you to give up on your goal of reaching heaven again.",
111
+ "chat_history": "",
112
+ "game_environment": "The game title is: 'The Forsaken Redemption'. You must battle your way through the seven circles \
113
+ of hell and defeat the warped enemies in your quest to redeem yourself and reach the promised land once more.\
114
+ But beware, a mysterious creature lurks in the shadows, intent on tempting you with side quests to make you lose your way. Will you succumb to its influence or stay the course?"
115
+ },
116
+
117
+ {
118
+ "game_description": "Grandma Phyllis and Grandpa Jim are hosting a family reunion with their grandchildren when it is crashed by two bikers.\
119
+ what are some quests in this game with grandma phyllis?",
120
+ "chat_history":"What quests or challenges can the player's granddaughter, Nell, complete in the game 'Grandma Phyllis and Grandpa Jim's Family Reunion'?",
121
+ "game_environment": "In Grandma Phyllis and Grandpa Jim's Family Reunion, Nell can complete a variety of challenges that relate to the family reunion. Nell can explore the family history, interact with family members, find family heirlooms and special items, and much more. Nell can also complete tasks to help Grandma Phyllis and Grandpa Jim prepare for the reunion. She can make decorations, help plan the menu, and make sure everyone is ready for the big event. Each challenge \
122
+ completed will be rewarded with a special family heirloom, and at the end of the game, Nell will have earned enough to restore the family home"
123
+ },
124
+ {
125
+ "game_description":"add a baby",
126
+ "chat_history": "What kind of quests would involve a baby in Grandma Phyllis and Grandpa Jim's Family Reunion?",\
127
+ "game_environment": " You could have a quest where the player has to reunite the baby with their parent.\
128
+ This quest could be difficult as the baby's parent could be anywhere in the world. The player could start off \
129
+ by visiting Grandma Phyllis and Grandpa Jim, who can provide clues as to their whereabouts. The player could \
130
+ also talk to other family members to gain more information. Throughout the quest, the player can collect items that \
131
+ can help in their search for the baby's parent.\
132
+ Upon successful completion of the quest, the player is rewarded with Grandma Phyllis and Grandpa Jim's appreciation."
133
+ },
134
+ {
135
+ "game_description": "who is the enemy and give me a dangerous plot point",
136
+ "chat_history": "The enemy in Grandma Phyllis and Grandpa Jim's Family Reunion is the two bikers who crashed the family reunion. \
137
+ They threaten the safety of the family and must be stopped. A dangerous plot point could be when the bikers take the baby away,\
138
+ leaving the player to find and reunite the baby with their parent. This would add an element of suspense and danger to the game.",
139
+ "game_environment": "For Grandma Phyllis and Grandpa Jim's Family Reunion, the enemy of the game \
140
+ are the two bikers who crashed the family reunion. They threaten the safety of the family and must be stopped. \
141
+ As for a dangerous plot point, how about when the bikers take the baby away and the player must reunite the baby with\
142
+ their parent. This would add an element of suspense and urgency to the game,\
143
+ as the player is tasked with rescuing the baby before the bikers hurt them. Do you have any other ideas or suggestions for the game?"
144
+ },
145
+ {
146
+ "game_description": "For the underwater game, what game objects can we add? ",
147
+ "chat_history":"",
148
+ "game_environment": "Ancient Underwater Tablet - A collectible that can be found throughout the ancient underwater civilization and provides information and clues about the \
149
+ civilization's history and secrets. Can be examined and studied in the player's inventory, place_object('collectible', '50'). Cursed Fish \
150
+ - An enemy that inhabits the deep waters of the ancient underwater civilization. It attacks the player if they get too close. Can be defeated \
151
+ by using weapons or magic. place_object('enemy', '40')], and Underwater Creature, an NPC that the player can talk to for advice and information \
152
+ about the ancient underwater civilization, place_object('NPC', '100')]"
153
+ },
154
+ {
155
+ "game_description":"'a soccer game where the player attempts to win a match against their childhood rival , taking place in Argentina during an abnormal period of strife",
156
+ "chat_history": "",
157
+ "game_environment": "Game Title: Rivalry On The Field \
158
+ Game Genre: Sports \
159
+ Story/Emotional Motivation of Player Character: The player character is a passionate soccer player who grew up in Argentina. \
160
+ This player has a long-standing rivalry with their childhood rival, and this game will give them the chance to finally prove who's the best on the field. \
161
+ Game Objects: \
162
+ NPCs: Player Character's Childhood Rival - The opponent in the game whose competitiveness fuels the rivalry. \
163
+ Enemies: Soccer defender - An aggressive defender who will attempt to stop the player from scoring goals. \
164
+ Collectibles: Soccer Ball - A special soccer ball that the player must use in order to win the game. \
165
+ Do you have any details you'd like to add or questions about the game?"
166
+ },
167
+ {
168
+ "game_description": "does the mother love the player or the soccer rival ",
169
+ "chat_history":"The Mother collectible is a special item with a story associated with it. The player will discover \
170
+ the details of the collectible's story as they progress in the game and they will learn the answer to your question when they find the collectible.",
171
+ "game_environment": "In the game, the relationship between the Mother collectible and the player character and their childhood rival\
172
+ is unclear. Does the Mother love the player, the soccer rival, or both?\
173
+ combined The Mother collectible represents love for both the player character and their childhood soccer rival. \
174
+ The Mother provides the player a quest, which is to resolve the conflict between them\
175
+ and their rival, ultimately bringing the two closer together. The Mother collectible symbolizes the importance of love and family in the player's life"
176
+ },
177
+ {
178
+ "game_description":"'The Nightmare's Lair' is a first-person survival horror game set in a haunted mansion where the player uncovers",
179
+ "chat_history": "Human: provide game details Assistant: Title:'The Nightmare's Lair', Theme: is a first-person survival horror \
180
+ game set in a haunted mansion where the player uncovers the truth behind\
181
+ terrifying nightmares with dark and realistic art style, Artistic Style: Dark and realistic, View: first-person, Genre: Survival horror",\
182
+ "game_environment": "the player will interact with NPCs in order to progress \
183
+ through the game. Each NPC has their own unique personality and behavior, as well as an agenda that the player \
184
+ must discover in order to complete the game. Some NPCs may offer advice or assistance, while others may prove\
185
+ hostile or deceptive. The player will need to be strategic in order to navigate these relationships and work towards their ultimate goal."
186
+ },
187
+ ] # all of this
188
+
189
+ # documents = [
190
+ # {
191
+ # "game_description": "a thrilling underwater game with where players discover artifacts",
192
+ # "chat_history": "Human: what is the game environment? Assistant:: Title: Shadow of the abyss,\
193
+ # Theme: ancient underwater civilization, \
194
+ # Artistic Style: Anime, View: isometric-view, Genre: Action-Adventure",\
195
+ # "game_environment": "In Shadow of the Abyss, you will encounter a variety of obstacles, enemies, \
196
+ # NPCs, and collectibles. For this underwater game, sea obstacles include ancient ruins, coral reefs, and underwater caves.\
197
+ # Enemies include sea monsters, sharks, and other aquatic creatures. NPCs include friendly merpeople, lost divers, \
198
+ # and mysterious sea creatures. Collectibles include artifacts, gems, and other hidden treasures.\
199
+ # Ancient ruins can be explored to find hidden secrets and clues, while coral reefs and underwater \
200
+ # caves can be navigated to discover new areas. Monsters and sharks can be fought off while creatures \
201
+ # and NPCs can be interacted with to gain information or items. \
202
+ # Collectibles can be gathered to power up the player’s abilities or used to craft new items."
203
+ # },
204
+ # {
205
+ # "game_description": "For the underwater game, what game objects can we add? ",
206
+ # "chat_history":"":,
207
+ # "game_environment": "Ancient Underwater Tablet - A collectible that can be found throughout the ancient underwater civilization and provides information and clues about the \
208
+ # civilization's history and secrets. Can be examined and studied in the player's inventory, place_object('collectible', '50'). Cursed Fish \
209
+ # - An enemy that inhabits the deep waters of the ancient underwater civilization. It attacks the player if they get too close. Can be defeated \
210
+ # by using weapons or magic. place_object('enemy', '40')], and Underwater Creature, an NPC that the player can talk to for advice and information \
211
+ # about the ancient underwater civilization, place_object('NPC', '100')]"
212
+ # },
213
+ # {
214
+ # "game_description":"'The Nightmare's Lair' is a first-person survival horror game set in a haunted mansion where the player uncovers",
215
+ # "chat_history": "Human: provide game details Assistant: Title:'The Nightmare's Lair', Theme: is a first-person survival horror \
216
+ # game set in a haunted mansion where the player uncovers the truth behind\
217
+ # terrifying nightmares with dark and realistic art style, Artistic Style: Dark and realistic, View: first-person, Genre: Survival horror",\
218
+ # "game_environment": "In 'The Nightmare's Lair', the player will interact with NPCs in order to progress \
219
+ # through the game. Each NPC has their own unique personality and behavior, as well as an agenda that the player \
220
+ # must discover in order to complete the game. Some NPCs may offer advice or assistance, while others may prove\
221
+ # hostile or deceptive. The player will need to be strategic in order to navigate these relationships and work towards their ultimate goal."
222
+ # },
223
+ # ] # all of this is in the {'Rephrase': chat history --weaviate.
224
+
225
+ from langchain.prompts.example_selector.semantic_similarity import \
226
+ sorted_values
227
+
228
+ for d in documents:
229
+ d["content"] = " ".join(sorted_values(d))
230
+ print(d["content"])
231
+ with client.batch as batch:
232
+ for text in documents:
233
+ # print(text)
234
+ batch.add_data_object(
235
+ text,
236
+ "Rephrase",
237
+ )
238
+
239
+ client.schema.get()
240
+ schema = {
241
+ "classes": [
242
+ {
243
+ "class": "QAs",
244
+ "description": "Rephrased Examples",
245
+ "vectorizer": "text2vec-openai",
246
+ "moduleConfig": {
247
+ "text2vec-openai": {
248
+ "model": "ada",
249
+ "modelVersion": "002",
250
+ "type": "text",
251
+ }
252
+ },
253
+ "properties": [
254
+ {
255
+ "dataType": ["text"],
256
+ "moduleConfig": {
257
+ "text2vec-openai": {
258
+ "skip": False,
259
+ "vectorizePropertyName": False,
260
+ }
261
+ },
262
+ "name": "content",
263
+ },
264
+ {
265
+ "dataType": ["text"],
266
+ "description": "The link",
267
+ "moduleConfig": {
268
+ "text2vec-openai": {
269
+ "skip": True, # can try setting to false ?
270
+ "vectorizePropertyName": False,
271
+ }
272
+ },
273
+ "name": "game_description", # question
274
+ },
275
+ {
276
+ "dataType": ["text"],
277
+ "description": "The link",
278
+ "moduleConfig": {
279
+ "text2vec-openai": {
280
+ "skip": True,
281
+ "vectorizePropertyName": False,
282
+ }
283
+ },
284
+ "name": "game_quest", # summaries
285
+ },
286
+ {
287
+ "dataType": ["text"],
288
+ "description": "The link",
289
+ "moduleConfig": {
290
+ "text2vec-openai": {
291
+ "skip": True,
292
+ "vectorizePropertyName": False,
293
+ }
294
+ },
295
+ "name": "sources",
296
+ },
297
+ ],
298
+ },
299
+ ]
300
+ }
301
+
302
+ client.schema.create(schema)
303
+
304
+ documents = [
305
+ {
306
+ "game_description": "a thrilling underwater game with where players discover artifacts",
307
+ "game_environment": "underwater theme",
308
+ "game_quest": ">Example:\nContent:\n---------\nThe inhabitants of an ancient underwater civilization known as 'Shadow of the Abyss' \
309
+ are in dire need of help. A mysterious force has been corrupting and consuming the artifacts that are essential to the civilization’s \
310
+ history and culture. An intrepid adventurer has been summoned to undertake a daring quest to save the artifacts.\
311
+ The player must explore the depths of 'Shadow of the Abyss' and battle against various underwater enemies, such as the \
312
+ cursed fish, as well as collect ancient underwater tablets. The player must also search for and speak to the mysterious underwater creature in order\
313
+ to gain information and advice about the ancient underwater civilization. As the player progresses on the quest, they will be met with greater and more \
314
+ difficult challenges. This includes navigating the treacherous and complicated underwater world, avoiding the deadly cursed fish, \
315
+ and finding and deciphering the ancient underwater tablets. Eventually, the player will reach the climax of the quest and battle \
316
+ against a powerful enemy in order to save the artifacts and preserve the ancient civilization.The reward for completing this quest is the \
317
+ knowledge that the artifacts have been saved, as well as access to the secrets of the ancient civilization.\
318
+ Sample character dialogue:\
319
+ Player: 'I have been summoned to save the artifacts of this ancient civilization'",
320
+ "sources": "foo.html"
321
+ },
322
+ # {
323
+ # "game_description": "'The Nightmare's Lair' is a first-person survival horror game set in a haunted mansion where the player uncovers the truth behind terrifying nightmares with dark and realistic art style",
324
+ # "game_environment": "The Nightmare's Lair', is a first-person survival horror game set in a haunted mansion where the player uncovers the truth behind\
325
+ # terrifying nightmares with dark and realistic art style', 'Dark and realistic', 'first-person', 'Survival horror'",
326
+ # "game_quest": ">Example:\nContent:\n---------\nShadow of the Abyss is an action-adventure game with a theme of uncovering secrets of an ancient underwater civilization, featuring stylized graphics, survival and exploration elements",
327
+ # "sources": "bar.html"
328
+ # },
329
+ ]
330
+
331
+ from langchain.prompts.example_selector.semantic_similarity import \
332
+ sorted_values
333
+
334
+ for d in documents:
335
+ d["content"] = " ".join(sorted_values(d))
336
+ with client.batch as batch:
337
+ for text in documents:
338
+ batch.add_data_object(
339
+ text,
340
+ "QAs",
341
+ )
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ langchain==0.0.64
2
+ beautifulsoup4
3
+ weaviate-client
4
+ openai
5
+ black
6
+ isort
7
+ Flask
8
+ transformers
9
+ gradio