Skip to content

Commit

Permalink
Update Collection Names
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashacker committed Apr 15, 2024
1 parent 352ce1d commit ef69d27
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 35 deletions.
7 changes: 1 addition & 6 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,14 @@
"containerEnv": {
"POETRY_VIRTUALENVS_IN_PROJECT": "true"
}

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "pip3 install --user -r requirements.txt",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,7 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

.devcontainer

.python-version
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Before you run the Jupyter notebook or the Streamlit app, create a `.env` file i
```
WEAVIATE_URL= YOUR WEAVIATE_CLUSTER_URL
WEAVIATE_API_KEY= YOUR WEAVIATE_API_KEY
OPENAI_API_KEY= (ONLY NEEDED FOR STREAMLIT APP)
OPENAI_KEY= (ONLY NEEDED FOR STREAMLIT APP)
```
To set up your Weaviate cluster, follow either of these methods:
Expand Down
8 changes: 4 additions & 4 deletions data/add_card_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def main() -> None:

# Connect to Weaviate
url = os.environ.get("WEAVIATE_URL", "")
openai_key = os.environ.get("OPENAI_API_KEY", "")
openai_key = os.environ.get("OPENAI_KEY", "")
auth_config = weaviate.AuthApiKey(api_key=os.environ.get("WEAVIATE_API_KEY", ""))

if openai_key == "" or url == "":
Expand All @@ -32,14 +32,14 @@ def main() -> None:

msg.good("Client connected to Weaviate Server")

if client.schema.exists("Card"):
msg.warn("Card class already exists")
if client.schema.exists("MagicChat_Card"):
msg.warn("MagicChat_Card class already exists")
return

with open("weaviate_schema.json", "r") as reader:
class_obj = json.load(reader)
client.schema.create_class(class_obj)
msg.good("Card class created")
msg.good("MagicChat_Card class created")


if __name__ == "__main__":
Expand Down
8 changes: 4 additions & 4 deletions data/delete_card_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ def main() -> None:

msg.good("Client connected to Weaviate Server")

if not client.schema.exists("Card"):
msg.warn(f"Card class does not exist")
if not client.schema.exists("MagicChat_Card"):
msg.warn(f"MagicChat_Card class does not exist")
return
else:
client.schema.delete_class("Card")
msg.good(f"Card class deleted")
client.schema.delete_class("MagicChat_Card")
msg.good(f"MagicChat_Card class deleted")


if __name__ == "__main__":
Expand Down
10 changes: 5 additions & 5 deletions data/retrieve_magic_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def add_card_to_weaviate(weaviate_obj: dict, client: weaviate.Client) -> None:
"""
with client.batch as batch:
batch.batch_size = 1
client.batch.add_data_object(weaviate_obj, "Card")
client.batch.add_data_object(weaviate_obj, "MagicChat_Card")
msg.good(f"Imported {weaviate_obj['name']} to database")


Expand All @@ -80,7 +80,7 @@ def main() -> None:

# Connect to Weaviate
url = os.environ.get("WEAVIATE_URL", "")
openai_key = os.environ.get("OPENAI_API_KEY", "")
openai_key = os.environ.get("OPENAI_KEY", "")
auth_config = weaviate.AuthApiKey(api_key=os.environ.get("WEAVIATE_API_KEY", ""))

if openai_key == "" or url == "":
Expand All @@ -99,7 +99,7 @@ def main() -> None:

query_results = (
client.query.get(
"Card",
"MagicChat_Card",
["name"],
)
.with_limit(30000)
Expand All @@ -109,11 +109,11 @@ def main() -> None:
unique_cards = set(
[
str(card["name"]).lower().strip()
for card in query_results["data"]["Get"]["Card"]
for card in query_results["data"]["Get"]["MagicChat_Card"]
]
)

msg.info(f"Loaded {len(query_results['data']['Get']['Card'])} cards")
msg.info(f"Loaded {len(query_results['data']['Get']['MagicChat_Card'])} cards")

with open("all_cards.json", "r") as reader:
all_cards = json.load(reader)["data"]
Expand Down
2 changes: 1 addition & 1 deletion data/weaviate_schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"class": "Card",
"class": "MagicChat_Card",
"description": "Magic the Gathering cards",
"properties": [
{
Expand Down
6 changes: 3 additions & 3 deletions notebooks/01_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
"source": [
"with conn.client().batch as batch:\n",
" for pokemon in pokemons:\n",
" batch.add_data_object(data_object=pokemon, class_name=\"Pokemon\")"
" batch.add_data_object(data_object=pokemon, class_name=\"MagicChat_Pokemon\")"
]
},
{
Expand Down Expand Up @@ -249,7 +249,7 @@
"gql = \"\"\"\n",
"{\n",
" Get {\n",
" Pokemon(limit: 3, bm25: {query: \"electric\"}) {\n",
" MagicChat_Pokemon(limit: 3, bm25: {query: \"electric\"}) {\n",
" name\n",
" attack\n",
" _additional {\n",
Expand Down Expand Up @@ -291,7 +291,7 @@
}
],
"source": [
"results = conn.client().query.get(\"Pokemon\", [\"name\", \"attack\"])\\\n",
"results = conn.client().query.get(\"MagicChat_Pokemon\", [\"name\", \"attack\"])\\\n",
" .with_limit(3)\\\n",
" .with_additional(\"score\")\\\n",
" .with_bm25(query=\"electric\")\\\n",
Expand Down
23 changes: 12 additions & 11 deletions streamlit_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

from dotenv import load_dotenv

load_dotenv()

# Constants
ENV_VARS = ["WEAVIATE_URL", "WEAVIATE_API_KEY", "OPENAI_API_KEY"]
ENV_VARS = ["WEAVIATE_URL", "WEAVIATE_API_KEY", "OPENAI_KEY"]
NUM_IMAGES_PER_ROW = 3


Expand All @@ -17,7 +19,6 @@ def get_env_vars(env_vars: list) -> dict:
@parameter env_vars : list - List containing keys of environment variables
@returns dict - A dictionary of environment variables
"""
load_dotenv()

