Skip to content

Instantly share code, notes, and snippets.

@alexcg1
Last active November 7, 2024 13:05
Show Gist options
  • Save alexcg1/4150f2e7dfe0d635260c71d59324172b to your computer and use it in GitHub Desktop.
Save alexcg1/4150f2e7dfe0d635260c71d59324172b to your computer and use it in GitHub Desktop.
App Factory with Jina AI Meta-Prompt
import os
import requests
import llm
"""
1. Store your prompts in the folder "prompts" as text files.
2. Create the directory "apps".
3. Set your `ANTHROPIC_API_KEY`
3. Run appfactory.py to generate your apps.
"""
META_PROMPT_URL = "https://docs.jina.ai"
PROMPT_DIR = "prompts"
APP_DIR = "apps"
LLM = "claude-3.5-sonnet"
meta_prompt = requests.get(META_PROMPT_URL).text
model = llm.get_model(LLM)
model.key = os.environ["ANTHROPIC_API_KEY"]
def generate_app(prompt):
response = model.prompt(prompt, system=meta_prompt)
app = response.text()
return app
def extract_code(text):
system_prompt = 'leave just the code in this file, remove all surrounding explanatory text. do not wrap code in backticks, just return "pure code"'
response = model.prompt(text, system=system_prompt)
code = response.text()
return code
for filename in os.listdir(PROMPT_DIR):
print(f"Processing {filename}")
with open(f"{PROMPT_DIR}/{filename}", "r") as file:
prompt = file.read()
app = generate_app(prompt)
code = extract_code(app)
app_name = filename.split(".")[0]
output_filename = f"apps/{app_name}.py"
with open(output_filename, "w") as file:
file.write(code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment