Readme

example of inferring params from a prompt: https://x.com/yawnxyz/status/1812922642510586039

  • putting results in does wonders
  • use an "extraction guide" to direct results
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { modelProvider } from "https://esm.town/v/yawnxyz/ai";
// selects from xml selectors like <json></json> gets better results
export function selectFromString(str, selector = "json", returnAll = false) {
const regex = new RegExp(`<${selector}>([\\s\\S]*?)</${selector}>`, 'gm');
const matches = [...str.matchAll(regex)].map(match => match[1]);
return returnAll ? matches : matches[0] || null;
}
const paramGuide = JSON.stringify({
from: "extract country code like US, FR, etc from the given string in an array; the country coming from",
to: "extract country code like US, FR, etc from the given string in an array; the country going to",
toCity: "extract city name from the given string in an array; the city going to",
tel: "extract phone number from the given string in an array",
staying: "extract and infer staying details like hotels/services, host name, door/lock code - anything pertaining to where they're staying, details from the given string; output as a string",
});
let response = await modelProvider.gen({
system: `export a properly formatted json response, within <json></json> tags, inferring from the given option parameter guide ${paramGuide}`,
prompt: `hey I'm leaving SFO and landing at degaulle at 4pm; hit me up on whatsapp 1415558686 and let me know the airbnb host name (I think their name is Jacques?) and code for 55 Rue de Example`,
provider: 'groq',
model: 'llama3-8b-8192',
})
// console.log(response.text)
console.log(selectFromString(response.text))
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
July 15, 2024