-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
105 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { AppContext } from "../../mod.ts"; | ||
import { Reply } from "../../../ai-assistants/actions/chat.ts"; | ||
|
||
interface Props { | ||
prompt: string; | ||
currentCode: string; | ||
} | ||
|
||
export default async function action( | ||
{ currentCode, prompt }: Props, | ||
_req: Request, | ||
ctx: AppContext, | ||
): Promise<Response | { replies: Reply<unknown>[]; thread: string }> { | ||
return await ctx.invoke("ai-assistants/actions/chat.ts", { | ||
assistant: "code-assistant", | ||
message: | ||
`The user asks: ${prompt}. \n\nThe current the user is prompting upon is: ${currentCode}`, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import type { AIAssistant } from "../../../ai-assistants/mod.ts"; | ||
|
||
export interface Props { | ||
/** @description Base snippet to generate the code from */ | ||
snippet: string; | ||
} | ||
|
||
const BASE_INSTRUCTIONS = ` | ||
You are a code guru in typescript, preact and tailwindcss. | ||
Users will ask you for improving and creating new components based on preact, tailwindcss and typescript | ||
Under no circunstance ask something back. You should always respond with the full component code. This code should be runnable | ||
Things to consider: | ||
1. Do not import h from preact, we are using automatic jsx | ||
2. Do not wrapp with any code formatting strings, like backsticks etc | ||
3. Return a code that is ready to be used in a Deno like environment | ||
4. Since this is a server component, do not use preact hooks. Always prefer css-only solutions. | ||
Examples: | ||
question: Give me a fancy component | ||
response: interface Props { | ||
/** | ||
* @description The description of name. | ||
*/ | ||
name: string; | ||
} | ||
export default function Section({ name }: Props) { | ||
return (<div class="bg-white p-8 rounded-md shadow-md"> | ||
<h2 class="text-2xl font-semibold mb-4">Fancy Component</h2> | ||
<div class="space-y-4"> | ||
<button class="btn btn-primary">Click me</button> | ||
<input type="text" class="input input-bordered" placeholder="Type something" /> | ||
<div class="alert alert-success"> | ||
{name} | ||
</div> | ||
</div> | ||
</div>) | ||
} | ||
`; | ||
|
||
export default function loader(props: Props): AIAssistant { | ||
return { | ||
name: "code-assistant", | ||
model: "gpt-3.5-turbo-1106", | ||
availableFunctions: [], | ||
instructions: BASE_INSTRUCTIONS, | ||
prompts: [ | ||
{ | ||
context: "This is a snippet of the code you should generate from", | ||
content: props.snippet, | ||
}, | ||
], | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters