File size: 899 Bytes
d25ee4b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import re
def generate_sql(client,query,tables):
    
    out = "## Database tables\n"
    for table in tables:
        out += table.get('content')

    prompt = f"Generate an sql query to answer this question {query} \n Based on this database information \n {out} /no_think"
    print(prompt)
    response = client.chat.completions.create(
        model="Qwen/Qwen3-8B",  # nom du modèle à utiliser
        messages=[
            {"role": "system", "content": "You are an expert in generating sql query based on a given schema. You will output the generated query in <sql> </sql> tags"},
            {"role": "user", f"content": prompt}
        ],
        temperature=0.7
    )

    # Affichage du résultat
    txt = response.choices[0].message.content
    match = re.search(r"<sql>(.*?)</sql>", txt, re.DOTALL | re.IGNORECASE)
    if match:
        return match.group(1).strip()
    return None