feat: upgrade to gpt-4-turbo (#2655)

This commit is contained in:
HugoCasa
2023-11-20 12:54:22 +01:00
committed by GitHub
parent c2598b3304
commit 8ea98c2c8d
15 changed files with 431 additions and 314 deletions
@@ -368,7 +368,7 @@
Context: {lang === 'graphql' ? 'GraphQL' : 'DB'} schema
</p>
<Tooltip>
In order to better generate the script, we pass the selected schema to GPT-4.
In order to better generate the script, we pass the selected schema to GPT-4-turbo.
</Tooltip>
</div>
{#if dbSchema.lang !== 'graphql' && (dbSchema.schema?.public || dbSchema.schema?.PUBLIC || dbSchema.schema?.dbo)}
@@ -8,7 +8,7 @@
</script>
<Button
size="sm"
size="xs"
variant="contained"
color="dark"
{disabled}
+12 -11
View File
@@ -41,7 +41,8 @@ export type FlowCopilotContext = {
}>
}
const systemPrompt = `You write code as instructed by the user. Only output code. Wrap the code in a code block.
const systemPrompt = `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:
@@ -55,24 +56,24 @@ const additionalInfos: {
python3: string
} = {
bun: `<contextual_information>
We have to export a "main" function like this: "export async function main(...)" and specify the parameter types but do not call it.
If needed, the standard fetch method is available globally, do not import it.
You can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: "{resource_type}Resource".
The following resource types are available:
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.
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>
Only define the type for resources that are actually needed to achieve the function purpose. The resource type name has to be exactly as specified. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE.
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>`,
python3: `<contextual_information>
We have to export a "main" function and specify the parameter types but do not call it.
You can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: "{resource_type}_resource".
The following resource types are available:
You have to write a function in Python called "main". Specify the parameter types. Do not call the main function.
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>
Only define the type for resources that 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 the imported object, rename the imported object NOT THE TYPE.
</contextual_information>`
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>`
}
const triggerPrompts: {
+10 -9
View File
@@ -8,17 +8,18 @@ import { formatResourceTypes } from './utils'
import { EDIT_CONFIG, FIX_CONFIG, GEN_CONFIG } from './prompts'
import type {
CompletionCreateParamsStreaming,
CreateChatCompletionRequestMessage
ChatCompletionCreateParamsStreaming,
ChatCompletionMessageParam
} from 'openai/resources/chat'
import { buildClientSchema, printSchema } from 'graphql'
export const SUPPORTED_LANGUAGES = new Set(Object.keys(GEN_CONFIG.prompts))
const openaiConfig: CompletionCreateParamsStreaming = {
const openaiConfig: ChatCompletionCreateParamsStreaming = {
temperature: 0,
max_tokens: 2048,
model: 'gpt-4',
model: 'gpt-4-1106-preview',
seed: 42,
stream: true,
messages: []
}
@@ -32,7 +33,7 @@ export async function testKey({
messages
}: {
apiKey?: string
messages: CreateChatCompletionRequestMessage[]
messages: ChatCompletionMessageParam[]
abortController: AbortController
}) {
if (apiKey) {
@@ -236,9 +237,9 @@ const PROMPTS_CONFIGS = {
}
export async function getNonStreamingCompletion(
messages: CreateChatCompletionRequestMessage[],
messages: ChatCompletionMessageParam[],
abortController: AbortController,
model: string = 'gpt-4'
model: string = 'gpt-4-1106-preview'
) {
if (!openai) {
throw new Error('OpenAI not initialized')
@@ -265,7 +266,7 @@ export async function getNonStreamingCompletion(
}
export async function getCompletion(
messages: CreateChatCompletionRequestMessage[],
messages: ChatCompletionMessageParam[],
abortController: AbortController
) {
if (!openai) {
@@ -374,7 +375,7 @@ function getStringEndDelta(prev: string, now: string) {
}
export async function deltaCodeCompletion(
messages: CreateChatCompletionRequestMessage[],
messages: ChatCompletionMessageParam[],
generatedCodeDelta: Writable<string>,
abortController: AbortController
) {
@@ -1,5 +1,6 @@
system: |-
You write code as instructed by the user. Only output code. Wrap the code in a code block.
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.
Put explanations directly in the code as comments.
Here's how interactions have to look like:
@@ -15,14 +16,14 @@ prompts:
{code}
```
<contextual_information>
We have to export a "main" function and specify the parameter types but do not call it.
You can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: "{resource_type}_resource".
The following resource types are available:
You have to write a function in python called "main". Specify the parameter types. Do not call the main function.
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>
Only define the type for resources that 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 the imported object, rename the imported object NOT THE TYPE.
</contextual_information>
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}
deno:
prompt: |-
@@ -1,8 +1,8 @@
export const EDIT_PROMPT = {
"system": "You write code as instructed by the user. Only output code. Wrap the code in a code block. \nPut explanations directly in the code as comments.\n\nHere's how interactions have to look like:\nuser: {sample_question}\nassistant: ```language\n{code}\n```",
"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.\nOnly output code. Wrap the code in a code block. \nPut explanations directly in the code as comments.\n\nHere's how interactions have to look like:\nuser: {sample_question}\nassistant: ```language\n{code}\n```",
"prompts": {
"python3": {
"prompt": "Here's my python3 code: \n```python\n{code}\n```\n<contextual_information>\nWe have to export a \"main\" function and specify the parameter types but do not call it.\nYou can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: \"{resource_type}_resource\".\nThe following resource types are available:\n<resourceTypes>\n{resourceTypes}\n</resourceTypes>\nOnly define the type for resources that 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 the imported object, rename the imported object NOT THE TYPE.\n</contextual_information>\nMy instructions: {description}"
"prompt": "Here's my python3 code: \n```python\n{code}\n```\n<contextual_information>\nYou have to write a function in python called \"main\". Specify the parameter types. Do not call the main function.\nYou 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:\n<resourceTypes>\n{resourceTypes}\n</resourceTypes>\nYou 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.\nThe 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.\n<contextual_information>\nMy instructions: {description}"
},
"deno": {
"prompt": "Here's my TypeScript code in a deno running environment:\n```typescript\n{code}\n```\n<contextual_information>\nWe have to export a \"main\" function like this: \"export async function main(...)\" and specify the parameter types but do not call it.\nIf needed, the standard fetch method is available globally, do not import it.\nYou can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: \"{resource_type}Resource\". \nThe resource type name has to be exactly as specified.\n<resourceTypes>\n{resourceTypes}\n</resourceTypes>\nOnly define the type for resources that are actually needed to achieve the function purpose. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE.\n</contextual_information>\nMy instructions: {description}"
@@ -1,5 +1,6 @@
system: |-
You fix the code shared by the user. Only output code. Wrap the code in a code block.
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.
@@ -17,14 +18,14 @@ prompts:
{code}
```
<contextual_information>
We have to export a "main" function and specify the parameter types but do not call it.
You can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: "{resource_type}_resource".
The following resource types are available:
You have to write a function in python called "main". Specify the parameter types. Do not call the main function.
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>
Only define the type for resources that 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 the imported object, rename the imported object NOT THE TYPE.
</contextual_information>
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.
deno:
@@ -1,8 +1,8 @@
export const FIX_PROMPT = {
"system": "You fix the code shared by the user. Only output code. Wrap the code in a code block. \nExplain the error and the fix after generating the code inside an <explanation> tag.\nAlso put explanations directly in the code as comments.\n\nHere's how interactions have to look like:\nuser: {sample_question}\nassistant: ```language\n{code}\n```\n<explanation>{explanation}</explanation>",
"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.\nOnly output code. Wrap the code in a code block. \nExplain the error and the fix after generating the code inside an <explanation> tag.\nAlso put explanations directly in the code as comments.\n\nHere's how interactions have to look like:\nuser: {sample_question}\nassistant: ```language\n{code}\n```\n<explanation>{explanation}</explanation>",
"prompts": {
"python3": {
"prompt": "Here's my python3 code: \n```python\n{code}\n```\n<contextual_information>\nWe have to export a \"main\" function and specify the parameter types but do not call it.\nYou can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: \"{resource_type}_resource\". \nThe following resource types are available:\n<resourceTypes>\n{resourceTypes}\n</resourceTypes>\nOnly define the type for resources that 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 the imported object, rename the imported object NOT THE TYPE.\n</contextual_information>\nI get the following error: {error}\nFix my code."
"prompt": "Here's my python3 code: \n```python\n{code}\n```\n<contextual_information>\nYou have to write a function in python called \"main\". Specify the parameter types. Do not call the main function.\nYou 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:\n<resourceTypes>\n{resourceTypes}\n</resourceTypes>\nYou 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.\nThe 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.\n<contextual_information>\nI get the following error: {error}\nFix my code."
},
"deno": {
"prompt": "Here's my TypeScript code in a deno running environment:\n```typescript\n{code}\n```\n<contextual_information>\nWe have to export a \"main\" function like this: \"export async function main(...)\" and specify the parameter types but do not call it.\nIf needed, the standard fetch method is available globally, do not import it.\nYou can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: \"{resource_type}Resource\".\nThe following resource types are available:\n<resourceTypes>\n{resourceTypes}\n</resourceTypes>\nOnly define the type for resources that are actually needed to achieve the function purpose. The resource type name has to be exactly as specified. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE.\n</contextual_information>\nI get the following error: {error}\nFix my code."
@@ -1,5 +1,6 @@
system: |-
You write code as instructed by the user. Only output code. Wrap the code in a code block.
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:
@@ -10,69 +11,113 @@ system: |-
prompts:
python3:
prompt: |-
Write a function in python called "main". The function should {description}. Specify the parameter types. Do not call the main function.
You can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: "{resource_type}_resource".
The following resource types are available:
<contextual_information>
You have to write a function in Python called "main". Specify the parameter types. Do not call the main function.
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>
Only define the type for resources that 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 the imported object, rename the imported object NOT THE TYPE.
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}
deno:
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.
If needed, the standard fetch method is available globally, do not import it.
You can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: "{resource_type}Resource".
The following resource types are available:
<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 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>
Only define the type for resources that are actually needed to achieve the function purpose. The resource type name has to be exactly as specified. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE.
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}
go:
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".
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}
bash:
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.
<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}
postgresql:
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 (without specifying the type) by adding comments before the statement like that: `-- $1 name1` or `-- $2 name = default` (one per row)
<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}
mysql:
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 statement like that: `-- ? name1 ({type})` or `-- ? name2 ({type}) = default` (one per row)
<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}
bigquery:
prompt: |-
Write SQL code for BigQuery that should {description}. 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>
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}
snowflake:
prompt: |-
Write SQL code for snowflake that should {description}. 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>
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}
mssql:
prompt: |-
Write SQL code for Microsoft SQL Server that should {description}. Arguments can be obtained directly in the statement with @p1, @p2, etc.. Name the parameters by adding comments before the statement like that: `-- @p1 name1 ({type})` or `-- @p2 name2 ({type}) = default` (one per row)
<contextual_information>
You have to write a statement for Microsoft SQL Server. Arguments can be obtained directly in the statement with @p1, @p2, etc.. Name the parameters by adding comments before the statement like that: `-- @p1 name1 ({type})` or `-- @p2 name2 ({type}) = default` (one per row)
</contextual_information>
My instructions: {description}
graphql:
prompt: |-
Write a GraphQL query that should {description}. Add the needed arguments as query parameters.
<contextual_information>
You have to write a query for GraphQL. Add the needed arguments as query parameters.
</contextual_information>
My instructions: {description}
powershell:
prompt: |-
Write powershell code that should {description}. Arguments can be obtained by calling the param function on the first line like that: `param($ParamName1, $ParamName2 = "default value", [{type}]$ParamName3, ...)`
<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}
nativets:
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 can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: "{resource_type}Resource".
The following resource types are available:
<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 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>
Only define the type for resources that are actually needed to achieve the function purpose. The resource type name has to be exactly as specified. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE.
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}
bun:
prompt: |-
Write a function in TypeScript called "main". The function should {description}. Specify the parameter types. You can import npm libraries. Export the "main" function like this: "export async function main(...)". Do not call the main function.
If needed, the standard fetch method is available globally, do not import it.
You can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: "{resource_type}Resource".
The following resource types are available:
<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.
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>
Only define the type for resources that are actually needed to achieve the function purpose. The resource type name has to be exactly as specified. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE.
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}
frontend:
prompt: |-
Write client-side javascript code that should {description}. You have access to a few helpers:
@@ -1,44 +1,44 @@
export const GEN_PROMPT = {
"system": "You write code as instructed by the user. Only output code. Wrap the code in a code block. \nPut explanations directly in the code as comments.\n\nHere's how interactions have to look like:\nuser: {sample_question}\nassistant: ```language\n{code}\n```",
"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.\nOnly output code. Wrap the code in a code block.\nPut explanations directly in the code as comments.\n\nHere's how interactions have to look like:\nuser: {sample_question}\nassistant: ```language\n{code}\n```",
"prompts": {
"python3": {
"prompt": "Write a function in python called \"main\". The function should {description}. Specify the parameter types. Do not call the main function.\nYou can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: \"{resource_type}_resource\".\nThe following resource types are available:\n<resourceTypes>\n{resourceTypes}\n</resourceTypes>\nOnly define the type for resources that 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 the imported object, rename the imported object NOT THE TYPE."
"prompt": "<contextual_information>\nYou have to write a function in Python called \"main\". Specify the parameter types. Do not call the main function.\nYou 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:\n<resourceTypes>\n{resourceTypes}\n</resourceTypes>\nYou 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.\nThe 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.\n<contextual_information>\nMy instructions: {description}"
},
"deno": {
"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.\nIf needed, the standard fetch method is available globally, do not import it.\nYou can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: \"{resource_type}Resource\".\nThe following resource types are available:\n<resourceTypes>\n{resourceTypes}\n</resourceTypes>\nOnly define the type for resources that are actually needed to achieve the function purpose. The resource type name has to be exactly as specified. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE."
"prompt": "<contextual_information>\nYou 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.\nYou can import deno libraries or you can also import npm libraries like that: \"import ... from \"npm:{package}\";\". The fetch standard method is available globally.\nYou 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:\n<resourceTypes>\n{resourceTypes}\n</resourceTypes>\nYou 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.\nThe 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.\n</contextual_information>\nMy instructions: {description}"
},
"go": {
"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\"."
"prompt": "Here's my go code: \n```go\n{code}\n```\n<contextual_information>\nYou 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\"\n</contextual_information>\nMy instructions: {description}"
},
"bash": {
"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."
"prompt": "<contextual_information>\nYou 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.\n</contextual_information>\nMy instructions: {description}"
},
"postgresql": {
"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 (without specifying the type) by adding comments before the statement like that: `-- $1 name1` or `-- $2 name = default` (one per row)"
"prompt": "<contextual_information>\nYou 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)\n</contextual_information>\nMy instructions: {description}"
},
"mysql": {
"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 statement like that: `-- ? name1 ({type})` or `-- ? name2 ({type}) = default` (one per row)"
"prompt": "<contextual_information>\nYou 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)\n</contextual_information>\nMy instructions: {description}"
},
"bigquery": {
"prompt": "Write SQL code for BigQuery that should {description}. 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...."
"prompt": "<contextual_information>\nYou 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....\n</contextual_information>\nMy instructions: {description}"
},
"snowflake": {
"prompt": "Write SQL code for snowflake that should {description}. 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)"
"prompt": "<contextual_information>\nYou 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)\n</contextual_information>\nMy instructions: {description}"
},
"mssql": {
"prompt": "Write SQL code for Microsoft SQL Server that should {description}. Arguments can be obtained directly in the statement with @p1, @p2, etc.. Name the parameters by adding comments before the statement like that: `-- @p1 name1 ({type})` or `-- @p2 name2 ({type}) = default` (one per row)"
"prompt": "<contextual_information>\nYou have to write a statement for Microsoft SQL Server. Arguments can be obtained directly in the statement with @p1, @p2, etc.. Name the parameters by adding comments before the statement like that: `-- @p1 name1 ({type})` or `-- @p2 name2 ({type}) = default` (one per row)\n</contextual_information>\nMy instructions: {description}"
},
"graphql": {
"prompt": "Write a GraphQL query that should {description}. Add the needed arguments as query parameters."
"prompt": "<contextual_information>\nYou have to write a query for GraphQL. Add the needed arguments as query parameters.\n</contextual_information>\nMy instructions: {description}"
},
"powershell": {
"prompt": "Write powershell code that should {description}. Arguments can be obtained by calling the param function on the first line like that: `param($ParamName1, $ParamName2 = \"default value\", [{type}]$ParamName3, ...)`"
"prompt": "<contextual_information>\nYou 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, ...)`\n</contextual_information>\nMy instructions: {description}"
},
"nativets": {
"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.\nYou can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: \"{resource_type}Resource\".\nThe following resource types are available:\n<resourceTypes>\n{resourceTypes}\n</resourceTypes>\nOnly define the type for resources that are actually needed to achieve the function purpose. The resource type name has to be exactly as specified. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE."
"prompt": "<contextual_information>\nYou 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.\nYou should use fetch and are not allowed to import any libraries. \nYou 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:\n<resourceTypes>\n{resourceTypes}\n</resourceTypes>\nYou 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.\nThe resource type name has to be exactly as specified (no resource suffix).\n</contextual_information>\nMy instructions: {description}"
},
"bun": {
"prompt": "Write a function in TypeScript called \"main\". The function should {description}. Specify the parameter types. You can import npm libraries. Export the \"main\" function like this: \"export async function main(...)\". Do not call the main function.\nIf needed, the standard fetch method is available globally, do not import it.\nYou can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: \"{resource_type}Resource\".\nThe following resource types are available:\n<resourceTypes>\n{resourceTypes}\n</resourceTypes>\nOnly define the type for resources that are actually needed to achieve the function purpose. The resource type name has to be exactly as specified. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE."
"prompt": "<contextual_information>\nYou 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.\nThe fetch standard method is available globally.\nYou 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:\n<resourceTypes>\n{resourceTypes}\n</resourceTypes>\nYou 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.\nThe 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.\n</contextual_information>\nMy instructions: {description}"
},
"frontend": {
"prompt": "Write client-side javascript code that should {description}. You have access to a few helpers:\nYou can access the context object with the ctx global variable. \nThe 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'\nYou can use the goto function to navigate to a specific URL: goto(path: string, newTab?: boolean)\nUse the setTab function to manually set the tab of a Tab component: setTab(id: string, index: string)\nUse the recompute function to recompute a component: recompute(id: string)\nUse the getAgGrid function to get the ag-grid instance of a table: getAgGrid(id: string)\nThe setValue function is meant to set or force the value of a component: setValue(id: string, value: any)."
@@ -555,8 +555,8 @@
<PageHeader title="Windmill AI" primary={false} />
<div class="mt-2">
<Alert type="info" title="Select an OpenAI resource to unlock Windmill AI features!">
Windmill AI uses OpenAI's GPT-3.5-turbo for code completion and GPT-4 for all other AI
features.
Windmill AI uses OpenAI's GPT-3.5-turbo for code completion and GPT-4-turbo for all other
AI features.
</Alert>
</div>
<div class="mt-5 flex gap-1">
+1 -1
View File
@@ -1,4 +1,4 @@
openai==0.27.8
openai==1.1.0
python-dotenv==1.0.0
pyyaml==6.0
tqdm==4.65.0
+293 -227
View File
@@ -1,9 +1,9 @@
- answer: |-
```python
from typing import TypedDict, List
import psycopg2
from typing import TypedDict
# Define the resource type for postgresql
# Define the TypedDict for the PostgreSQL resource
class postgresql(TypedDict):
host: str
port: int
@@ -12,45 +12,60 @@
sslmode: str
password: str
def main(postgresql_resource: postgresql):
# Connect to the PostgreSQL server
conn = psycopg2.connect(
host=postgresql_resource['host'],
port=postgresql_resource['port'],
user=postgresql_resource['user'],
dbname=postgresql_resource['dbname'],
sslmode=postgresql_resource['sslmode'],
password=postgresql_resource['password']
def main(postgres: postgresql) -> List[dict]:
# Connect to the PostgreSQL database
connection = psycopg2.connect(
host=postgres['host'],
port=postgres['port'],
user=postgres['user'],
dbname=postgres['dbname'],
password=postgres['password'],
sslmode=postgres['sslmode']
)
# Create a cursor
cur = conn.cursor()
# Create a cursor object
cursor = connection.cursor()
# Execute a command: this creates a new table
cur.execute("SELECT * FROM orders")
# Execute the query to fetch all rows from the orders table
cursor.execute("SELECT * FROM orders")
# Fetch all the rows
rows = cur.fetchall()
# Fetch all rows from the cursor
rows = cursor.fetchall()
# Close communication with the PostgreSQL database server
cur.close()
conn.close()
# Define the list to hold the rows as dictionaries
orders_list = []
# Return the rows
return rows
# Get the column names
column_names = [desc[0] for desc in cursor.description]
# Convert each row to a dictionary with column names as keys
for row in rows:
order = dict(zip(column_names, row))
orders_list.append(order)
# Close the cursor and the connection
cursor.close()
connection.close()
# Return the list of orders
return orders_list
```
description: connect to postgres and list the rows in the orders table
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 can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: "{resource_type}_resource".
The resource type name has to be exactly as specified (has to be IN LOWERCASE).
<contextual_information>
You have to write a function in Python called "main". Specify the parameter types. Do not call the main function.
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>
Only define the type for resources that are actually needed to achieve the function purpose. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE.
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 write code as instructed by the user. Only output code. Wrap the code in a code block.
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:
@@ -61,17 +76,13 @@
type: gen
- answer: |-
```python
def main(num: int, airtable_resource: airtable) -> float:
if num == 0:
raise ValueError("The input number cannot be zero.")
return 3 / num
def main(num: int) -> float:
if num == 0: # Check if num is zero to avoid division by zero error
raise ValueError("Cannot divide by zero")
return 3 / num
```
<explanation>
The error you're encountering is a "division by zero" error. This happens when the variable `num` is zero, because division by zero is undefined in mathematics and not allowed in Python.
To fix this, I added a check at the start of your function to see if `num` is zero. If it is, the function raises a `ValueError` with a descriptive message. This way, the function will stop executing before it tries to perform the division, and you'll get a helpful error message instead of a "division by zero" error.
Also, based on the contextual information you provided, I added a parameter for the `airtable_resource` of type `airtable` to the function. This is because you mentioned that the function should take resources as parameters, and the resource parameters should be named "{resource_type}_resource". However, if you don't need this resource for your function, feel free to remove this parameter.
The error "division by zero" occurs when you attempt to divide a number by zero, which is mathematically undefined and not allowed in programming. To fix this error, I added a check at the beginning of the `main` function to ensure that the `num` parameter is not zero. If `num` is zero, the function raises a `ValueError` with an appropriate message. This prevents the division by zero from occurring and allows the user of the function to handle the exception appropriately.
</explanation>
code: |-
def main(num: int) -> float:
@@ -84,18 +95,19 @@
{code}
```
<contextual_information>
We have to export a "main" function and specify the parameter types but do not call it.
You can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: "{resource_type}_resource".
The resource type name has to be exactly as specified (has to be IN LOWERCASE).
You have to write a function in python called "main". Specify the parameter types. Do not call the main function.
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>
Only define the type for resources that are actually needed to achieve the function purpose. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE.
</contextual_information>
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 fix the code shared by the user. Only output code. Wrap the code in a code block.
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.
@@ -108,10 +120,9 @@
type: fix
- answer: |-
```python
# This is a Python function named 'main' that takes an integer as an argument.
# The function returns the result of the division of the input number by 16.
# The return type of the function is float.
# Define the function 'main' which takes an integer 'num' and returns a float
def main(num: int) -> float:
# Divide the input number by 16 and return the result
return num / 16
```
code: |-
@@ -125,17 +136,18 @@
{code}
```
<contextual_information>
We have to export a "main" function and specify the parameter types but do not call it.
You can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: "{resource_type}_resource".
The resource type name has to be exactly as specified (has to be IN LOWERCASE).
You have to write a function in python called "main". Specify the parameter types. Do not call the main function.
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>
Only define the type for resources that are actually needed to achieve the function purpose. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE.
</contextual_information>
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 write code as instructed by the user. Only output code. Wrap the code in a code block.
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.
Put explanations directly in the code as comments.
Here's how interactions have to look like:
@@ -150,27 +162,31 @@
import (
"errors"
"fmt"
)
func main(num float64) (float64, error) {
// Check if the number is zero to avoid division by zero error
if num == 0 {
return 0, errors.New("Cannot divide by zero")
// main divides a given number by 16 and returns the result along with any error that might occur.
func main(number float64) (float64, error) {
if number == 0 {
return 0, errors.New("cannot divide by zero")
}
// Divide the number by 16
result := num / 16
result := number / 16
return result, nil
}
```
description: civide a number by 16
description: divide a number by 16
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".
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 write code as instructed by the user. Only output code. Wrap the code in a code block.
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:
@@ -181,31 +197,32 @@
type: gen
- answer: |-
```typescript
// Importing the required npm library
import { toWords } from "npm:number-to-words";
// Defining the main function
export async function main(number: number): Promise<string> {
// Converting the number to words using the toWords function from the number-to-words library
const numberInWords = toWords(number);
// Returning the converted number
return numberInWords;
// Define the main function that converts a number to its word representation
export async function main(numberToConvert: number): Promise<string> {
// Convert the number to words using the number-to-words package
const words = toWords(numberToConvert);
return words;
}
```
description: convert a number to a word
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.
If needed, the standard fetch method is available globally, do not import it.
You can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: "{resource_type}Resource".
The resource type name has to be exactly as specified.
<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 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>
Only define the type for resources that are actually needed to achieve the function purpose. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE.
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 write code as instructed by the user. Only output code. Wrap the code in a code block.
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:
@@ -216,10 +233,9 @@
type: gen
- answer: |-
```typescript
// Importing the required libraries
import { Client } from "npm:https://deno.land/x/postgres/mod.ts";
import { Client } from "npm:pg";
// Defining the type for Postgresql resource
// Define the Postgresql resource type as specified
type Postgresql = {
host: string,
port: number,
@@ -227,48 +243,58 @@
dbname: string,
sslmode: string,
password: string
}
};
// Defining the main function
export async function main(postgresqlResource: Postgresql) {
// Creating a new client with the provided resource
export async function main(postgres: Postgresql) {
// Create a new client instance with the provided Postgresql resource
const client = new Client({
hostname: postgresqlResource.host,
port: postgresqlResource.port,
user: postgresqlResource.user,
database: postgresqlResource.dbname,
password: postgresqlResource.password,
tls: {
enforce: postgresqlResource.sslmode === "require",
},
user: postgres.user,
host: postgres.host,
database: postgres.dbname,
password: postgres.password,
port: postgres.port,
ssl: postgres.sslmode === 'require' ? { rejectUnauthorized: false } : false,
});
// Connecting to the database
await client.connect();
try {
// Connect to the PostgreSQL server
await client.connect();
// Querying the orders table
const result = await client.queryArray("SELECT * FROM orders;");
// Query the orders table and fetch all rows
const res = await client.query('SELECT * FROM orders');
// Closing the connection
await client.end();
// Log the rows to the console
console.log(res.rows);
// Returning the result
return result.rows;
// Return the rows
return res.rows;
} catch (error) {
// If there's an error, log it to the console
console.error('Error querying the PostgreSQL database:', error);
throw error;
} finally {
// Close the client connection
await client.end();
}
}
```
description: connect to postgres and list the rows in the orders table
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.
If needed, the standard fetch method is available globally, do not import it.
You can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: "{resource_type}Resource".
The resource type name has to be exactly as specified.
<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 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>
Only define the type for resources that are actually needed to achieve the function purpose. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE.
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 write code as instructed by the user. Only output code. Wrap the code in a code block.
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:
@@ -279,30 +305,36 @@
type: gen
- answer: |-
```typescript
// Importing the 'numeral' library to convert numbers to words
import * as numeral from 'numeral';
// Import the necessary module for number to words conversion.
// If there's a naming conflict with the "convert" function, it can be renamed during import.
import { toWords } from 'number-to-words';
export async function main(number: number): Promise<string> {
// Converting the number to a word using the 'numeral' library
const word = numeral(number).format('0,0');
// Define the main function that converts a number to its word representation.
export async function main(numberToConvert: number): Promise<string> {
// Convert the number to words using the imported function.
const words = toWords(numberToConvert);
// Returning the word
return word;
// Return the word representation of the number.
return words;
}
```
description: convert a number to a word
lang: bun
template_prompt: |-
Write a function in TypeScript called "main". The function should {description}. Specify the parameter types. You can import npm libraries. Export the "main" function like this: "export async function main(...)". Do not call the main function.
If needed, the standard fetch method is available globally, do not import it.
You can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: "{resource_type}Resource".
The resource type name has to be exactly as specified.
<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.
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>
Only define the type for resources that are actually needed to achieve the function purpose. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE.
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 write code as instructed by the user. Only output code. Wrap the code in a code block.
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:
@@ -314,20 +346,26 @@
- answer: |-
```sql
-- $1 email
-- $2 disabled
-- $3 is_admin
-- $4 operator
-- $5 username
-- $6 workspace_id
INSERT INTO usr (email, disabled, is_admin, operator, username, workspace_id)
VALUES ($1::varchar, $2::bool, $3::bool, $4::bool, $5::varchar, $6::varchar);
-- $2 username
-- $3 workspace_id
-- $4 role (optional)
-- $5 is_admin (optional, default = false)
-- $6 operator (optional, default = false)
-- $7 disabled (optional, default = false)
INSERT INTO usr (email, username, workspace_id, role, is_admin, operator, disabled)
VALUES ($1::varchar, $2::varchar, $3::varchar, $4::varchar, $5::bool, $6::bool, $7::bool);
```
description: insert an a new user
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 (without specifying the type) by adding comments before the statement like that: `-- $1 name1` or `-- $2 name = default` (one per row)
<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 write code as instructed by the user. Only output code. Wrap the code in a code block.
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:
@@ -345,9 +383,13 @@
description: insert an email and a name in the users table
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 statement like that: `-- ? name1 ({type})` or `-- ? name2 ({type}) = default` (one per row)
<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 write code as instructed by the user. Only output code. Wrap the code in a code block.
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:
@@ -362,14 +404,18 @@
-- @name (STRING)
INSERT INTO users (email, name)
VALUES (@email, @name)
VALUES (@email, @name);
```
description: insert an email and a name in the users table
lang: bigquery
template_prompt: |-
Write SQL code for BigQuery that should {description}. 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>
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 write code as instructed by the user. Only output code. Wrap the code in a code block.
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:
@@ -383,15 +429,18 @@
-- ? email (VARCHAR)
-- ? name (VARCHAR)
INSERT INTO users (email, name)
VALUES (?, ?);
INSERT INTO users (email, name) VALUES (?, ?);
```
description: insert an email and a name in the users table
lang: snowflake
template_prompt: |-
Write SQL code for snowflake that should {description}. 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>
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 write code as instructed by the user. Only output code. Wrap the code in a code block.
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:
@@ -403,22 +452,23 @@
- answer: |-
```graphql
mutation CreateUser($email: String!, $name: String!) {
createUser(input: {email: $email, name: $name}) {
user {
id
email
name
}
createUser(email: $email, name: $name) {
id
email
name
}
}
```
In this GraphQL mutation, we are creating a new user with an email and a name. The `$email` and `$name` are variables that we pass into the `CreateUser` mutation. The `!` after the variable type means that these fields are required. The `createUser` mutation takes an `input` object that contains the `email` and `name` fields. The `user` object that is returned contains the `id`, `email`, and `name` of the newly created user.
description: create a new user with an email and a name
lang: graphql
template_prompt: |-
Write a GraphQL query that should {description}. Add the needed arguments as query parameters.
<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 write code as instructed by the user. Only output code. Wrap the code in a code block.
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:
@@ -429,21 +479,20 @@
type: gen
- answer: |-
```bash
# Assign the first argument to a variable
var1="$1"
# Divide the variable by 16 using bc (a language that supports arbitrary precision numbers)
result=$(echo "scale=2; $var1 / 16" | bc)
# Print the result
result=$((var1 / 16))
echo $result
```
description: divide a number by 16
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.
<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 write code as instructed by the user. Only output code. Wrap the code in a code block.
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:
@@ -454,22 +503,23 @@
type: gen
- answer: |-
```powershell
# Define a function that accepts a number as a parameter and divides it by 16
function DivideBySixteen {
param(
[int]$Number # The number to divide
)
param($Number)
# Divide the input number by 16
$Result = $Number / 16
# Divide the number by 16 and return the result
return $Number / 16
}
# Output the result
$Result
```
description: divide a number by 16
lang: powershell
template_prompt: |-
Write powershell code that should {description}. Arguments can be obtained by calling the param function on the first line like that: `param($ParamName1, $ParamName2 = "default value", [{type}]$ParamName3, ...)`
<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 write code as instructed by the user. Only output code. Wrap the code in a code block.
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:
@@ -479,31 +529,38 @@
```
type: gen
- answer: |-
```bash
# Assigning the arguments to variables
image_name="$1"
app_directory="$2"
```dockerfile
# Use an official Python runtime as a parent image
FROM python:3.8-slim
# Navigate to the app directory
cd "$app_directory"
# Set the working directory in the container
WORKDIR /usr/src/app
# Write the Dockerfile
echo "FROM python:3.7-slim" > Dockerfile
echo "WORKDIR /app" >> Dockerfile
echo "COPY . /app" >> Dockerfile
echo "RUN pip install --no-cache-dir -r requirements.txt" >> Dockerfile
echo "CMD [ \"python\", \"./your-daemon-or-script.py\" ]" >> Dockerfile
# Copy the current directory contents into the container at /usr/src/app
COPY . .
# Build the Docker image
docker build -t "$image_name" .
# 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 World
# Run app.py when the container launches
CMD ["python", "./app.py"]
```
This script will create a Dockerfile in the specified app directory and then build a Docker image from it. The Dockerfile is set up to use the slim version of Python 3.7, copy the app files into the image, install any requirements, and then run a Python script when a container is started from the image. You should replace "your-daemon-or-script.py" with the actual script you want to run.
description: write a docker image for a python app
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.
<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 write code as instructed by the user. Only output code. Wrap the code in a code block.
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:
@@ -514,48 +571,52 @@
type: gen
- answer: |-
```typescript
// Define the type for Github resource
type Github = {
token: string
}
};
// Define the main function
export async function main(githubResource: Github, owner: string, repo: string): Promise<number> {
// Define the url for the Github API
const url = `https://api.github.com/repos/${owner}/${repo}`;
export async function main(github: Github, owner: string, repo: string): Promise<number> {
// Define the GitHub API URL for fetching repository details
const apiUrl = `https://api.github.com/repos/${owner}/${repo}`;
// Fetch the data from the Github API
const response = await fetch(url, {
// Make a GET request to the GitHub API to retrieve repository details
const response = await fetch(apiUrl, {
headers: {
'Authorization': `token ${githubResource.token}`,
'Accept': 'application/vnd.github.v3+json'
// Include the token in the Authorization header for authentication
Authorization: `token ${github.token}`
}
});
// Check if the response is ok
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
// Parse the JSON response
const repository = await response.json();
// Check if the response has a 'stargazers_count' property
if (response.ok && 'stargazers_count' in repository) {
// Return the number of stars
return repository.stargazers_count;
} else {
// If the property is not found or the response is not OK, throw an error
throw new Error('Failed to retrieve the number of stars for the repository.');
}
// Parse the response to JSON
const data = await response.json();
// Return the number of stars
return data.stargazers_count;
}
```
description: query the github api and return the number of stars of a repo
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 can take as parameters resources which are dictionaries containing credentials or configuration information. Name the resource parameters like this: "{resource_type}Resource".
The resource type name has to be exactly as specified.
<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 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>
Only define the type for resources that are actually needed to achieve the function purpose. If the type name conflicts with the imported object, rename the imported object NOT THE TYPE.
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 write code as instructed by the user. Only output code. Wrap the code in a code block.
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:
@@ -567,9 +628,9 @@
- answer: |-
```javascript
// Access the email from the context object
var email = ctx.email;
const email = ctx.email;
// Use the setValue function to set the value of the input with id 'my_field' to the email
// Set the value of the input with id 'my_field' to the email from the context
setValue('my_field', email);
```
description: set the value of the input with id 'my_field' to the context variable
@@ -585,7 +646,8 @@
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 instructed by the user. Only output code. Wrap the code in a code block.
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:
@@ -595,31 +657,35 @@
```
type: gen
- answer: |-
-- $1 username
```sql
-- $1 username
SELECT
EXTRACT(MONTH FROM completed_job.created_at) AS month,
EXTRACT(YEAR FROM completed_job.created_at) AS year,
COUNT(*)::DECIMAL / COUNT(DISTINCT completed_job.created_at::DATE) AS avg_jobs_per_month
EXTRACT(YEAR FROM completed_at) AS year,
EXTRACT(MONTH FROM completed_at) AS month,
COUNT(*) / COUNT(DISTINCT DATE_TRUNC('month', completed_at)) AS avg_completed_jobs_per_month
FROM
completed_job
completed_job
WHERE
completed_job.created_by = $1::VARCHAR
created_by = $1::varchar
GROUP BY
year,
month
year,
month
ORDER BY
year DESC,
month DESC;
year,
month;
```
This SQL query will compute the average number of completed jobs per month for the given username. It groups the completed jobs by year and month, and then calculates the average number of jobs per month. The result is ordered by year and month in descending order.
description: compute the average number of completed jobs per month for the given
username
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 (without specifying the type) by adding comments before the statement like that: `-- $1 name1` or `-- $2 name = default` (one per row)
<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 write code as instructed by the user. Only output code. Wrap the code in a code block.
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:
@@ -630,14 +696,13 @@
type: gen
- answer: |-
```sql
SELECT is_secret FROM variable
-- $1 is_public
SELECT is_public FROM variable
```
<explanation>
The error you're encountering is because you're trying to select a column "is_secret" from a table "account" where it does not exist.
The error "ExecutionError: db error: ERROR: column "is_secret" does not exist" indicates that there is no column named "is_secret" in the table being queried. According to the provided database schema, the "is_secret" column does not exist in the "account" table or any other table except for the "variable" table.
Looking at your database schema, the "is_secret" column exists in the "variable" table, not in the "account" table.
So, the correct SQL statement should be `SELECT is_secret FROM variable`.
The corrected code selects the "is_public" column from the "variable" table, which is the closest match to the original intent of querying a boolean column related to secret/public status. If the intention was indeed to select "is_secret", the correct table to select from would be "variable", not "account".
</explanation>
code: |-
SELECT is_secret FROM account
@@ -654,7 +719,8 @@
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 in a code block.
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.
+1 -1
View File
@@ -15,7 +15,7 @@
description: comment my code
- lang: go
type: gen
description: civide a number by 16
description: divide a number by 16
- lang: deno
type: gen
description: convert a number to a word
+5 -3
View File
@@ -119,19 +119,21 @@ def gen_samples(queries_path: str, answers_path: str, prompts_path: str):
(system, prompt, template_prompt) = prepare_prompt(
query, GEN_CONFIG, EDIT_CONFIG, FIX_CONFIG
)
chat_completion = openai.ChatCompletion.create(
model="gpt-4",
client = openai.OpenAI()
chat_completion = client.chat.completions.create(
model="gpt-4-1106-preview",
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
"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)),
}