Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
feat: use map (#258)
Browse files Browse the repository at this point in the history
  • Loading branch information
seren5240 authored Dec 2, 2023
1 parent c707025 commit 89bc0c6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 17 deletions.
33 changes: 17 additions & 16 deletions .grit/patterns/ai.grit
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ language js

// Given a question and a list of choices,
function ai_ask($question, $choices) {
$choice_text = join($choices, `, `),
$messages = [
`{
"role": "system",
"content": "Answer all questions with a single word. Choices: $choices"
}`,
`{
"role": "user",
"content": "$question"
}`
{
role: "system",
content: `Answer all questions with a single word. Choices: $choice_text`
},
{
role: "user",
content: $question
}
],
$answer = llm_choice($messages, $choices),
return $answer
Expand All @@ -20,14 +21,14 @@ function ai_ask($question, $choices) {
pattern ai_is($condition) {
$item_to_check where {
$messages = [
`{
"role": "system",
"content": "Classify whether the input code should match this condition: $condition. Answer with yes or no."
}`,
`{
"role": "user",
"content": "$item_to_check"
}`
{
role: "system",
content: `Classify whether the input code should match this condition: $condition. Answer with yes or no.`
},
{
role: "user",
content: $item_to_check
}
],
$answer = llm_choice($messages, choices=["yes", "no"]),
$answer <: "yes"
Expand Down
13 changes: 12 additions & 1 deletion .grit/patterns/ai_choose.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ For example, you can use the `ai_choose` function to choose a name for a functio
tags: #ai, #sample, #util, #hidden

```grit
`function ($args) { $body}` as $func where {
`function ($args) { $body }` as $func where {
$name = ai_ask(choices=["adder", "remover", "divider"], question=`What should I name the function? $func`)
} => `// This function: $name
$func`
Expand Down Expand Up @@ -35,3 +35,14 @@ function (x) { return x / 2; }
// This function: divider
function (x) { return x / 2; }
```

## With double quotes

```js
function (x) { return x + ""; }
```

```ts
// This function: adder
function (x) { return x + ""; }
```
12 changes: 12 additions & 0 deletions .grit/patterns/ai_match.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,15 @@ console.log('We are now processing the user. Their name is:', user.name);
console.log('This is the system. It is fine.');
// REDACTED: 'We are now processing the user. Their name is:', user.name;
```

## With double quotes

```js
console.log('This is the system. It is fine.');
console.log('We are now processing "the user". Their name is:', user.name);
```

```ts
console.log('This is the system. It is fine.');
// REDACTED: 'We are now processing "the user". Their name is:', user.name;
```

0 comments on commit 89bc0c6

Please sign in to comment.