{"id":17637865,"url":"https://github.com/quackscience/duckdb-extension-openprompt","last_synced_at":"2025-05-05T23:10:50.122Z","repository":{"id":258856196,"uuid":"875804278","full_name":"quackscience/duckdb-extension-openprompt","owner":"quackscience","description":"DuckDB Community Extension to prompt LLMs from SQL","archived":false,"fork":false,"pushed_at":"2025-01-08T20:19:37.000Z","size":107,"stargazers_count":46,"open_issues_count":3,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-03T23:09:29.078Z","etag":null,"topics":["duckdb","duckdb-database","extension","llm","llms","ollama","prompt","sql"],"latest_commit_sha":null,"homepage":"https://duckdb.org/community_extensions/extensions/open_prompt.html","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/quackscience.png","metadata":{"files":{"readme":"docs/README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-20T21:33:51.000Z","updated_at":"2025-04-28T23:29:59.000Z","dependencies_parsed_at":"2024-12-29T15:28:07.159Z","dependency_job_id":null,"html_url":"https://github.com/quackscience/duckdb-extension-openprompt","commit_stats":{"total_commits":38,"total_committers":3,"mean_commits":"12.666666666666666","dds":"0.13157894736842102","last_synced_commit":"23a4f5ebfc4c46e5f19abf07f0af076ea8ed85ed"},"previous_names":["lmangani/duckdb-extension-openprompt"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quackscience%2Fduckdb-extension-openprompt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quackscience%2Fduckdb-extension-openprompt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quackscience%2Fduckdb-extension-openprompt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/quackscience%2Fduckdb-extension-openprompt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/quackscience","download_url":"https://codeload.github.com/quackscience/duckdb-extension-openprompt/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252590619,"owners_count":21772939,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["duckdb","duckdb-database","extension","llm","llms","ollama","prompt","sql"],"created_at":"2024-10-23T03:06:27.786Z","updated_at":"2025-05-05T23:10:50.116Z","avatar_url":"https://github.com/quackscience.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://github.com/user-attachments/assets/46a5c546-7e9b-42c7-87f4-bc8defe674e0\" width=250 /\u003e\n\n# DuckDB Open Prompt Extension\nSimple extension to query OpenAI Completion API endpoints such as Ollama/OpenAI/etc\n\n\u003e Experimental: USE AT YOUR OWN RISK!\n\n## Installing and Loading\n```sql\nINSTALL open_prompt FROM community;\nLOAD open_prompt;\n```\n\n### Functions\n- `open_prompt(prompt)`\n- `set_api_url(/v1/chat/completions)`\n- `set_api_token(optional_auth_token)`\n- `set_model_name(model_name)`\n\n#### Requirements\n\n- DuckDB v1.1.1 or higher\n- API must support `/v1/chat/completions`\n\n### Settings\nSetup the completions API configuration w/ optional auth token and model name\n```sql\nSET VARIABLE openprompt_api_url = 'http://localhost:11434/v1/chat/completions';\nSET VARIABLE openprompt_api_token = 'your_api_key_here';\nSET VARIABLE openprompt_model_name = 'qwen2.5:0.5b';\n```\n\nAlternatively the following ENV variables can be used at runtime\n```\n   OPEN_PROMPT_API_URL='http://localhost:11434/v1/chat/completions'\n   OPEN_PROMPT_API_TOKEN='your_api_key_here'\n   OPEN_PROMPT_MODEL_NAME='qwen2.5:0.5b'\n   OPEN_PROMPT_API_TIMEOUT='30'\n```\n\nFor persistent usage, configure parameters using DuckDB SECRETS\n```sql\nCREATE SECRET IF NOT EXISTS open_prompt (\n      TYPE open_prompt,\n      PROVIDER config,\n      api_token 'your-api-token',\n      api_url 'http://localhost:11434/v1/chat/completions',\n      model_name 'qwen2.5:0.5b',\n      api_timeout '30'\n  );\n```\n\n\n### Usage\n```sql\nD SELECT open_prompt('Write a one-line poem about ducks') AS response;\n┌────────────────────────────────────────────────┐\n│                    response                    │\n│                    varchar                     │\n├────────────────────────────────────────────────┤\n│ Ducks quacking at dawn, swimming in the light. │\n└────────────────────────────────────────────────┘\n```\n\n#### JSON Structured Output\nFor supported models you can request structured JSON output by providing a schema\n\n```sql\nSET VARIABLE openprompt_api_url = 'http://localhost:11434/v1/chat/completions';\nSET VARIABLE openprompt_api_token = 'your_api_key_here';\nSET VARIABLE openprompt_model_name = 'llama3.2:3b';\n\nSELECT open_prompt('I want ice cream', json_schema := '{\n       \"type\": \"object\",\n       \"properties\": {\n         \"summary\": { \"type\": \"string\" },\n         \"sentiment\": { \"type\": \"string\", \"enum\": [\"pos\", \"neg\", \"neutral\"] }\n       },\n       \"required\": [\"summary\", \"sentiment\"],\n       \"additionalProperties\": false\n     }');\n```\n\nFor smaller models the `system_prompt` can be used to request JSON schema in _best-effort_ mode\n\n```sql\nSET VARIABLE openprompt_api_url = 'http://localhost:11434/v1/chat/completions';\nSET VARIABLE openprompt_api_token = 'your_api_key_here';\nSET VARIABLE openprompt_model_name = 'qwen2.5:1.5b';\nSELECT open_prompt('I want ice cream.',\n       system_prompt:='The respose MUST be a JSON with the following schema: {\n           \"type\": \"object\",\n           \"properties\": {\n             \"summary\": { \"type\": \"string\" },\n             \"sentiment\": { \"type\": \"string\", \"enum\": [\"pos\", \"neg\", \"neutral\"] }\n           },\n           \"required\": [\"summary\", \"sentiment\"],\n           \"additionalProperties\": false\n       }');\n```\n\n\n\u003cbr\u003e\n\n\u003cimg src=\"https://github.com/user-attachments/assets/824bfab2-aca6-4bd9-8a4a-bc01901fcd5b\" width=100 /\u003e\n\n### Ollama self-hosted\nTest the open_prompt extension using a local or remote Ollama with Completions API\n\n#### CPU only\n```\ndocker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama\n```\n#### Nvidia GPU\nInstall the Nvidia container toolkit. Run Ollama inside a Docker container\n```\ndocker run -d --gpus=all -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama\n```\n\n\u003cbr\u003e\n\n###### Disclaimers\n\n* Configuration and formats loosely inspired by the [Motherduck prompt()](https://motherduck.com/docs/sql-reference/motherduck-sql-reference/ai-functions/prompt/)\n\n\u003e DuckDB ® is a trademark of DuckDB Foundation. Motherduck ® is a trademark of the Motherduck Corporation. Any trademarks, service marks, and logos mentioned or depicted are the property of their respective owners. The use of any third-party trademarks, brand names, product names, and company names is purely informative or intended as parody and does not imply endorsement, affiliation, or association with the respective owners.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquackscience%2Fduckdb-extension-openprompt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fquackscience%2Fduckdb-extension-openprompt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fquackscience%2Fduckdb-extension-openprompt/lists"}