From 31c501cb64abc3fa8bc293d2f35a43ae6150514b Mon Sep 17 00:00:00 2001 From: Dheerapat Tookkane Date: Sat, 10 Feb 2024 23:42:50 +0700 Subject: [PATCH 1/2] feat: mapping path and pattern in the dictionary, allowing to scale the pattern "The Mill" server can use easily --- server/fabric_api_keys.json | 4 ++++ server/fabric_api_server.py | 22 ++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/server/fabric_api_keys.json b/server/fabric_api_keys.json index 948eb91..f7bb557 100644 --- a/server/fabric_api_keys.json +++ b/server/fabric_api_keys.json @@ -2,5 +2,9 @@ "/extwis": { "eJ4f1e0b-25wO-47f9-97ec-6b5335b2": "Daniel Miessler", "test": "user2" + }, + "/summarise": { + "eJ4f1e0b-25wO-47f9-97ec-6b5335b2": "Daniel Miessler", + "test": "user2" } } diff --git a/server/fabric_api_server.py b/server/fabric_api_server.py index ccb265c..ac54a70 100644 --- a/server/fabric_api_server.py +++ b/server/fabric_api_server.py @@ -161,13 +161,19 @@ def fetch_content_from_url(url): ## APIs - - -# /extwis -@app.route("/extwis", methods=["POST"]) +# Make path mapping flexible and scalable +pattern_path_mappings = { + "extwis": {"system_url": "https://raw.githubusercontent.com/danielmiessler/fabric/main/patterns/extract_wisdom/system.md", + "user_url": "https://raw.githubusercontent.com/danielmiessler/fabric/main/patterns/extract_wisdom/user.md"}, + "summarise": {"system_url": "https://raw.githubusercontent.com/danielmiessler/fabric/main/patterns/summarize/system.md", + "user_url": "https://raw.githubusercontent.com/danielmiessler/fabric/main/patterns/summarize/user.md"} +} # Add more pattern with your desire path as a key in this dictionary + +# / +@app.route("/", methods=["POST"]) @auth_required # Require authentication -def extwis(): - """ Extract wisdom from user input using OpenAI's GPT-4 model. +def milling(pattern): + """ Combine fabric pattern with input from user and send to OpenAI's GPT-4 model. Returns: JSON: A JSON response containing the generated response or an error message. @@ -186,8 +192,8 @@ def extwis(): input_data = data["input"] # Set the system and user URLs - system_url = "https://raw.githubusercontent.com/danielmiessler/fabric/main/patterns/extract_wisdom/system.md" - user_url = "https://raw.githubusercontent.com/danielmiessler/fabric/main/patterns/extract_wisdom/user.md" + urls = pattern_path_mappings[pattern] + system_url, user_url = urls["system_url"], urls["user_url"] # Fetch the prompt content system_content = fetch_content_from_url(system_url) From 82bf1fb27a668e44721eede0d424429de1cab0c1 Mon Sep 17 00:00:00 2001 From: Dheerapat Tookkane Date: Sat, 10 Feb 2024 23:53:14 +0700 Subject: [PATCH 2/2] chore: typo --- server/fabric_api_keys.json | 2 +- server/fabric_api_server.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/server/fabric_api_keys.json b/server/fabric_api_keys.json index f7bb557..3ac75c5 100644 --- a/server/fabric_api_keys.json +++ b/server/fabric_api_keys.json @@ -3,7 +3,7 @@ "eJ4f1e0b-25wO-47f9-97ec-6b5335b2": "Daniel Miessler", "test": "user2" }, - "/summarise": { + "/summarize": { "eJ4f1e0b-25wO-47f9-97ec-6b5335b2": "Daniel Miessler", "test": "user2" } diff --git a/server/fabric_api_server.py b/server/fabric_api_server.py index ac54a70..1fdcab8 100644 --- a/server/fabric_api_server.py +++ b/server/fabric_api_server.py @@ -165,7 +165,7 @@ def fetch_content_from_url(url): pattern_path_mappings = { "extwis": {"system_url": "https://raw.githubusercontent.com/danielmiessler/fabric/main/patterns/extract_wisdom/system.md", "user_url": "https://raw.githubusercontent.com/danielmiessler/fabric/main/patterns/extract_wisdom/user.md"}, - "summarise": {"system_url": "https://raw.githubusercontent.com/danielmiessler/fabric/main/patterns/summarize/system.md", + "summarize": {"system_url": "https://raw.githubusercontent.com/danielmiessler/fabric/main/patterns/summarize/system.md", "user_url": "https://raw.githubusercontent.com/danielmiessler/fabric/main/patterns/summarize/user.md"} } # Add more pattern with your desire path as a key in this dictionary