Files
windmill/llm/sample_answers.yaml
HugoCasa 82612c35bd feat: copilot tokens streaming + cancel (#2107)
* feat: copilot tokens streaming + cancel

* fix: UI improvements
2023-08-17 14:21:42 +02:00

619 lines
29 KiB
YAML

- answer: |-
```python
import psycopg2
from typing import TypedDict
# Define the TypedDict for postgresql
class postgresql(TypedDict):
host: str
port: int
user: str
dbname: str
sslmode: str
password: str
def main(postgres: postgresql):
# Create connection string
conn_string = f"host={postgres['host']} dbname={postgres['dbname']} user={postgres['user']} password={postgres['password']}"
# Connect to the PostgreSQL server
conn = psycopg2.connect(conn_string)
# Create a cursor object
cur = conn.cursor()
# Execute the SQL query
cur.execute("SELECT * FROM orders")
# Fetch all the rows
rows = cur.fetchall()
# Close the cursor and connection
cur.close()
conn.close()
return rows
```
description: Connect to postgres and list the rows in the orders table
example_answer: |-
```python
import random
def main(name: str):
print("hello", name) # print hello name to the console
return random.randint(0, 100) # return a random number between 0 and 100
```
example_prompt: |-
Write a function in python called "main". The function should say hello to the passed name and return a random number between 0 and 100. Specify the parameter types. Do not call the main function.
You have access to the following resource types, if you need them, you have to define the TypedDict exactly as specified (class name has to be IN LOWERCASE) and add them as parameters: {resourceTypes}
Only use the ones you need. If the TypedDict name conflicts with the imported object, rename the imported object NOT THE TYPE.
lang: python3
template_prompt: |-
Write a function in python called "main". The function should {description}. Specify the parameter types. Do not call the main function.
You have access to the following resource types, if you need them, you have to define the TypedDict exactly as specified (class name has to be IN LOWERCASE) and add them as parameters: {resourceTypes}
Only use the ones you need. If the TypedDict name conflicts with the imported object, rename the imported object NOT THE TYPE.
template_system: |-
You write code as queried by the user. Only output code. Wrap the code like that:
```language
{code}
```
Put explanations directly in the code as comments.
type: gen
- answer: |-
```python
def main(num: int) -> int:
if num == 0:
return "Error: Division by zero is not allowed."
else:
return 3 / num
```
explanation: "The error occurs when the function tries to divide by zero, which is not allowed in mathematics. To fix this, we can add a condition to check if the number is zero before performing the division. If the number is zero, we can return an error message instead."
code: |-
def main(num: int) -> int:
return 3 / num
error: division by zero
example_answer: |-
```python
def main():
print("Hello world")
```
explanation: "The code should be wrapped it in a function called "main"."
example_prompt: |-
Here's my python3 code:
```python
print("Hello world")
```
Additional information: We have to export a "main" function and specify the parameter types but do not call it.
You have access to the following resource types, if you need them, you have to define the TypedDict exactly as specified (class name has to be IN LOWERCASE) and add them as parameters: {resourceTypes}
Only use the ones you need. If the TypedDict name conflicts with the imported object, rename the imported object NOT THE TYPE.
I get the following error: {"error":{"name":"ExecutionErr","message":"error during execution of the script:\\nNo main function found"}}`
Fix my code.
lang: python3
template_prompt: |-
Here's my python3 code:
```python
{code}
```
Additional information: We have to export a "main" function and specify the parameter types but do not call it.
You have access to the following resource types, if you need them, you have to define the TypedDict exactly as specified (class name has to be IN LOWERCASE) and add them as parameters: {resourceTypes}
Only use the ones you need. If the TypedDict name conflicts with the imported object, rename the imported object NOT THE TYPE.
I get the following error: {error}
Fix my code.
template_system: |-
You fix the code shared by the user. Only output code. Wrap the code like that:
```language
{code}
```
Explain the error and the fix in the following format:
explanation: "Here's the explanation"
Also put the explanations in the code as comments.
type: fix
- answer: |-
```python
def main(num: int) -> int:
# The function takes an integer as input,
# divides it by 16, and returns the result
return num / 16
```
code: |-
def main(num: int) -> int:
return num / 16
description: Comment my code
example_answer: |-
```python
import random
def main(name: str):
print("hello", name) # print hello name to the console
return random.randint(0, 100) # return a random number between 0 and 100
```
example_prompt: |-
Here's my python3 code:
```python
import random
def main(name: str):
print("hello", name)
return random.randint(0, 100)
```
Additional information: We have to export a "main" function and specify the parameter types but do not call it.
You have access to the following resource types, if you need them, you have to define the TypedDict exactly as specified (class name has to be IN LOWERCASE) and add them as parameters: {resourceTypes}
Only use the ones you need. If the TypedDict name conflicts with the imported object, rename the imported object NOT THE TYPE.
My instructions: add comments
lang: python3
template_prompt: |-
Here's my python3 code:
```python
{code}
```
Additional information: We have to export a "main" function and specify the parameter types but do not call it.
You have access to the following resource types, if you need them, you have to define the TypedDict exactly as specified (class name has to be IN LOWERCASE) and add them as parameters: {resourceTypes}
Only use the ones you need. If the TypedDict name conflicts with the imported object, rename the imported object NOT THE TYPE.
My instructions: {description}
template_system: |-
You write code as instructed by the user. Only output code. Wrap the code like that:
```language
{code}
```
Put explanations directly in the code as comments.
type: edit
- answer: |-
```go
package inner
import "errors" // import errors package for error handling
func main(number float64) (float64, error) {
if number == 0 { // check if the number is zero to avoid division by zero error
return 0, errors.New("division by zero") // return error if number is zero
}
result := number / 16 // divide the number by 16
return result, nil // return the result and nil error
}
```
description: Divide a number by 16
example_answer: |-
```go
package inner
import (
"fmt"
"math/rand"
)
func main(name string) (int, error) {
fmt.Println("hello", name) // print hello name to the console
return rand.Intn(100), nil // return a random number between 0 and 100
}
```
example_prompt: |-
Write a function in go called "main". The function should say hello to the passed name and return a random number between 0 and 100. Import the packages you need. The return type of the function has to be ({return_type}, error). The file package has to be "inner".
lang: go
template_prompt: |-
Write a function in go called "main". The function should {description}. Import the packages you need. The return type of the function has to be ({return_type}, error). The file package has to be "inner".
template_system: |-
You write code as queried by the user. Only output code. Wrap the code like that:
```language
{code}
```
Put explanations directly in the code as comments.
type: gen
- answer: |-
```typescript
import { toWords } from "npm:lodash"; // import the toWords function from lodash
export async function main(number: number): Promise<string> {
return toWords(number); // convert the number to words and return it
}
```
description: Convert a number to a word
example_answer: |-
```typescript
export async function main(name: string) {
console.log("hello", name) // print hello name to the console
return Math.floor(Math.random() * 100) // return a random number between 0 and 100
}
```
example_prompt: |-
Write a function in TypeScript called "main". The function should say hello to the passed name and return a random number between 0 and 100. Specify the parameter types. You are in a Deno environment. You can import deno libraries or you can also import npm libraries like that: "import ... from "npm:{package}";". Export the "main" function like this: "export async function main(...)". Do not call the main function.
You have access to the following resource types, if you need them, you have to define the type exactly as specified and add them as parameters: {resourceTypes}
Only use the ones you need. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE.
lang: deno
template_prompt: |-
Write a function in TypeScript called "main". The function should {description}. Specify the parameter types. You are in a Deno environment. You can import deno libraries or you can also import npm libraries like that: "import ... from "npm:{package}";". Export the "main" function like this: "export async function main(...)". Do not call the main function.
You have access to the following resource types, if you need them, you have to define the type exactly as specified and add them as parameters: {resourceTypes}
Only use the ones you need. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE.
template_system: |-
You write code as queried by the user. Only output code. Wrap the code like that:
```language
{code}
```
Put explanations directly in the code as comments.
type: gen
- answer: |-
```typescript
// Importing the required libraries
import { Client } from "https://deno.land/x/postgres/mod.ts";
type Postgresql = {
host: string,
port: number,
user: string,
dbname: string,
sslmode: string,
password: string
}
export async function main(postgres: Postgresql) {
// Create a new client using the provided Postgres details
const client = new Client({
hostname: postgres.host,
port: postgres.port,
user: postgres.user,
password: postgres.password,
database: postgres.dbname,
});
// Connect to the Postgres server
await client.connect();
// Query the "orders" table and get all rows
const result = await client.queryArray("SELECT * FROM orders;");
// Disconnect from the Postgres server
await client.end();
// Return the result of the query
return result.rows
}
```
description: Connect to postgres and list the rows in the orders table
example_answer: |-
```typescript
export async function main(name: string) {
console.log("hello", name) // print hello name to the console
return Math.floor(Math.random() * 100) // return a random number between 0 and 100
}
```
example_prompt: |-
Write a function in TypeScript called "main". The function should say hello to the passed name and return a random number between 0 and 100. Specify the parameter types. You are in a Deno environment. You can import deno libraries or you can also import npm libraries like that: "import ... from "npm:{package}";". Export the "main" function like this: "export async function main(...)". Do not call the main function.
You have access to the following resource types, if you need them, you have to define the type exactly as specified and add them as parameters: {resourceTypes}
Only use the ones you need. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE.
lang: deno
template_prompt: |-
Write a function in TypeScript called "main". The function should {description}. Specify the parameter types. You are in a Deno environment. You can import deno libraries or you can also import npm libraries like that: "import ... from "npm:{package}";". Export the "main" function like this: "export async function main(...)". Do not call the main function.
You have access to the following resource types, if you need them, you have to define the type exactly as specified and add them as parameters: {resourceTypes}
Only use the ones you need. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE.
template_system: |-
You write code as queried by the user. Only output code. Wrap the code like that:
```language
{code}
```
Put explanations directly in the code as comments.
type: gen
- answer: |-
```typescript
import { toWords } from 'number-to-words'; // npm library to convert numbers to words
export async function main(number: number): Promise<string> {
return toWords(number); // convert the number to a word and return it
}
```
description: Convert a number to a word
example_answer: |-
```typescript
export async function main(name: string) {
console.log("hello", name) // print hello name to the console
return Math.floor(Math.random() * 100) // return a random number between 0 and 100
}
```
example_prompt: |-
Write a function in TypeScript called "main". The function should say hello to the passed name and return a random number between 0 and 100. Specify the parameter types. You are in a Node.js environment. You can import npm libraries. Export the "main" function like this: "export async function main(...)". Do not call the main function.
You have access to the following resource types, if you need them, you have to define the type exactly as specified and add them as parameters: {resourceTypes}
Only use the ones you need. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE.
lang: bun
template_prompt: |-
Write a function in TypeScript called "main". The function should {description}. Specify the parameter types. You are in a Node.js environment. You can import npm libraries. Export the "main" function like this: "export async function main(...)". Do not call the main function.
You have access to the following resource types, if you need them, you have to define the type exactly as specified and add them as parameters: {resourceTypes}
Only use the ones you need. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE.
template_system: |-
You write code as queried by the user. Only output code. Wrap the code like that:
```language
{code}
```
Put explanations directly in the code as comments.
type: gen
- answer: |-
```sql
-- $1 role
-- $2 email
-- $3 disabled
-- $4 is_admin
-- $5 operator
-- $6 username
-- $7 created_at
-- $8 workspace_id
INSERT INTO usr (role, email, disabled, is_admin, operator, username, created_at, workspace_id)
VALUES ($1::varchar, $2::varchar, $3::boolean, $4::boolean, $5::boolean, $6::varchar, $7::timestamptz, $8::varchar)
```
description: Insert an a new user
example_answer: |-
```sql
-- $1 name
-- $2 price
INSERT INTO products (name, price) VALUES ($1::text, $2::numeric)
```
example_prompt: |-
Write SQL code for a PostgreSQL that should insert a name and a price into the products table. Arguments can be obtained directly in the statement with `$1::{type}`, `$2::{type}`, etc... Name the parameters by adding comments before the command like that: `-- $1 name1` or `-- $2 name = default` (one per row, do not include the type)
lang: postgresql
template_prompt: |-
Write SQL code for a PostgreSQL that should {description}. Arguments can be obtained directly in the statement with `$1::{type}`, `$2::{type}`, etc... Name the parameters by adding comments before the command like that: `-- $1 name1` or `-- $2 name = default` (one per row, do not include the type)
template_system: |-
You write code as queried by the user. Only output code. Wrap the code like that:
```language
{code}
```
Put explanations directly in the code as comments.
type: gen
- answer: |-
```sql
-- ? email (text)
-- ? name (text)
INSERT INTO users (email, name) VALUES (?, ?)
```
description: Insert an email and a name in the users table
example_answer: |-
```sql
-- ? name (text)
-- ? price (float)
INSERT INTO products (name, price) VALUES (?, ?)
```
example_prompt: |-
Write SQL code for MySQL that should insert a name and a price into the products table. Arguments can be obtained directly in the statement with ?. Name the parameters by adding comments before the command like that: -- ? name1 ({type}) (one per row)
lang: mysql
template_prompt: |-
Write SQL code for MySQL that should {description}. Arguments can be obtained directly in the statement with ?. Name the parameters by adding comments before the command like that: -- ? name1 ({type}) (one per row)
template_system: |-
You write code as queried by the user. Only output code. Wrap the code like that:
```language
{code}
```
Put explanations directly in the code as comments.
type: gen
- answer: |-
```bash
# shellcheck shell=bash
num="$1" # get the number argument
divided_num=$(echo "scale=2; $num / 16" | bc) # divide the number by 16 with 2 decimal places
echo $divided_num # print the result
```
description: Divide a number by 16
example_answer: |-
```shell
# shellcheck shell=bash
name="$1" # get the name argument
echo "hello $name" # print hello name
```
example_prompt: |-
Write bash code that should say hello to the passed name. 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.
lang: bash
template_prompt: |-
Write bash code that should {description}. 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.
template_system: |-
You write code as queried by the user. Only output code. Wrap the code like that:
```language
{code}
```
Put explanations directly in the code as comments.
type: gen
- answer: |-
```bash
# shellcheck shell=bash
app_path="$1" # Get the path to the python app
image_name="$2" # Get the name of the docker image
# Create a Dockerfile content for a Python app
dockerfile_content="FROM python:3.7
WORKDIR /app
COPY . /app
RUN pip install --no-cache-dir -r requirements.txt
CMD [\"python\", \"./your-daemon-or-script.py\"]"
# Write the Dockerfile content into a Dockerfile
echo "$dockerfile_content" > "$app_path/Dockerfile"
# Build the Docker image
docker build -t "$image_name" "$app_path"
```
This script will create a Dockerfile in the directory of the Python app, then it will build a Docker image with the specified image name. Please replace "your-daemon-or-script.py" with your actual python script name.
description: Write a docker image for a python app
example_answer: |-
```shell
# shellcheck shell=bash
name="$1" # get the name argument
echo "hello $name" # print hello name
```
example_prompt: |-
Write bash code that should say hello to the passed name. 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.
lang: bash
template_prompt: |-
Write bash code that should {description}. 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.
template_system: |-
You write code as queried by the user. Only output code. Wrap the code like that:
```language
{code}
```
Put explanations directly in the code as comments.
type: gen
- answer: |-
```typescript
type Github = {
token: string
}
// Here we define our function
export async function main(github: Github, owner: string, repo: string): Promise<number> {
// We will fetch the data from the GitHub API
const response = await fetch(`https://api.github.com/repos/${owner}/${repo}`, {
headers: {
'Authorization': `token ${github.token}`,
'Accept': 'application/vnd.github.v3+json'
}
});
// We will then parse the response as JSON
const data = await response.json();
// And finally return the number of stars
return data.stargazers_count;
}
```
This function will take in three parameters: a `Github` object (which contains the GitHub token), and two strings representing the owner of the repository and the repository name, respectively. The function will then fetch the data for the given repository from the GitHub API, parse the response as JSON, and return the number of stars the repository has.
description: Query the github api and return the number of stars of a repo
example_answer: |-
```typescript
export async function main() {
// fetch the data from jsonplaceholder
const res = await fetch("https://jsonplaceholder.typicode.com/todos/1", {
headers: { "Content-Type": "application/json" },
});
return res.json();
}
```
example_prompt: |-
Write a function in TypeScript called "main". The function should query sample data from jsonplaceholder. Specify the parameter types. You should use fetch and are not allowed to import any libraries. Export the "main" function like this: "export async function main(...)". Do not call the main function.
You have access to the following resource types, if you need them, you have to define the type exactly as specified and add them as parameters: {resourceTypes}
Only use the ones you need. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE.
lang: nativets
template_prompt: |-
Write a function in TypeScript called "main". The function should {description}. Specify the parameter types. You should use fetch and are not allowed to import any libraries. Export the "main" function like this: "export async function main(...)". Do not call the main function.
You have access to the following resource types, if you need them, you have to define the type exactly as specified and add them as parameters: {resourceTypes}
Only use the ones you need. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE.
template_system: |-
You write code as queried by the user. Only output code. Wrap the code like that:
```language
{code}
```
Put explanations directly in the code as comments.
type: gen
- answer: |-
```javascript
// Access the email from the context object
var email = ctx.email;
// Use the setValue function to set the value of the input field with id 'my_field' to the email
setValue('my_field', email);
```
description:
set the value of the input with id 'my_field' to the context variable
email
example_answer: |-
```javascript
// Access the email from the context object
var email = ctx.email;
// Use the setValue function to set the value of the input field with id 'my_field' to the email
setValue('my_field', email);
```
example_prompt: |-
Write client-side javascript code that should set the value of the input with id 'my_field' to the context variable email. You have access to a few helpers:
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)
Use the setTab function to manually set the tab of a Tab component: setTab(id: string, index: string)
Use the recompute function to recompute a component: recompute(id: string)
Use the getAgGrid function to get the ag-grid instance of a table: getAgGrid(id: string)
The setValue function is meant to set or force the value of a component: setValue(id: string, value: any).
lang: frontend
template_prompt: |-
Write client-side javascript code that should {description}. You have access to a few helpers:
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)
Use the setTab function to manually set the tab of a Tab component: setTab(id: string, index: string)
Use the recompute function to recompute a component: recompute(id: string)
Use the getAgGrid function to get the ag-grid instance of a table: getAgGrid(id: string)
The setValue function is meant to set or force the value of a component: setValue(id: string, value: any).
template_system: |-
You write code as queried by the user. Only output code. Wrap the code like that:
```language
{code}
```
Put explanations directly in the code as comments.
type: gen
- answer: |-
```sql
-- $1 username
SELECT
DATE_TRUNC('month', created_at) AS month,
COUNT(*)::float / COUNT(DISTINCT DATE_TRUNC('month', created_at)) AS avg_jobs_per_month
FROM
completed_job
WHERE
created_by = $1::varchar
GROUP BY
month
ORDER BY
month;
```
description:
compute the average number of completed jobs per month for the given
username
example_answer: |-
```sql
-- $1 name
-- $2 price
INSERT INTO products (name, price) VALUES ($1::text, $2::numeric)
```
example_prompt: |-
Write SQL code for a PostgreSQL that should insert a name and a price into the products table. Arguments can be obtained directly in the statement with `$1::{type}`, `$2::{type}`, etc... Name the parameters by adding comments before the command like that: `-- $1 name1` or `-- $2 name = default` (one per row, do not include the type)
lang: postgresql
template_prompt: |-
Write SQL code for a PostgreSQL that should {description}. Arguments can be obtained directly in the statement with `$1::{type}`, `$2::{type}`, etc... Name the parameters by adding comments before the command like that: `-- $1 name1` or `-- $2 name = default` (one per row, do not include the type)
template_system: |-
You write code as queried by the user. Only output code. Wrap the code like that:
```language
{code}
```
Put explanations directly in the code as comments.
type: gen
- answer: |-
```sql
SELECT is_secret FROM variable
```
explanation: "The `is_secret` column does not exist in the `account` table. Looking at your schema, it seems like the `is_secret` column is in the `variable` table, not the `account` table. So, you should select from the `variable` table instead."
code: |-
SELECT is_secret FROM account
error: 'ExecutionError: db error: ERROR: column "is_secret" does not exist'
example_answer: |-
```sql
select * from demo
```
explanation: "You're missing a "t" in "select"."
example_prompt: |-
Here's my PostgreSQL code:
```sql
selec * from demo
```
Additional information: Arguments can be obtained directly in the statement with `$1::{type}`, `$2::{type}`, etc... Name the parameters by adding comments before the command like that: `-- $1 name1` or `-- $2 name = default` (one per row, do not include the type)
I get the following error: {"error":{"name":"ExecutionErr","message":"error during execution of the script:\\ndb error: ERROR: syntax error at or near \\"selec\\""}}
Fix my code.
lang: postgresql
template_prompt: |-
Here's my PostgreSQL code:
```sql
{code}
```
Additional information: Arguments can be obtained directly in the statement with `$1::{type}`, `$2::{type}`, etc... Name the parameters by adding comments before the command like that: `-- $1 name1` or `-- $2 name = default` (one per row, do not include the type)
I get the following error: {error}
Fix my code.
template_system: |-
You fix the code shared by the user. Only output code. Wrap the code like that:
```language
{code}
```
Explain the error and the fix in the following format:
explanation: "Here's the explanation"
Also put the explanations in the code as comments.
type: fix