Search

Results include substring matches and semantically similar vals. Learn more
juansebsol avatar
RudeAI
@juansebsol
@jsxImportSource https://esm.sh/react
HTTP
import { createRoot } from "https://esm.sh/react-dom/client";
function App() {
const [messages, setMessages] = useState([]);
</div>
function client() {
createRoot(document.getElementById("root")).render(<App />);
client();
function generateSessionId() {
return Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
export default async function server(request: Request): Promise<Response> {
const { OpenAI } = await import("https://esm.town/v/std/openai");
const { sqlite } = await import("https://esm.town/v/stevekrouse/sqlite");
const openai = new OpenAI();
const SCHEMA_VERSION = 2;
// Generate AI response
const completion = await openai.chat.completions.create({
messages: [
jamisonl avatar
sunnyAmberCrane
@jamisonl
Bot for Cama discord server. To initialize new slash commands, you have to run a separate bit of code. This is for modifying their functionality
HTTP
mmands, you have to run a separate bit of code. This is for modifying their functionality
req.headers.get("X-Signature-Ed25519"),
req.headers.get("X-Signature-Timestamp"),
// Get the user calling this slash command
const userId = await body.member?.user?.id;
if (bank[userId] === undefined) bank[userId] = starting_amount;
dhvanil avatar
val_DxjKDGJFD8
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export async function val_DxjKDGJFD8(req) {
try {
// Create a function from the provided code and execute it
const userCode = async () => {
return const findPrimes = (n) => {
raunakdoesdev avatar
myApi
@raunakdoesdev
An interactive, runnable TypeScript val by raunakdoesdev
Script
export function myApi(name) {
return "hi " + name;
dhvanil avatar
val_4INpGNAf93
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export async function val_4INpGNAf93(req) {
try {
// This demonstrates how infinite complexity can emerge from simple rules
function mandelbrotPoint(x0, y0, maxIter) {
let x = 0;
return iter;
function createMandelbrotVisualization(width, height, maxIter) {
let visualization = '';
lazyplatypus avatar
chatWithCerebras
@lazyplatypus
@jsxImportSource https://esm.sh/react
HTTP
const MODELS = ["llama3.1-8b", "llama3.1-70b"];
function App() {
const [messages, setMessages] = useState<Array<{ role: string; content: string }>>([]);
</div>
function client() {
createRoot(document.getElementById("root")).render(<App />);
client();
async function server(request: Request): Promise<Response> {
if (request.method === "POST" && new URL(request.url).pathname === "/api/chat") {
nbbaier avatar
dbToAPI
@nbbaier
Create an API from a lowdb blob This val exports a function that takes a lowdb instance and returns a Hono router that can be used to interact with the data. This is the beginning of an implementation of something like json-server for Val Town. The resulting server also comes with a frontend at / . The code for the frontend can be found here . See this val for an example. Things I'd like to implement All HTTP methods Custom route definitions (like in json-server ) Custom frontends Filtering, sorting, pagination, etc
Script
## Create an API from a [lowdb blob](https://www.val.town/v/pomdtr/lowdb)
This val exports a function that takes a lowdb instance and returns a [Hono](https://hono.dev) router that can be used to int
The resulting server also comes with a frontend at `/`. The code for the frontend can be found [here](https://www.val.town/v/
import { Hono } from "npm:hono";
// TODO: implement options
export async function createServer(db, options: Options & { auth?: { username: string; password: string } } = {}) {
const app = new Hono();
if (options.auth) {
maxm avatar
wide
@maxm
WIDE Store any unstructured JSON data. Retrieve it with an expressive and efficient query system. WIDE is a library and service hosted on Val Town. Authenticate and use it with your Val Town credentials, or fork it and connect it to your own Clickhouse Instance. import { ValSession } from 'https://esm.town/v/maxm/valSession'; import { Wide } from 'https://esm.town/v/maxm/wide'; // Use your Val Town API Token to create a session const wide = new Wide(await ValSession.new(Deno.env.get("valtown"))) // Write any data. await wide.write([ { user: {id: 1, name: 'Alice', email: 'alice@example.com' }}, { user: {id: 2, name: 'Bob', email: 'bob@example.com' }}, { user: {id: 3, name: 'Charlie', email: 'charlie@example.com' }}, ]); await wide.fields("user.") // => [ // { fieldName: "user.email", fieldType: "string", count: 3 }, // { fieldName: "user.id", fieldType: "number", count: 3 }, // { fieldName: "user.name", fieldType: "string", count: 3 } // ] await wide.values("user.email") // [ // { value: "bob@example.com", count: 1 }, // { value: "charlie@example.com", count: 1 }, // { value: "alice@example.com", count: 1 } // ] await wide.search({ start: new Date(Date.now() - 1000 * 60 * 10), end: new Date(), filters: [{ fieldName: "user.name", operator: "equals", value: "Alice" }], }) // [{ user: { name: "Alice", email: "alice@example.com", id: 1 } }];
HTTP
header: { sessiontoken: this.#sessionToken },
return await resp.json();
export default async function(req: Request): Promise<Response> {
// Use your Val Town API Token to create a session
const wide = new Wide(await ValSession.new(Deno.env.get("valtown")));
nerdymomocat avatar
add_to_notion_w_ai
@nerdymomocat
Uses instructor and open ai (with gpt-4-turbo) to process any content into a notion database entry. Use addToNotion with any database id and content. await addToNotion( "DB_ID_GOES_HERE", "CONTENT_GOES HERE"//"for example: $43.28 ordered malai kofta and kadhi (doordash) [me and mom] jan 3 2024" ); Prompts are created based on your database name, database description, property name, property type, property description, and if applicable, property options (and their descriptions). Supports: checkbox, date, multi_select, number, rich_text, select, status, title, url, email Uses NOTION_API_KEY , OPENAI_API_KEY stored in env variables and uses Valtown blob storage to store information about the database. Use get_notion_db_info to use the stored blob if exists or create one, use get_and_save_notion_db_info to create a new blob (and replace an existing one if exists).
Script
- Uses `NOTION_API_KEY`, `OPENAI_API_KEY` stored in env variables and uses [Valtown blob storage](https://esm.town/v/std/blob
import OpenAI from "npm:openai";
const oai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY ?? undefined,
function createPrompt(title, description, properties) {
function processProperties(jsonObject) {
async function get_and_save_notion_db_processed_properties(databaseId)
async function get_notion_db_info(databaseId) {
async function get_and_save_notion_db_info(databaseId) {
function createZodSchema(filteredProps) {
function convertToNotionProperties(responseValues, filteredProps) {
janpaul123 avatar
valle_tmp_1232975987134350426195802232196885
@janpaul123
@jsxImportSource https://esm.sh/react
HTTP
import OpenAI from "npm:openai";
unless strictly necessary, for example use APIs that don't require a key, prefer internal function
functions where possible. Unless specified, don't add error handling,
The val should create a "export default async function main() {" which
is the main function that gets executed on every HTTP request.
function write(text) {
function updateValName(valName) {
function saveVal() {
function openTab(tab) {
function toggleTab() {
dhvanil avatar
val_Rb1F0hdOA9
@dhvanil
An interactive, runnable TypeScript val by dhvanil
HTTP
export async function val_Rb1F0hdOA9(req) {
try {
// Execute the code directly and capture its result
sairamoe avatar
myApi
@sairamoe
An interactive, runnable TypeScript val by sairamoe
Script
export function myApi(name) {
return "hi " + name;
janpaul123 avatar
semanticSearchTurso
@janpaul123
Part of Val Town Semantic Search . Uses Turso to search embeddings of all vals, using the sqlite-vss extension. Call OpenAI to generate an embedding for the search query. Query the vss_vals_embeddings table in Turso using vss_search . The vss_vals_embeddings table has been generated by janpaul123/indexValsTurso . It is not run automatically. This table is incomplete due to a bug in Turso .
Script
Uses [Turso](https://turso.tech/) to search embeddings of all vals, using the [sqlite-vss](https://github.com/asg017/sqlite-v
- Call OpenAI to generate an embedding for the search query.
- Query the `vss_vals_embeddings` table in Turso using `vss_search`.
import { db as allValsDb } from "https://esm.town/v/sqlite/db?v=9";
import OpenAI from "npm:openai";
export default async function semanticSearchPublicVals(query) {
const sqlite = createClient({
authToken: Deno.env.get("TURSO_AUTH_TOKEN_VALSEMBEDDINGS"),
const openai = new OpenAI();
const embedding = await openai.embeddings.create({
model: "text-embedding-3-small",
nbbaier avatar
sqliteWriter
@nbbaier
SQLite QueryWriter The QueryWriter class is a utility for generating and executing SQL queries using natural language and OpenAI. It provides a simplified interface for interacting with your Val Town SQLite database and generating SQL queries based on user inputs. This val is inspired by prisma-gpt . PRs welcome! See Todos below for some ideas I have. Usage Import the QueryWriter class into your script: import { QueryWriter } from "https://esm.town/v/nbbaier/sqliteWriter"; Create an instance of QueryWriter, providing the desired table and an optional model: const writer = new QueryWriter({ table: "my_table", model: "gpt-4-1106-preview" }); Call the writeQuery() method to generate an SQL query based on a user input string: const userInput = "Show me all the customers with more than $1000 in purchases."; const query = await writer.writeQuery(userInput); Alternatively, use the gptQuery() method to both generate and execute the SQL query: const userInput = "Show me all the customers with more than $1000 in purchases."; const result = await writer.gptQuery(userInput); Handle the generated query or query result according to your application's needs. API new QueryWriter(args: { table: string; model?: string }): QueryWriter Creates a new instance of the QueryWriter class. table : The name of the database table to operate on. model (optional): The model to use for generating SQL queries. Defaults to "gpt-3.5-turbo". apiKey (optional): An OpenAI API key. Defaults to Deno.env.get("OPENAI_API_KEY") . writeQuery(str: string): Promise<string> Generates an SQL query based on the provided user input string. str : The user input string describing the desired query. Returns a Promise that resolves to the generated SQL query. gptQuery(str: string): Promise<any> Generates and executes an SQL query based on the provided user input string. str : The user input string describing the desired query. Returns a Promise that resolves to the result of executing the generated SQL query. Todos [ ] Handle multiple tables for more complex use cases [ ] Edit prompt to allow for more than just SELECT queries [ ] Allow a user to add to the system prompt maybe? [ ] Expand usage beyond just Turso SQLite to integrate with other databases
Script
utility for generating and executing SQL queries using natural language and OpenAI. It provides a simplified interface for i
- `apiKey` (optional): An OpenAI API key. Defaults to `Deno.env.get("OPENAI_API_KEY")`.
import OpenAI from "npm:openai";
openai: OpenAI;
const { table, model, ...openaiOptions } = options;
// this.apiKey = openaiOptions.apiKey ? openaiOptions.apiKey : Deno.env.get("OPENAI_API_KEY");
this.openai = new OpenAI(openaiOptions);
const response = await this.openai.chat.completions.create({
throw new Error("No response from OpenAI");
throw new Error("No SQL returned from OpenAI. Try again.");
const response = await this.openai.chat.completions.create({
throw new Error("No response from OpenAI");
d0ccc avatar
falDemoApp
@d0ccc
@jsxImportSource https://esm.sh/react
HTTP
import { falProxyRequest } from "https://esm.town/v/stevekrouse/falProxyRequest";
function App() {
const [prompt, setPrompt] = useState("");
</div>
function client() {
createRoot(document.getElementById("root")).render(<App />);
if (typeof document !== "undefined") { client(); }
export default async function server(req: Request): Promise<Response> {
const url = new URL(req.url);