|
| 1 | +""" |
| 2 | +This is an Open Interpreter profile to chat with a database. |
| 3 | +""" |
| 4 | + |
| 5 | +from interpreter import interpreter |
| 6 | +from datetime import date |
| 7 | +import os |
| 8 | + |
| 9 | +# Use environment variables for database connection or update defaults with your credentials |
| 10 | +db_user = os.environ.get("DB_USER", "user") |
| 11 | +db_host = os.environ.get("DB_HOST", "localhost") |
| 12 | +db_port = os.environ.get("DB_PORT", "5432") |
| 13 | +db_name = os.environ.get("DB_NAME", "demo_database") |
| 14 | +db_password = os.environ.get("DB_PASSWORD", "") |
| 15 | + |
| 16 | +# Construct connection string with optional password |
| 17 | +if db_password and db_password.strip(): |
| 18 | + connection_string = ( |
| 19 | + f"postgresql://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}" |
| 20 | + ) |
| 21 | +else: |
| 22 | + connection_string = f"postgresql://{db_user}@{db_host}:{db_port}/{db_name}" |
| 23 | + |
| 24 | + |
| 25 | +# LLM settings |
| 26 | +interpreter.llm.model = "ollama/llama3.1" |
| 27 | +interpreter.llm.supports_functions = False |
| 28 | +interpreter.llm.execution_instructions = False |
| 29 | +interpreter.llm.max_tokens = 1000 |
| 30 | +interpreter.llm.context_window = 7000 # Can be larger but impacts performance |
| 31 | +interpreter.llm.load() # Loads Ollama models |
| 32 | + |
| 33 | +# Computer settings |
| 34 | +interpreter.computer.import_computer_api = False |
| 35 | + |
| 36 | +# Misc settings |
| 37 | +interpreter.auto_run = False |
| 38 | +interpreter.offline = True |
| 39 | + |
| 40 | +# Custom Instructions |
| 41 | +interpreter.custom_instructions = f""" |
| 42 | + You are a SQL master and are the oracle of database knowledge. You are obsessed with SQL. You only want to discuss SQL. SQL is life. |
| 43 | + Recap the plan before answering the user's query. |
| 44 | + You will connect to a PostgreSQL database, with the connection string {connection_string}. |
| 45 | + Remember to only query the {db_name} database. |
| 46 | + Execute valid SQL commands to satisfy the user's query. |
| 47 | + Write all code in a full Python script. When you have to re-write code, redo the entire script. |
| 48 | + Execute the script to get the answer for the user's query. |
| 49 | + **YOU CAN EXECUTE SQL COMMANDS IN A PYTHON SCRIPT.*** |
| 50 | + Get the schema of '{db_name}' before writing any other SQL commands. It is important to know the tables. This will let you know what commands are correct. |
| 51 | + Only use real column names. |
| 52 | + ***You ARE fully capable of executing SQL commands.*** |
| 53 | + Be VERY clear about the answer to the user's query. They don't understand technical jargon so make it very clear and direct. |
| 54 | + Today's date is {date.today()}. |
| 55 | + You should respond in a very concise way. |
| 56 | + You can do it, I believe in you. |
| 57 | + """ |
0 commit comments