File size: 1,110 Bytes
bf9ae34 5e7d2c0 bf9ae34 fa810c7 5e7d2c0 bf9ae34 5e7d2c0 bf9ae34 ed6d964 bf9ae34 ed6d964 7368af4 bf9ae34 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
from ctransformers import AutoModelForCausalLM
from fastapi import FastAPI
from pydantic import BaseModel
# Model loading with the new model name
llm = AutoModelForCausalLM.from_pretrained("sqlcoder-7b.Q4_K_S.gguf")
class Validation(BaseModel):
prompt: str # Assuming this includes both user_question and table_metadata_string
app = FastAPI()
@app.post("/generate_sql")
async def generate_sql(item: Validation):
# Updated system prompt
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
"""
# Format the actual prompt using item.prompt
prompt = system_prompt.format(user_question="Your question here", table_metadata_string="Your schema here")
completion = llm(prompt)
return completion
|