tdoehmen commited on
Commit
a148b10
1 Parent(s): 57816fc
Files changed (1) hide show
  1. app.py +26 -12
app.py CHANGED
@@ -1,30 +1,44 @@
1
  import streamlit as st
2
  import requests
3
 
4
- def generate_prompt(question, schema):
5
- instruction = f"""Your task is to generate valid duckdb SQL to answer the following question{"" if (schema == "") else ", given a duckdb database schema."}"""
6
- input_text = f"""
7
- {schema}
8
-
9
- Generate a SQL query that answers the question `{question}`.
10
- """
11
- return f"""### Instruction:\n{instruction}\n\n### Input:\n{input_text}\n### Response:\n"""
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  def generate_sql(question, schema):
15
  prompt = generate_prompt(question, schema)
16
  s = requests.Session()
17
- api_base = "https://text-motherduck-cl7b-chat-fp16-4vycuix6qcp2.octoai.run/v1"
18
- url = f"{api_base}/completions"
19
  body = {
20
  "model": "motherduck-sql-fp16",
21
  "prompt": prompt,
22
  "temperature": 0.1,
23
  "max_tokens": 200,
24
- "stop":'<s>'
 
25
  }
 
26
 
27
- with s.post(url, json=body) as resp:
28
  return resp.json()["choices"][0]["text"]
29
 
30
  st.title("DuckDB-NSQL-7B Demo")
 
1
  import streamlit as st
2
  import requests
3
 
 
 
 
 
 
 
 
 
4
 
5
+ PROMPT_TEMPLATE = """### Instruction:\n{instruction}\n\n### Input:\n{input}{context}\n### Question:\n{question}\n\n### Response:\n"""
6
+ INSTRUCTION_TEMPLATE = """Your task is to generate valid duckdb SQL to answer the following question{has_schema}""" # noqa: E501
7
+
8
+ def generate_prompt(question, schema):
9
+ input = ""
10
+ if schema:
11
+ input = """Here is the database schema that the SQL query will run on:\n{schema}\n""".format( # noqa: E501
12
+ schema=schema
13
+ )
14
+ prompt = PROMPT_TEMPLATE.format(
15
+ instruction = INSTRUCTION_TEMPLATE.format(
16
+ has_schema="."
17
+ if schema == ""
18
+ else ", given a duckdb database schema."
19
+ ),
20
+ context="",
21
+ input=input,
22
+ question=question + ". Use DuckDB shorthand if possible.",
23
+ )
24
+ return prompt
25
 
26
  def generate_sql(question, schema):
27
  prompt = generate_prompt(question, schema)
28
  s = requests.Session()
29
+ api_base = "https://text-motherduck-sql-fp16-4vycuix6qcp2.octoai.run"
30
+ url = f"{api_base}/v1/completions"
31
  body = {
32
  "model": "motherduck-sql-fp16",
33
  "prompt": prompt,
34
  "temperature": 0.1,
35
  "max_tokens": 200,
36
+ "stop":'<s>',
37
+ "n": 1
38
  }
39
+ headers = {"Authorization": f"Bearer {st.secrets['octoml_token']}"}
40
 
41
+ with s.post(url, json=body, headers=headers) as resp:
42
  return resp.json()["choices"][0]["text"]
43
 
44
  st.title("DuckDB-NSQL-7B Demo")