Search
js_auth_authenticate
@marcomontalbano
An interactive, runnable TypeScript val by marcomontalbano
Script
import { authenticate, getCoreApiBaseEndpoint, jwtVerify } from "jsr:@commercelayer/js-auth";
const auth = await authenticate("client_credentials", {
clientId: "BISG8bb3GWpC8_D7Nt1SuWWdieS5bJq831A50LgB_Ig",
scope: "stock_location:id:DGzAouppwn",
console.log(auth, "\n");
BuyukInsan
@cingozilyas
@jsxImportSource npm:react
HTTP
/** @jsxImportSource npm:react **/
import { renderToString } from "npm:react-dom@18/server";
// AlbΓΌm verisi
const albumData = {
downloadTextFromS3
@vtdocs
Part of the Upload and download from AWS S3 guide on docs.val.town
Script
export const downloadTextFromS3 = (async () => {
const { S3Client } = await import(
"https://deno.land/x/s3_lite_client@0.6.1/mod.ts"
const s3client = new S3Client({
endPoint: "s3.amazonaws.com",
secretKey: process.env.awsS3Secret,
const res = await s3client.getObject("filename.txt");
return await res.text();
solution_getter_no
@robsimmons
An interactive, runnable TypeScript val by robsimmons
Script
import { Dusa } from "https://unpkg.com/dusa@0.1.6/lib/client.js";
const dusa = new Dusa(`
name is "one".
aoc_2023_15_1
@robsimmons
An interactive, runnable TypeScript val by robsimmons
Script
import { Dusa } from "https://unpkg.com/dusa@0.0.11/lib/client.js";
const INPUT = `
rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7
transformEvalCode
@maxm
See: https://www.val.town/v/maxm/eval
Script
Some notes about the differences between the ECMAScript spec and what the
TypeScript compiler produces:
- TS considers top-level declarations to be DeclarationStatements, while
there is no such production in the ECMAScript grammar.
- TS doesn't distinguish let/const (what ES calls a HoistableDeclaration)
and var (ES: VariableDeclaration). TS considers them all to be
VariableStatements.
return (
emeraldPig
@onurpolattimur
An interactive, runnable TypeScript val by onurpolattimur
Script
import Craftgate from "npm:@craftgate/craftgate";
const craftgate = new Craftgate.Client({
apiKey: "sandbox-YEhueLgomBjqsnvBlWVVuFsVhlvJlMHE",
secretKey: "sandbox-tBdcdKVGmGupzfaWcULcwDLMoglZZvTz",
runAgent
@jacoblee93
An interactive, runnable TypeScript val by jacoblee93
Script
gl: "us",
const agent = await initializeAgentExecutorWithOptions(tools, model, {
agentType: "chat-conversational-react-description",
const result = await agent.call({
input: `Generate a Twitter thread announcing a new LangChain release.
githubRestClient
@neverstew
githubRestClient Does what it says! Defaults to using GITHUB_TOKEN env var if none is passed to the function.
Script
# githubRestClient
Does what it says! Defaults to using `GITHUB_TOKEN` env var if none is passed to the function.
import { Octokit } from "npm:@octokit/rest";
export async function githubRestClient(ghToken: string | undefined) {
return new Octokit({ auth: ghToken || Deno.env.get("GITHUB_TOKEN") }).rest;
readmeGPT
@nbbaier
Val Town AI Readme Writer This val provides a class ReadmeWriter for generating readmes for vals with OpenAI. It can both draft readmes and update them directly PRs welcome! See Todos below for some ideas I have. Usage To draft a readme for a given code, use the draftReadme method: import { ReadmeWriter } from "https://esm.town/v/nbbaier/readmeGPT";
const readmeWriter = new ReadmeWriter({});
const val = "https://www.val.town/v/:username/:valname";
const generatedReadme = await readmeWriter.draftReadme(val); To write and update a readme for a given code, use the writeReadme method: import { ReadmeWriter } from "https://esm.town/v/nbbaier/readmeGPT";
const readmeWriter = new ReadmeWriter({});
const val = "https://www.val.town/v/:username/:valname";
const successMessage = await readmeWriter.writeReadme(val); API Reference Class: ReadmeWriter The ReadmeWriter class represents a utility for generating and updating README files. Constructor Creates an instance of the ReadmeWriter class. Parameters: model (optional): The model to be used for generating the readme. Defaults to "gpt-3.5-turbo". apiKey (optional): An OpenAI API key. Defaults to Deno.env.get("OPENAI_API_KEY") . Methods draftReadme(val: string): Promise<string> : Generates a readme for the given val. Parameters: val : URL of the code repository. Returns: A promise that resolves to the generated readme. writeReadme(val: string): Promise<string> : Generates and updates a readme for the given val. Parameters: val : URL of the code repository. Returns: A promise that resolves to a success message if the update is successful. Todos [ ] Additional options to pass to the OpenAI model [ ] Ability to pass more instructions to the prompt to modify how the readme is constructed
Script
import { type WriterOptions } from "https://esm.town/v/nbbaier/WriterOptions";
import { fetch } from "https://esm.town/v/std/fetch?v=4";
import OpenAI, { type ClientOptions } from "npm:openai";
export class ReadmeWriter {
model: string;
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
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](https://github.com/aliyeysides/prisma-gpt). PRs welcome! See **Todos** below for some ideas I have.
## Usage
star_a_github_repository_with_natural_language
@thatsmeadarsh
Using OpenAI Assistant API, Composio to Star a Github Repo This is an example code of using Composio to star a github Repository by creating an AI Agent using OpenAI API Goal Enable OpenAI assistants to perform tasks like starring a repository on GitHub via natural language commands. Tools List of supported tools . FAQs How to get Composio API key? Open app.composio.dev and log in to your account. Then go to app.composio.dev/settings .
Navigate to the API Keys -> Generate a new API key .
Script
async function setupUserConnectionIfNotExists(entityId) {
const entity = toolset.client.getEntity(entityId);
const connection = await entity.getConnection(appName);
async function executeAgent(entityName) {
const entity = toolset.client.getEntity(entityName);
await setupUserConnectionIfNotExists(entity.id);
const instruction = "Star a repo ComposioHQ/composio on GitHub";
const client = new OpenAI();
const response = await client.chat.completions.create({
model: "gpt-4-turbo",
semanticSearchBlobs
@janpaul123
Part of Val Town Semantic Search . Uses Val Town's blob storage to search embeddings of all vals, by downloading them all and iterating through all of them to compute distance. Slow and terrible, but it works! Get metadata from blob storage: allValsBlob${dimensions}EmbeddingsMeta (currently allValsBlob1536EmbeddingsMeta ), which has a list of all indexed vals and where their embedding is stored ( batchDataIndex points to the blob, and valIndex represents the offset within the blob). The blobs have been generated by janpaul123/indexValsBlobs . It is not run automatically. Get all blobs with embeddings pointed to by the metadata, e.g. allValsBlob1536EmbeddingsData_0 for batchDataIndex 0. Call OpenAI to generate an embedding for the search query. Go through all embeddings and compute cosine similarity with the embedding for the search query. Return list sorted by similarity.
Script
import { decode as base64Decode, encode as base64Encode } from "https://deno.land/std@0.166.0/encoding/base64.ts";
import { createClient } from "https://esm.sh/@libsql/client@0.6.0/web";
import { sqlToJSON } from "https://esm.town/v/nbbaier/sqliteExportHelpers?v=22";
import { db as allValsDb } from "https://esm.town/v/sqlite/db?v=9";
sqlite2
@std
SQLite2 - Docs β This is our second generation SQLite client: it exposes a different API than std/sqlite .
Specifically, this will support the full @libsql/client interface . SQLite is a lightweight, standard database. Every Val Town account comes with its own private SQLite database that is accessible from any of your vals via std/sqlite . Val Town SQLite is powered by Turso . Usage Migrations ORMs We recommend these admin data viewers for managing your database β viewing or editing data or your database table schema: Outerbase Studio (recommended) - formely known as LibSQL Studio β see instructions here SQLite Explorer (built in Val Town) New in sqlite2 Support for inserting and retreiving values from BLOB columns. Improved performance Limits You can store 10mb on the free plan and up to 1gb on the paid plan. Contact us if you need more space. π Edit docs
Script
# SQLite2 - [Docs β](https://docs.val.town/std/sqlite)
_This is our second generation SQLite client: it exposes a different API than [std/sqlite](https://www.val.town/v/std/sqlite).
Specifically, this will support the full [@libsql/client interface](https://docs.turso.tech/sdk/ts/reference#simple-query)._
[SQLite](https://www.sqlite.org/) is a lightweight, standard database. Every Val Town account comes with its own private SQLite database that is accessible from any of your vals via [`std/sqlite`](https://www.val.town/v/std/sqlite).
import { createClient } from "https://esm.sh/@libsql/client@0.6.0/web";
export const sqlite = createClient({
url: "https://api.val.town/v2/sqlite/",
uploadTextToS3
@stevekrouse
Part of the Upload and download from AWS S3 guide .
Script
import { S3Client } from "https://deno.land/x/s3_lite_client@0.6.1/mod.ts"
const s3client = new S3Client({
endPoint: "s3.amazonaws.com",
secretKey: Deno.env.get("awsS3Secret"),
const upload = await s3client.putObject("filename.txt", "File contents");
console.log(upload)