| from ctransformers import AutoModelForCausalLM |
| from fastapi import FastAPI |
| from pydantic import BaseModel |
|
|
| |
| llm = AutoModelForCausalLM.from_pretrained("sqlcoder-7b.Q4_K_S.gguf") |
|
|
| class Validation(BaseModel): |
| prompt: str |
|
|
| app = FastAPI() |
|
|
| @app.post("/generate_sql") |
| async def generate_sql(item: Validation): |
| |
| system_prompt = """### Task |
| Generate a SQL query to answer the following question: |
| `{question}` |
| |
| ### Database Schema |
| The query will run on a database with the following schema: |
| {schema} |
| |
| ###Instructions |
| -Understand the question and the database schema provided |
| -based on the given question and the database schema,generate a proper SQL |
| |
| ### Answer |
| Given the database schema, here is the SQL query that answers `{question}`: |
| ```sql |
| """ |
| |
| prompt = system_prompt.format(user_question="Your question here", table_metadata_string="Your schema here") |
| completion = llm(prompt) |
| return completion |
|
|