Skip to content

Commit

Permalink
feat: Add API endpoint to save system prompt and load it for initiali…
Browse files Browse the repository at this point in the history
…zation
  • Loading branch information
onuratakan committed Dec 10, 2024
1 parent 72f4058 commit d9deb9d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
15 changes: 15 additions & 0 deletions gpt_computer_assistant/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,21 @@ def save_openai_api_key():
save_api_key(openai_api_key)
return jsonify({"response": "OpenAI API key saved."})




@app.route("/save_system_prompt", methods=["POST"])
def save_system_prompt():
"""
This api saves the prompt
"""
data = request.json
prompt = data["prompt"]
from .utils.db import save_system_prompt

save_system_prompt(prompt)
return jsonify({"response": "prompt saved."})

@app.route("/save_anthropic_api_key", methods=["POST"])
def save_anthropic_api_key():
"""
Expand Down
5 changes: 2 additions & 3 deletions gpt_computer_assistant/llm_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,11 @@ def get_groq_models():
def first_message():
from .character import name, developer, get_website_content
from .cu.computer import width, height, display_num
from .utils.db import load_system_prompt
model = load_model_settings()

the_text = f"""
Hi, you are an platform for vertical AI. You need to understant the user aspect and then trying to do these things and give valuation.
{load_system_prompt()}
"""

the_website_content = get_website_content()
Expand Down
5 changes: 5 additions & 0 deletions gpt_computer_assistant/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ def save_openai_api_key(self, openai_api_key):
response = self.send_request("/save_openai_api_key", data)
return response["response"]

def save_system_prompt(self, prompt):
data = {"prompt": prompt}
response = self.send_request("/save_system_prompt", data)
return response["response"]

def save_anthropic_api_key(self, anthropic_api_key):
data = {"anthropic_api_key": anthropic_api_key}
response = self.send_request("/save_anthropic_api_key", data)
Expand Down
12 changes: 12 additions & 0 deletions gpt_computer_assistant/utils/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ def load_openai_url():
return "default"




def save_system_prompt(prompt):
kot_db_.set("system_prompt", prompt)
def load_system_prompt():
if kot_db_.get("system_prompt"):
return kot_db_.get("system_prompt")
else:
return "Hi, you are an platform for vertical AI. You need to understant the user aspect and then trying to do these things and give valuation."



# API VERSION SAVING AND LOADING
def save_api_version(url):
kot_db_.set("api_version", url)
Expand Down

0 comments on commit d9deb9d

Please sign in to comment.