chore: remove outdated llm folder

This commit is contained in:
HugoCasa
2025-12-22 12:43:43 +01:00
parent 02bd9277fa
commit 55dfd0b6e1
10 changed files with 0 additions and 1678 deletions

3
llm/.gitignore vendored
View File

@@ -1,3 +0,0 @@
.venv
.env
**/__pycache__

View File

@@ -1,42 +0,0 @@
# Test sample queries of the AI feature
## Setup
Create a virtual environment `python -m venv .venv`, activate it `source .venv/bin/activate` and install the requirements `pip install -r requirements.txt`. Put your `OPENAI_API_KEY` in `.env`.
## Run
Run the script `python src/gen_samples.py` and check the results in `sample_answers.yaml`.
## Add queries
You can add more queries in `sample_queries.yaml`. There are three types of queries:
### Generate code from a prompt
```yaml
- type: gen
description: hello world
lang: python3
```
### Modifiy code according to a prompt
```yaml
- type: edit
description: comment
lang: python3
code: |-
print("hello world")
```
### Fix code given an error
```yaml
- type: fix
lang: python3
code: |-
def main():
return 3 / 0
error: division by zero
```

View File

@@ -1,81 +0,0 @@
const getWords = async () => {
const response = await fetch("http://localhost:3001/searchData");
const data: {
asks: {
summary: string;
app: string;
}[];
} = await response.json();
const words = data.asks
.map((a) => [
...a.summary.split(" ").map((w: string) => w.toLowerCase()),
...a.app.split(" ").map((w: string) => w.toLowerCase()),
])
.flat();
return words;
};
const generateQuery = async (words: string[]) => {
const word1 = words[Math.floor(Math.random() * words.length)];
const word2 = words[Math.floor(Math.random() * words.length)];
const word3 = words[Math.floor(Math.random() * words.length)];
const query = `${word1} ${word2} ${word3}`;
return query.substring(0, 3 + Math.random() * (query.length - 3));
};
async function sendRequest(q: string) {
const time = Date.now();
try {
await fetch(
"http://localhost:3001/scripts/query?" +
new URLSearchParams({
text: q,
})
);
return {
time: Date.now() - time,
error: false,
};
} catch (err) {
return {
time: Date.now() - time,
error: true,
};
}
}
async function benchmark() {
// first fetch to mitigate cold start
await fetch(
"http://localhost:3001/scripts/query?" +
new URLSearchParams({
text: "init",
})
);
const words = await getWords();
const tryouts = [1, 10, 100, 1000, 10000];
for (const tryout of tryouts) {
const requests: Promise<{
time: number;
error: boolean;
}>[] = [];
for (let i = 0; i < tryout; i++) {
const q = await generateQuery(words);
requests.push(sendRequest(q));
}
const startTime = Date.now();
const times = await Promise.all(requests);
const duration = Date.now() - startTime;
const avg = times.reduce((a, b) => a + b.time, 0) / times.length;
const errors = times.filter((t) => t.error).length;
console.log(`Average time for ${tryout} simultaneous requests: ${avg}ms`);
console.log(
`Total time for ${tryout} simultaneous requests: ${duration}ms`
);
console.log(`Number of errors: ${errors}`);
}
}
benchmark();

View File

@@ -1,6 +0,0 @@
openai==1.30.3
python-dotenv==1.0.0
pyyaml==6.0
tqdm==4.66.3
anyio>=4.4.0 # not directly required, pinned by Snyk to avoid a vulnerability
zipp>=3.19.1 # not directly required, pinned by Snyk to avoid a vulnerability

View File