env_vars = {}
for var in ENV_VARS:
Expand Down Expand Up @@ -49,7 +50,7 @@ def display_chat_messages() -> None:
env_vars = get_env_vars(ENV_VARS)
url = env_vars["WEAVIATE_URL"]
api_key = env_vars["WEAVIATE_API_KEY"]
openai_key = env_vars["OPENAI_API_KEY"]
openai_key = env_vars["OPENAI_KEY"]

# Check keys
if url == "" or api_key == "" or openai_key == "":
Expand Down Expand Up @@ -85,7 +86,7 @@ def display_chat_messages() -> None:
bm25_gql = """
{{
Get {{
Card(limit: {limit_card}, bm25: {{ query: "{input}" }})
MagicChat_Card(limit: {limit_card}, bm25: {{ query: "{input}" }})
{{
name
card_id
Expand All @@ -112,7 +113,7 @@ def display_chat_messages() -> None:
vector_gql = """
{{
Get {{
Card(limit: {limit_card}, nearText: {{ concepts: ["{input}"] }})
MagicChat_Card(limit: {limit_card}, nearText: {{ concepts: ["{input}"] }})
{{
name
card_id
Expand All @@ -139,7 +140,7 @@ def display_chat_messages() -> None:
hybrid_gql = """
{{
Get {{
Card(limit: {limit_card}, hybrid: {{ query: "{input}" alpha:0.5 }})
MagicChat_Card(limit: {limit_card}, hybrid: {{ query: "{input}" alpha:0.5 }})
{{
name
card_id
Expand All @@ -166,7 +167,7 @@ def display_chat_messages() -> None:
generative_gql = """
{{
Get {{
Card(limit: {limit_card}, nearText: {{ concepts: ["{input}"] }})
MagicChat_Card(limit: {limit_card}, nearText: {{ concepts: ["{input}"] }})
{{
name
card_id
Expand Down Expand Up @@ -257,7 +258,7 @@ def display_chat_messages() -> None:
"""
{
Get {
Card(limit: {card_limit}, bm25: { query: "Vampires with flying ability" })
MagicChat_Card(limit: {card_limit}, bm25: { query: "Vampires with flying ability" })
{
...
}
Expand All @@ -274,7 +275,7 @@ def display_chat_messages() -> None:
"""
{
Get {
Card(limit: {card_limit}, nearText: { concepts: ["Vampires with flying ability"] })
MagicChat_Card(limit: {card_limit}, nearText: { concepts: ["Vampires with flying ability"] })
{
...
}
Expand All @@ -291,7 +292,7 @@ def display_chat_messages() -> None:
"""
{
Get {
Card(limit: {card_limit}, hybrid: { query: "Vampires with flying ability" alpha:0.5 })
MagicChat_Card(limit: {card_limit}, hybrid: { query: "Vampires with flying ability" alpha:0.5 })
{
...
}
Expand All @@ -308,7 +309,7 @@ def display_chat_messages() -> None:
"""
{
Get {
Card(limit: {card_limit}, nearText: { concepts: ["Vampires with flying ability"] })
MagicChat_Card(limit: {card_limit}, nearText: { concepts: ["Vampires with flying ability"] })
{
_additional {
generate(
Expand Down

0 comments on commit ef69d27

Please sign in to comment.