This repository has been archived by the owner on Jun 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: mustache prepare Signed-off-by: Yuhang Shi <[email protected]> * fix: last Signed-off-by: Yuhang Shi <[email protected]> * template Signed-off-by: Yuhang Shi <[email protected]> * fix: test Signed-off-by: Yuhang Shi <[email protected]> * feat: publish Signed-off-by: Yuhang Shi <[email protected]> * fix: build Signed-off-by: Yuhang Shi <[email protected]> * fix: remove publish test Signed-off-by: Yuhang Shi <[email protected]> * feat: bump nodejs version Signed-off-by: Yuhang Shi <[email protected]> --------- Signed-off-by: Yuhang Shi <[email protected]>
- Loading branch information
Yuhang Shi
authored
Nov 6, 2023
1 parent
b743a54
commit bb28b07
Showing
26 changed files
with
271 additions
and
51 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,37 @@ | ||
name: Codegen | ||
|
||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} | ||
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
paths: | ||
- 'yarn.lock' | ||
- 'tools/devkit/**' | ||
- 'templates/**' | ||
push: | ||
branches: [main] | ||
paths: | ||
- 'yarn.lock' | ||
- 'tools/devkit/**' | ||
- 'templates/**' | ||
|
||
jobs: | ||
nodejs-template-codegen-validate: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Setup node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version-file: 'package.json' | ||
cache: yarn | ||
|
||
- name: Install dependencies | ||
run: yarn install --immutable | ||
|
||
- name: validate | ||
run: yarn dev ts-mustache-codegen |
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
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
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 @@ | ||
export * from './renderer' |
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,51 @@ | ||
type MustacheValue = string | number | boolean | ||
|
||
type MustacheRecord<T> = T | ||
|
||
type MustacheSection<T> = T[] | T | ||
|
||
interface Test_ping { | ||
name: MustacheValue | ||
} | ||
|
||
interface Error_retry { | ||
message: MustacheValue | ||
} | ||
|
||
interface Agent_userMessage { | ||
prompt: MustacheValue | ||
} | ||
|
||
interface Agent_systemMessage { | ||
functions: MustacheValue | ||
returnSchema: MustacheValue | ||
} | ||
|
||
interface Features_synthesized_userMessage { | ||
prompt: MustacheValue | ||
} | ||
|
||
interface Features_synthesized_systemMessage { | ||
describe: MustacheValue | ||
argsSchema: MustacheValue | ||
returnTypeSchema: MustacheValue | ||
} | ||
|
||
interface Features_codeInterpreter_evalCode { | ||
code: MustacheValue | ||
} | ||
|
||
interface Features_codeInterpreter_description { | ||
enabled?: MustacheValue | ||
} | ||
|
||
export type TemplateMap = { | ||
'test/ping': Test_ping, | ||
'error/retry': Error_retry, | ||
'agent/userMessage': Agent_userMessage, | ||
'agent/systemMessage': Agent_systemMessage, | ||
'features/synthesized/userMessage': Features_synthesized_userMessage, | ||
'features/synthesized/systemMessage': Features_synthesized_systemMessage, | ||
'features/codeInterpreter/evalCode': Features_codeInterpreter_evalCode, | ||
'features/codeInterpreter/description': Features_codeInterpreter_description, | ||
} |
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,9 @@ | ||
import { expect, test, describe } from 'vitest' | ||
import { templateRenderer } from './renderer' | ||
|
||
describe('renderer', () => { | ||
test('ok', () => { | ||
const result = templateRenderer('test/ping', { name: 'foo' }) | ||
expect(result).toEqual('foo pong') | ||
}) | ||
}) |
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,31 @@ | ||
import { type TemplateMap } from './mustacheTypes' | ||
import { globSync } from 'glob' | ||
import path from 'path' | ||
import fs from 'fs' | ||
import Mustache from 'mustache' | ||
|
||
const TemplateFolderPath = './templates' | ||
const MUSTACHE_EXTENSION = '.mustache' | ||
|
||
const files = globSync(path.join(TemplateFolderPath, `**/*${MUSTACHE_EXTENSION}`)) | ||
|
||
if (files.length === 0) throw new Error('template not found') | ||
|
||
const contents = files.map(f => fs.readFileSync(f, { encoding: 'utf8' })) | ||
|
||
const templates = Object.fromEntries( | ||
files.map((f, i) => [path.relative(TemplateFolderPath, f).replace(MUSTACHE_EXTENSION, ''), contents[i]]) | ||
) | ||
|
||
export type TemplateRenderer = <K extends keyof TemplateMap>(templateName: K, params: TemplateMap[K]) => string | ||
|
||
export type RendererType = { | ||
[K in keyof TemplateMap]: (params: TemplateMap[K]) => string | ||
} | ||
|
||
export const templateRenderer: TemplateRenderer = (name, params) => { | ||
const template = templates[name] | ||
if (!template) throw new Error(`Unknown template '${String(name)}'`) | ||
|
||
return Mustache.render(template, params, undefined, { escape: value => value }) | ||
} |
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 @@ | ||
../../templates/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
You are an AI assistant that makes step-by-step plans to solve problems, utilizing external functions. Each step entails one plan followed by a function-call, which will later be executed to gather args for that step. | ||
Make as few plans as possible if it can solve the problem. | ||
The functions list is described using the following YAML schema array: | ||
{{functions}} | ||
|
||
Your specified plans should be output as JSON object array and adhere to the following JSON schema: | ||
{{returnSchema}} | ||
|
||
Only the listed functions are allowed to be used. |
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,3 @@ | ||
Prompt: {{prompt}} | ||
|
||
Plan array: |
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,4 @@ | ||
Your response is invalid for the following reason: | ||
{{message}} | ||
|
||
Please try again. |
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 @@ | ||
An safe sandbox that only support the built-in library. The execution time is limited to 120 seconds. The task is to define a function named "main" that doesn't take any parameters. The output should be a String. Network access is {{#enabled}}enabled{{/enabled}}{{^enabled}}disabled{{/enabled}} |
Oops, something went wrong.