@@ -1,804 +0,0 @@
- answer: |-
```python
from typing import List, Dict
import psycopg2
# Define the resource type for PostgreSQL
class postgresql(TypedDict):
host: str
port: int
user: str
dbname: str
sslmode: str
password: str
def main(db_config: postgresql) -> List[Dict]:
# Connect to the PostgreSQL database
conn = psycopg2.connect(
host=db_config['host'],
port=db_config['port'],
user=db_config['user'],
password=db_config['password'],
dbname=db_config['dbname'],
sslmode=db_config['sslmode']
)
# Create a cursor object
cursor = conn.cursor()
# Execute the query to fetch all rows from the orders table
cursor.execute("SELECT * FROM orders")
# Fetch all rows from the executed query
rows = cursor.fetchall()
# Get column names from the cursor description
colnames = [desc[0] for desc in cursor.description]
# Convert rows to a list of dictionaries
result = [dict(zip(colnames, row)) for row in rows]
# Close the cursor and connection
cursor.close()
conn.close()
return result
```
description: connect to postgres and list the rows in the orders table
lang: python3
template_prompt: |-
<contextual_information>
You have to write a function in Python called "main". Specify the parameter types. Do not call the main function. You should generally return the result.
The "main" function cannot be async. If you need to use async code, you can use the asyncio library.
You can take as parameters resources which are dictionaries containing credentials or configuration information. For Windmill to correctly detect the resources to be passed, the resource type name has to be exactly as specified in the following list:
<resourceTypes>
{resourceTypes}
</resourceTypes>
You need to define the type of the resources that are needed before the main function, but only include them if they are actually needed to achieve the function purpose.
The resource type name has to be exactly as specified (has to be IN LOWERCASE). If the type name conflicts with any imported methods, you have to rename the imported method with the conflicting name.
<contextual_information>
My instructions: {description}
template_system: |-
You are a helpful coding assistant for Windmill, a developer platform for running scripts. You write code as instructed by the user. Each user message includes some contextual information which should guide your answer.
Only output code. Wrap the code in a code block.
Put explanations directly in the code as comments.
Here's how interactions have to look like:
user: {sample_question}
assistant: ```language
{code}
```
type: gen
- answer: |-
```python
def main(num: int) -> float:
if num == 0:
raise ValueError("Division by zero is not allowed")
return 3 / num
```
<explanation>
The error occurs because dividing by zero is not allowed in mathematics and will raise a `ZeroDivisionError` in Python. To fix this, we need to check if `num` is zero before performing the division. If `num` is zero, we raise a `ValueError` with an appropriate message.
</explanation>
code: |-
def main(num: int) -> float:
return 3 / num
error: division by zero
lang: python3
template_prompt: |-
Here's my python3 code:
```python
{code}
```
<contextual_information>
You have to write a function in python called "main". Specify the parameter types. Do not call the main function. You should generally return the result.
The "main" function cannot be async. If you need to use async code, you can use the asyncio library.
You can take as parameters resources which are dictionaries containing credentials or configuration information. For Windmill to correctly detect the resources to be passed, the resource type name has to be exactly as specified in the following list:
<resourceTypes>
{resourceTypes}
</resourceTypes>
You need to define the type of the resources that are needed before the main function, but only include them if they are actually needed to achieve the function purpose.
The resource type name has to be exactly as specified (has to be IN LOEWRCASE). If the type name conflicts with any imported methods, you have to rename the imported method with the conflicting name.
<contextual_information>
I get the following error: {error}
Fix my code.
template_system: |-
You are a helpful coding assistant for Windmill, a developer platform for running scripts. You fix the code shared by the user. Each user message includes some contextual information which should guide your answer.
Only output code. Wrap the code in a code block.
Explain the error and the fix after generating the code inside an <explanation> tag.
Also put explanations directly in the code as comments.
Return the complete fixed code.
Here's how interactions have to look like:
user: {sample_question}
assistant: ```language
{code}
```
<explanation>{explanation}</explanation>
type: fix
- answer: |-
```python
def main(num: int) -> float:
# This function takes an integer 'num' as input and returns the result of dividing 'num' by 16.
return num / 16
```
code: |-
def main(num: int) -> float:
return num / 16
description: comment my code
lang: python3
template_prompt: |-
Here's my python3 code:
```python
{code}
```
<contextual_information>
You have to write a function in python called "main". Specify the parameter types. Do not call the main function. You should generally return the result.
The "main" function cannot be async. If you need to use async code, you can use the asyncio library.
You can take as parameters resources which are dictionaries containing credentials or configuration information. For Windmill to correctly detect the resources to be passed, the resource type name has to be exactly as specified in the following list:
<resourceTypes>
{resourceTypes}
</resourceTypes>
You need to define the type of the resources that are needed before the main function, but only include them if they are actually needed to achieve the function purpose.
The resource type name has to be exactly as specified (has to be IN LOEWRCASE). If the type name conflicts with any imported methods, you have to rename the imported method with the conflicting name.
<contextual_information>
My instructions: {description}
template_system: |-
You are a helpful coding assistant for Windmill, a developer platform for running scripts. You modify code as instructed by the user. Each user message includes some contextual information which should guide your answer.
Only output code. Wrap the code in a code block.
Put explanations directly in the code as comments.
Return the complete modified code.
Here's how interactions have to look like:
user: {sample_question}
assistant: ```language
{code}
```
type: edit
- answer: |-
```go
package inner
import (
"errors"
)
// main function divides a number by 16 and returns the result and an error if any
func main(number float64) (float64, error) {
if number == 0 {
return 0, errors.New("division by zero is not allowed")
}
result := number / 16
return result, nil
}
```
description: divide a number by 16
lang: go
template_prompt: |-
Here's my go code:
```go
{code}
```
<contextual_information>
You have to write go code and export a "main" function. Import the packages you need. The return type of the function has to be ({return_type}, error). The file package has to be "inner"
</contextual_information>
My instructions: {description}
template_system: |-
You are a helpful coding assistant for Windmill, a developer platform for running scripts. You write code as instructed by the user. Each user message includes some contextual information which should guide your answer.
Only output code. Wrap the code in a code block.
Put explanations directly in the code as comments.
Here's how interactions have to look like:
user: {sample_question}
assistant: ```language
{code}
```
type: gen
- answer: |-
```typescript
// Importing the 'number-to-words' npm package to convert numbers to words
import { toWords } from "npm:number-to-words";
// Define the main function with the appropriate parameter types
export async function main(number: number): Promise<string> {
// Convert the number to words and return the result
return toWords(number);
}
```
description: convert a number to a word
lang: deno
template_prompt: |-
<contextual_information>
You have to write TypeScript code and export a "main" function like this: "export async function main(...)" and specify the parameter types but do not call it. You should generally return the result.
You can import deno libraries or you can also import npm libraries like that: "import ... from "npm:{package}";". The fetch standard method is available globally.
You can take as parameters resources which are dictionaries containing credentials or configuration information. For Windmill to correctly detect the resources to be passed, the resource type name has to be exactly as specified in the following list:
<resourceTypes>
{resourceTypes}
</resourceTypes>
You need to define the type of the resources that are needed before the main function, but only include them if they are actually needed to achieve the function purpose.
The resource type name has to be exactly as specified (no resource suffix). If the type name conflicts with any imported methods, you have to rename the imported method with the conflicting name.
</contextual_information>
My instructions: {description}
template_system: |-
You are a helpful coding assistant for Windmill, a developer platform for running scripts. You write code as instructed by the user. Each user message includes some contextual information which should guide your answer.
Only output code. Wrap the code in a code block.
Put explanations directly in the code as comments.
Here's how interactions have to look like:
user: {sample_question}
assistant: ```language
{code}
```
type: gen
- answer: |-
```typescript
import { Client } from "npm:pg";
type Postgresql = {
host: string,
port: number,
user: string,
dbname: string,
sslmode: string,
password: string
};
export async function main(postgresql: Postgresql) {
const client = new Client({
host: postgresql.host,
port: postgresql.port,
user: postgresql.user,
database: postgresql.dbname,
password: postgresql.password,
ssl: { rejectUnauthorized: postgresql.sslmode === "require" }
});
await client.connect();
try {
const res = await client.query('SELECT * FROM orders');
return res.rows;
} finally {
await client.end();
}
}
```
description: connect to postgres and list the rows in the orders table
lang: deno
template_prompt: |-
<contextual_information>
You have to write TypeScript code and export a "main" function like this: "export async function main(...)" and specify the parameter types but do not call it. You should generally return the result.
You can import deno libraries or you can also import npm libraries like that: "import ... from "npm:{package}";". The fetch standard method is available globally.
You can take as parameters resources which are dictionaries containing credentials or configuration information. For Windmill to correctly detect the resources to be passed, the resource type name has to be exactly as specified in the following list:
<resourceTypes>
{resourceTypes}
</resourceTypes>
You need to define the type of the resources that are needed before the main function, but only include them if they are actually needed to achieve the function purpose.
The resource type name has to be exactly as specified (no resource suffix). If the type name conflicts with any imported methods, you have to rename the imported method with the conflicting name.
</contextual_information>
My instructions: {description}
template_system: |-
You are a helpful coding assistant for Windmill, a developer platform for running scripts. You write code as instructed by the user. Each user message includes some contextual information which should guide your answer.
Only output code. Wrap the code in a code block.
Put explanations directly in the code as comments.
Here's how interactions have to look like:
user: {sample_question}
assistant: ```language
{code}
```
type: gen
- answer: |-
```typescript
// No resources are needed for this function
export async function main(number: number): Promise<string> {
const units = ["", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"];
const teens = ["Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"];
const tens = ["", "", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety"];
const thousands = ["", "Thousand", "Million", "Billion"];
if (number === 0) return "Zero";
let word = "";
let thousandCounter = 0;
while (number > 0) {
if (number % 1000 !== 0) {
word = convertHundreds(number % 1000) + thousands[thousandCounter] + " " + word;
}
number = Math.floor(number / 1000);
thousandCounter++;
}
return word.trim();
function convertHundreds(num: number): string {
let result = "";
if (num > 99) {
result += units[Math.floor(num / 100)] + " Hundred ";
num %= 100;
}
if (num > 19) {
result += tens[Math.floor(num / 10)] + " ";
num %= 10;
}
if (num > 9) {
result += teens[num - 10] + " ";
} else if (num > 0) {
result += units[num] + " ";
}
return result;
}
}
```
description: convert a number to a word
lang: bun
template_prompt: |-
<contextual_information>
You have to write TypeScript code and export a "main" function like this: "export async function main(...)" and specify the parameter types but do not call it. You should generally return the result.
The fetch standard method is available globally.
You can take as parameters resources which are dictionaries containing credentials or configuration information. For Windmill to correctly detect the resources to be passed, the resource type name has to be exactly as specified in the following list:
<resourceTypes>
{resourceTypes}
</resourceTypes>
You need to define the type of the resources that are needed before the main function, but only include them if they are actually needed to achieve the function purpose.
The resource type name has to be exactly as specified (no resource suffix). If the type name conflicts with any imported methods, you have to rename the imported method with the conflicting name.
</contextual_information>
My instructions: {description}
template_system: |-
You are a helpful coding assistant for Windmill, a developer platform for running scripts. You write code as instructed by the user. Each user message includes some contextual information which should guide your answer.
Only output code. Wrap the code in a code block.
Put explanations directly in the code as comments.
Here's how interactions have to look like:
user: {sample_question}
assistant: ```language
{code}
```
type: gen
- answer: |-
```sql
-- $1 role
-- $2 email
-- $3 disabled = false
-- $4 is_admin = false
-- $5 operator = false
-- $6 username
-- $7 workspace_id
INSERT INTO usr (role, email, disabled, is_admin, operator, username, created_at, workspace_id)
VALUES ($1::varchar, $2::varchar, $3::bool, $4::bool, $5::bool, $6::varchar, now(), $7::varchar);
```
description: insert an a new user
lang: postgresql
template_prompt: |-
<contextual_information>
You have to write a statement for PostgreSQL. Arguments can be obtained directly in the statement with `$1::{type}`, `$2::{type}`, etc... Name the parameters (without specifying the type) by adding comments before the statement like that: `-- $1 name1` or `-- $2 name = default` (one per row)
</contextual_information>
My instructions: {description}
template_system: |-
You are a helpful coding assistant for Windmill, a developer platform for running scripts. You write code as instructed by the user. Each user message includes some contextual information which should guide your answer.
Only output code. Wrap the code in a code block.
Put explanations directly in the code as comments.
Here's how interactions have to look like:
user: {sample_question}
assistant: ```language
{code}
```
type: gen
- answer: |-
```sql
-- ? email (VARCHAR)
-- ? name (VARCHAR)
INSERT INTO users (email, name) VALUES (?, ?);
```
description: insert an email and a name in the users table
lang: mysql
template_prompt: |-
<contextual_information>
You have to write a statement for MySQL. Arguments can be obtained directly in the statement with ?. Name the parameters by adding comments before the statement like that: `-- ? name1 ({type})` or `-- ? name2 ({type}) = default` (one per row)
</contextual_information>
My instructions: {description}
template_system: |-
You are a helpful coding assistant for Windmill, a developer platform for running scripts. You write code as instructed by the user. Each user message includes some contextual information which should guide your answer.
Only output code. Wrap the code in a code block.
Put explanations directly in the code as comments.
Here's how interactions have to look like:
user: {sample_question}
assistant: ```language
{code}
```
type: gen
- answer: |-
```sql
-- @email (STRING)
-- @name (STRING)
INSERT INTO users (email, name)
VALUES (@email, @name);
```
description: insert an email and a name in the users table
lang: bigquery
template_prompt: |-
<contextual_information>
You have to write a statement for BigQuery. You can define arguments by adding comments before the statement like that: `-- @name1 ({type})` or `-- @name2 ({type}) = default` (one per row). They can then be obtained directly in the statement with `@name1`, `@name2`, etc....
</contextual_information>
My instructions: {description}
template_system: |-
You are a helpful coding assistant for Windmill, a developer platform for running scripts. You write code as instructed by the user. Each user message includes some contextual information which should guide your answer.
Only output code. Wrap the code in a code block.
Put explanations directly in the code as comments.
Here's how interactions have to look like:
user: {sample_question}
assistant: ```language
{code}
```
type: gen
- answer: |-
```sql
-- ? email (STRING)
-- ? name (STRING)
INSERT INTO users (email, name) VALUES (?, ?);
```
description: insert an email and a name in the users table
lang: snowflake
template_prompt: |-
<contextual_information>
You have to write a statement for Snowflake. Arguments can be obtained directly in the statement with ?. Name the parameters by adding comments before the statement like that: `-- ? name1 ({type})` or `-- ? name2 ({type}) = default` (one per row)
</contextual_information>
My instructions: {description}
template_system: |-
You are a helpful coding assistant for Windmill, a developer platform for running scripts. You write code as instructed by the user. Each user message includes some contextual information which should guide your answer.
Only output code. Wrap the code in a code block.
Put explanations directly in the code as comments.
Here's how interactions have to look like:
user: {sample_question}
assistant: ```language
{code}
```
type: gen
- answer: |-
```graphql
mutation CreateUser($email: String!, $name: String!) {
createUser(email: $email, name: $name) {
id
email
name
}
}
```
description: create a new user with an email and a name
lang: graphql
template_prompt: |-
<contextual_information>
You have to write a query for GraphQL. Add the needed arguments as query parameters.
</contextual_information>
My instructions: {description}
template_system: |-
You are a helpful coding assistant for Windmill, a developer platform for running scripts. You write code as instructed by the user. Each user message includes some contextual information which should guide your answer.
Only output code. Wrap the code in a code block.
Put explanations directly in the code as comments.
Here's how interactions have to look like:
user: {sample_question}
assistant: ```language
{code}
```
type: gen
- answer: |-
```bash
# Get the first argument
var1="$1"
# Divide the number by 16
result=$((var1 / 16))
# Print the result
echo "$result"
```
description: divide a number by 16
lang: bash
template_prompt: |-
<contextual_information>
You have to write bash code. Do not include "#!/bin/bash". Arguments are always string and can only be obtained with "var1="$1"", "var2="$2"", etc... You do not need to check if the arguments are present.
</contextual_information>
My instructions: {description}
template_system: |-
You are a helpful coding assistant for Windmill, a developer platform for running scripts. You write code as instructed by the user. Each user message includes some contextual information which should guide your answer.
Only output code. Wrap the code in a code block.
Put explanations directly in the code as comments.
Here's how interactions have to look like:
user: {sample_question}
assistant: ```language
{code}
```
type: gen
- answer: |-
```powershell
param(
[int]$Number # Define the parameter to accept an integer input
)
# Divide the number by 16 and store the result
$Result = $Number / 16
# Output the result
$Result
```
description: divide a number by 16
lang: powershell
template_prompt: |-
<contextual_information>
You have to write Powershell code. Arguments can be obtained by calling the param function on the first line like that: `param($ParamName1, $ParamName2 = "default value", [{type}]$ParamName3, ...)`
</contextual_information>
My instructions: {description}
template_system: |-
You are a helpful coding assistant for Windmill, a developer platform for running scripts. You write code as instructed by the user. Each user message includes some contextual information which should guide your answer.
Only output code. Wrap the code in a code block.
Put explanations directly in the code as comments.
Here's how interactions have to look like:
user: {sample_question}
assistant: ```language
{code}
```
type: gen
- answer: |-
```bash
# Get the arguments
app_name="$1"
python_version="$2"
# Create a Dockerfile
cat <<EOF > Dockerfile
# Use the specified Python version as the base image
FROM python:$python_version
# Set the working directory in the container
WORKDIR /usr/src/app
# Copy the current directory contents into the container at /usr/src/app
COPY . .
# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME $app_name
# Run app.py when the container launches
CMD ["python", "app.py"]
EOF
```
description: write a docker image for a python app
lang: bash
template_prompt: |-
<contextual_information>
You have to write bash code. Do not include "#!/bin/bash". Arguments are always string and can only be obtained with "var1="$1"", "var2="$2"", etc... You do not need to check if the arguments are present.
</contextual_information>
My instructions: {description}
template_system: |-
You are a helpful coding assistant for Windmill, a developer platform for running scripts. You write code as instructed by the user. Each user message includes some contextual information which should guide your answer.
Only output code. Wrap the code in a code block.
Put explanations directly in the code as comments.
Here's how interactions have to look like:
user: {sample_question}
assistant: ```language
{code}
```
type: gen
- answer: |-
```typescript
// Define the type for the Github resource
type Github = {
token: string
};
// Define the main function
export async function main(github: Github, owner: string, repo: string): Promise<number> {
const url = `https://api.github.com/repos/${owner}/${repo}`;
const response = await fetch(url, {
headers: {
'Authorization': `token ${github.token}`,
'Accept': 'application/vnd.github.v3+json'
}
});
if (!response.ok) {
throw new Error(`Error fetching repository data: ${response.statusText}`);
}
const data = await response.json();
return data.stargazers_count;
}
```
description: query the github api and return the number of stars of a repo
lang: nativets
template_prompt: |-
<contextual_information>
You have to write TypeScript code and export a "main" function like this: "export async function main(...)" and specify the parameter types but do not call it. You should generally return the result.
You should use fetch and are not allowed to import any libraries.
You can take as parameters resources which are dictionaries containing credentials or configuration information. For Windmill to correctly detect the resources to be passed, the resource type name has to be exactly as specified in the following list:
<resourceTypes>
{resourceTypes}
</resourceTypes>
You need to define the type of the resources that are needed before the main function, but only include them if they are actually needed to achieve the function purpose.
The resource type name has to be exactly as specified (no resource suffix).
</contextual_information>
My instructions: {description}
template_system: |-
You are a helpful coding assistant for Windmill, a developer platform for running scripts. You write code as instructed by the user. Each user message includes some contextual information which should guide your answer.
Only output code. Wrap the code in a code block.
Put explanations directly in the code as comments.
Here's how interactions have to look like:
user: {sample_question}
assistant: ```language
{code}
```
type: gen
- answer: |-
```javascript
// Set the value of the input with id 'my_field' to the context variable email
document.getElementById('my_field').value = ctx.email;
```
description: set the value of the input with id 'my_field' to the context variable
email
lang: frontend
template_prompt: |-
Write client-side javascript code that should {description}.
<contextual_information>
You can access the context object with the ctx global variable.
The app state is a store that can be used to store data. You can access and update the state object with the state global variable like this: state.foo = 'bar'
You can use the goto function to navigate to a specific URL: goto(path: string, newTab?: boolean)
You can use the openModal and closeModal functions to open and close a modal: openModal(id: string), closeModal(id: string)
You can use the setTab function to manually set the tab of a Tab component: setTab(id: string, index: string)
You can use the recompute function to recompute a component: recompute(id: string)
You can use the getAgGrid function to get the ag-grid instance of a table: getAgGrid(id: string)
You can use the setSelectedIndex function to select a row in a table or an AG Grid table: setSelectedIndex(id: string, index: number)
The setValue function is meant to set or force the value of a component: setValue(id: string, value: any)
You can validate a specific field of a form: validate(id: string, key: string)
You can validate all fields of a form: validateAll(id: string, key: string)
You can invalidate a specific field of a form: invalidate(id: string, key: string, error: string)
</contextual_information>
template_system: |-
You are a helpful coding assistant for Windmill, a developer platform for running scripts. You write code as instructed by the user. Each user message includes some contextual information which should guide your answer.
Only output code. Wrap the code in a code block.
Put explanations directly in the code as comments.
Here's how interactions have to look like:
user: {sample_question}
assistant: ```language
{code}
```
type: gen
- answer: |-
```sql
-- $1 username
SELECT AVG(job_count) AS average_jobs_per_month
FROM (
SELECT DATE_TRUNC('month', created_at) AS month, COUNT(*) AS job_count
FROM completed_job
WHERE created_by = $1::varchar
GROUP BY month
) AS monthly_jobs;
```
description: compute the average number of completed jobs per month for the given
username
lang: postgresql
template_prompt: |-
<contextual_information>
You have to write a statement for PostgreSQL. Arguments can be obtained directly in the statement with `$1::{type}`, `$2::{type}`, etc... Name the parameters (without specifying the type) by adding comments before the statement like that: `-- $1 name1` or `-- $2 name = default` (one per row)
</contextual_information>
My instructions: {description}
template_system: |-
You are a helpful coding assistant for Windmill, a developer platform for running scripts. You write code as instructed by the user. Each user message includes some contextual information which should guide your answer.
Only output code. Wrap the code in a code block.
Put explanations directly in the code as comments.
Here's how interactions have to look like:
user: {sample_question}
assistant: ```language
{code}
```
type: gen
- answer: |-
```sql
-- $1 owner
SELECT is_secret FROM variable WHERE owner = $1::varchar
```
<explanation>
The error occurred because the column "is_secret" does not exist in the "account" table. According to the provided database schema, the "is_secret" column is in the "variable" table. The fixed code selects "is_secret" from the correct table and includes a parameter for filtering by the "owner" column.
</explanation>
code: |-
SELECT is_secret FROM account
error: 'ExecutionError: db error: ERROR: column "is_secret" does not exist'
lang: postgresql
template_prompt: |-
Here's my PostgreSQL code:
```sql
{code}
```
<contextual_information>
Arguments can be obtained directly in the statement with `$1::{type}`, `$2::{type}`, etc... Name the parameters (without specifying the type) by adding comments before the statement like that: `-- $1 name1` or `-- $2 name = default` (one per row)
</contextual_information>
I get the following error: {error}
Fix my code.
template_system: |-
You are a helpful coding assistant for Windmill, a developer platform for running scripts. You fix the code shared by the user. Each user message includes some contextual information which should guide your answer.
Only output code. Wrap the code in a code block.
Explain the error and the fix after generating the code inside an <explanation> tag.
Also put explanations directly in the code as comments.
Return the complete fixed code.
Here's how interactions have to look like:
user: {sample_question}
assistant: ```language
{code}
```
<explanation>{explanation}</explanation>
type: fix
- answer: |-
```php
<?php
// require:
// stripe/stripe-php
if (!class_exists('Stripe')) {
class Stripe {
public string $token;
}
}
function main(Stripe $stripe): array {
\Stripe\Stripe::setApiKey($stripe->token);
$customers = \Stripe\Customer::all();
return $customers->data;
}
```
description: list all customers from stripe
lang: php
template_prompt: |-
<contextual_information>
You have to write a function in php called "main". Specify the parameter types. Do not call the main function. You should generally return the result. The script must start with `<?php`.
You can take as parameters resources which are classes containing credentials or configuration information. For Windmill to correctly detect the resources to be passed, the resource type name has to be exactly as specified in the following list:
<resourceTypes>
{resourceTypes}
</resourceTypes>
You need to define the type of the resources that are needed before the main function, but only include them if they are actually needed to achieve the function purpose.
Before defining each type, check if the class already exists using class_exists.
The resource type name has to be exactly as specified.
If you need to import libraries, you need to specify them as comments in the following manner before the main function:
```
// require:
// mylibrary/mylibrary
// myotherlibrary/myotherlibrary@optionalversion
```
No need to require autoload, it is already done.
<contextual_information>
My instructions: {description}
template_system: |-
You are a helpful coding assistant for Windmill, a developer platform for running scripts. You write code as instructed by the user. Each user message includes some contextual information which should guide your answer.
Only output code. Wrap the code in a code block.
Put explanations directly in the code as comments.
Here's how interactions have to look like:
user: {sample_question}
assistant: ```language
{code}
```
type: gen

View File

@@ -1,69 +0,0 @@
- lang: python3
type: gen
description: connect to postgres and list the rows in the orders table
- lang: python3
type: fix
code: |-
def main(num: int) -> float:
return 3 / num
error: division by zero
- lang: python3
type: edit
code: |-
def main(num: int) -> float:
return num / 16
description: comment my code
- lang: go
type: gen
description: divide a number by 16
- lang: deno
type: gen
description: convert a number to a word
- lang: deno
type: gen
description: connect to postgres and list the rows in the orders table
- lang: bun
type: gen
description: convert a number to a word
- lang: postgresql
type: gen
description: insert an a new user
- lang: mysql
type: gen
description: insert an email and a name in the users table
- lang: bigquery
type: gen
description: insert an email and a name in the users table
- lang: snowflake
type: gen
description: insert an email and a name in the users table
- lang: graphql
type: gen
description: create a new user with an email and a name
- lang: bash
type: gen
description: divide a number by 16
- lang: powershell
type: gen
description: divide a number by 16
- lang: bash
type: gen
description: write a docker image for a python app
- lang: nativets
type: gen
description: query the github api and return the number of stars of a repo
- lang: frontend
type: gen
description: set the value of the input with id 'my_field' to the context variable email
- lang: postgresql
type: gen
description: compute the average number of completed jobs per month for the given username
- lang: postgresql
type: fix
code: |-
SELECT is_secret FROM account
error: |-
ExecutionError: db error: ERROR: column "is_secret" does not exist
- lang: php
type: gen
description: list all customers from stripe

View File

View File

@@ -1,162 +0,0 @@
import argparse
import yaml
from dotenv import load_dotenv
from tqdm import tqdm
from test_data import RESOURCE_TYPES, DB_SCHEMA
load_dotenv()
import openai
import re
from typing import TypedDict, Tuple
class Literal(str):
pass
def literal_presenter(dumper, data):
return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|")
yaml.add_representer(Literal, literal_presenter)
class Prompt(TypedDict):
prompt: str
class PromptsConfig(TypedDict):
prompts: dict[str, Prompt]
system: str
class Query(TypedDict):
description: str
type: str
lang: str
code: str
error: str
def get_prompts(
prompts_path: str,
) -> Tuple[PromptsConfig, PromptsConfig, PromptsConfig]:
GEN_CONFIG = None
EDIT_CONFIG = None
FIX_CONFIG = None
with open(prompts_path + "/gen.yaml") as f:
GEN_CONFIG = yaml.safe_load(f)
with open(prompts_path + "/edit.yaml") as f:
EDIT_CONFIG = yaml.safe_load(f)
with open(prompts_path + "/fix.yaml") as f:
FIX_CONFIG = yaml.safe_load(f)
return GEN_CONFIG, EDIT_CONFIG, FIX_CONFIG
def get_queries(queries_path: str) -> list[Query]:
with open(queries_path) as f:
return yaml.safe_load(f)
def prepare_prompt(
query: Query,
GEN_CONFIG: PromptsConfig,
EDIT_CONFIG: PromptsConfig,
FIX_CONFIG: PromptsConfig,
):
system = ""
prompt = ""
template_prompt = ""
if query["type"] == "gen":
system = GEN_CONFIG["system"]
template_prompt = GEN_CONFIG["prompts"][query["lang"]]["prompt"]
prompt = template_prompt.replace("{description}", query["description"])
elif query["type"] == "edit":
system = EDIT_CONFIG["system"]
template_prompt = EDIT_CONFIG["prompts"][query["lang"]]["prompt"]
prompt = template_prompt.replace("{description}", query["description"]).replace(
"{code}", query["code"]
)
elif query["type"] == "fix":
system = FIX_CONFIG["system"]
template_prompt = FIX_CONFIG["prompts"][query["lang"]]["prompt"]
prompt = template_prompt.replace("{error}", query["error"]).replace(
"{code}", query["code"]
)
if query["lang"] in ["deno", "bun", "nativets"]:
prompt = prompt.replace("{resourceTypes}", RESOURCE_TYPES["typescript"])
elif query["lang"] == "python3":
prompt = prompt.replace("{resourceTypes}", RESOURCE_TYPES["python"])
elif query["lang"] == "php":
prompt = prompt.replace("{resourceTypes}", RESOURCE_TYPES["php"])
if query["lang"] in ["postgresql"]:
prompt = (
prompt
+ "\nHere's the database schema, each column is in the format [name, type, required, default?]: <dbschema>\n"
+ DB_SCHEMA
+ "\n</dbschema>"
)
return system, prompt, template_prompt
def format_literal(answer: str):
return re.sub("[^\\S\n]+\n", "\n", answer).replace("\t", " ")
def gen_samples(queries_path: str, answers_path: str, prompts_path: str):
GEN_CONFIG, EDIT_CONFIG, FIX_CONFIG = get_prompts(prompts_path)
queries = get_queries(queries_path)
answers = []
for query in tqdm(queries):
(system, prompt, template_prompt) = prepare_prompt(
query, GEN_CONFIG, EDIT_CONFIG, FIX_CONFIG
)
client = openai.OpenAI()
chat_completion = client.chat.completions.create(
model="gpt-4o-2024-05-13",
messages=[
{"role": "system", "content": system},
{"role": "user", "content": prompt},
],
temperature=0,
max_tokens=2048,
seed=42,
)
answer = {
**query,
"answer": Literal(format_literal(chat_completion.choices[0].message.content)), # type: ignore
"template_system": Literal(format_literal(system)),
"template_prompt": Literal(format_literal(template_prompt)),
}
if "code" in query:
answer["code"] = Literal(format_literal(query["code"]))
answers.append(answer)
with open(answers_path, "w") as f:
yaml.dump(answers, f)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Process some integers.")
parser.add_argument("--queries_path", type=str, default="./sample_queries.yaml")
parser.add_argument("--answers_path", type=str, default="./sample_answers.yaml")
parser.add_argument(
"--prompts_path",
type=str,
default="../frontend/src/lib/components/copilot/prompts",
)
args = parser.parse_args()
gen_samples(args.queries_path, args.answers_path, args.prompts_path)

File diff suppressed because one or more lines are too long

View File

@@ -1 +0,0 @@
3.10.4