Search

Results include substring matches and semantically similar vals. Learn more
martinbowling avatar
emailValHandler
@martinbowling
Email AI Assistant Chat with your favorite AI via email (with enhanced attachment and content support) What It Does This advanced email AI assistant allows you to: Send emails to an AI for comprehensive analysis and responses Automatically transform your queries into structured research objectives Parse and analyze various types of content: PDF attachments Image attachments (using GPT-4 Vision) Website content from links in your email Get detailed, context-aware responses directly to your inbox Setup Guide Copy this Val and save it as an Email Val (choose Val type in the top-right corner of the editor) Set up the required environment variables: OPENAI_API_KEY: Your OpenAI API key MD_API_KEY: Your API key for the markdown extraction service (optional) You can set these using Val Town's environment variables: https://docs.val.town/reference/environment-variables/ Copy the email address of the Val (click 3 dots in top-right > Copy > Copy email address) Compose your email: Write your query or request in the email body Attach any relevant PDFs or images Include links to websites you want analyzed Send it to the Val email address Wait for the AI's response, which will arrive in your inbox shortly How to Use Effectively Be clear and specific in your queries Provide context when necessary Utilize attachments and links to give the AI more information to work with The AI will transform your query into a structured research objective, so even simple questions may yield comprehensive answers Supported File Types and Limitations PDFs: Text content will be extracted and analyzed Images: Will be analyzed using GPT-4 Vision API Websites: Content will be extracted and converted to markdown for analysis Other file types are not currently supported and will be ignored Note: There may be size limitations for attachments and processing times may vary based on the complexity of the content. The AI uses advanced prompt transformation to enhance your queries, providing more detailed and structured responses. This process helps in generating comprehensive and relevant answers to your questions.
Email
- OPENAI_API_KEY: Your OpenAI API key
- OPENAI_API_KEY: Your OpenAI API key
// Main controller function
export default async function emailValHandler(receivedEmail) {
const openaiUrl = "https://api.openai.com/v1/chat/completions";
const openaiKey = Deno.env.get("OPENAI_API_KEY");
if (!openaiKey) {
throw new Error("OPENAI_KEY environment variable is not set.");
const transformedPrompt = await transformPrompt(receivedEmail.text, openaiUrl, openaiKey, model);
const { pdfTexts, imageAnalysis } = await processAttachments(attachments, openaiKey, transformedPrompt);
// Step 5: Send to OpenAI and get response
patrickjm avatar
openAiTextCompletion
@patrickjm
An interactive, runnable TypeScript val by patrickjm
Script
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
export let openAiTextCompletion = async (params: {
/** https://beta.openai.com/account/api-keys */
apiKey: string,
/** Optional. https://beta.openai.com/account/org-settings */
org?: string,
// REST args, see https://beta.openai.com/docs/api-reference/completions/create
prompt: string,
throw new Error(
"Please provide 'apiKey' param. See: https://beta.openai.com/account/api-keys "
const { apiKey, org, ...args } = params;
args.stream = false;
const response = await fetchJSON("https://api.openai.com/v1/completions", {
method: "POST",
Authorization: `Bearer ${params.apiKey}`,
...(params.org ? { "OpenAI-Organization": params.org } : {}),
body: JSON.stringify(args),
patrickjm avatar
openAiModeration
@patrickjm
* Calls the OpenAI moderation model. Useful for determining if OpenAI will flag something you did. * https://platform.openai.com/docs/api-reference/moderations
Script
import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
* Calls the OpenAI moderation model. Useful for determining if OpenAI will flag something you did.
* https://platform.openai.com/docs/api-reference/moderations
export let openAiModeration = async ({
apiKey,
if (!apiKey) {
throw new Error("You must provide an OpenAI API Key");
const body: { model?: string, input: string|string[] } = {
const result = await fetchJSON(
"https://api.openai.com/v1/moderations",
method: "POST",
kora avatar
ownOpenAI
@kora
Use my own OpenAI API key to avoid limit
Script
Use my own OpenAI API key to avoid limit
import { OpenAI } from "npm:openai";
const openai = new OpenAI();
const completion = await openai.chat.completions.create({
"messages": [
{ "role": "user", "content": "คุณรู้จัก Gemini ไหม" },
model: "gpt-4o", // ถ้าใช้ของ std/openai จะได้แค่ gpt-4o-mini
max_tokens: 30,
stevekrouse avatar
fineTuningJob1
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
Script
import process from "node:process";
import { openaiFineTuneData } from "https://esm.town/v/stevekrouse/openaiFineTuneData";
export let fineTuningJob1 = openaiFineTuneData({
key: process.env.openai,
data: fineTuneExMispellings,
l2046a avatar
oddTanRoundworm
@l2046a
An interactive, runnable TypeScript val by l2046a
HTTP
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
status: 204,
const openai = new OpenAI();
try {
model: "gpt-4-turbo",
const stream = await openai.chat.completions.create(body);
if (!body.stream) {
maxm avatar
openAIStreaming
@maxm
OpenAI Streaming - Assistant and Threads An example of using OpenAI to stream back a chat with an assistant. This example sends two messages to the assistant and streams back the responses when they come in. Example response: user > What should I build today? ................ assistant > Here are a few fun Val ideas you could build on Val Town: 1. **Random Joke Generator:** Fetch a random joke from an API and display it. 2. **Daily Weather Update:** Pull weather data for your location using an API and create a daily summary. 3. **Mini Todo List:** Create a simple to-do list app with add, edit, and delete functionalities. 4. **Chuck Norris Facts:** Display a random Chuck Norris fact sourced from an API. 5. **Motivational Quote of the Day:** Fetch and display a random motivational quote each day. Which one sounds interesting to you? user > Cool idea, can you make it even cooler? ................... assistant > Sure, let's add some extra flair to make it even cooler! How about creating a **Motivational Quote of the Day** app with these features: 1. **Random Color Theme:** Each day, the background color/theme changes randomly. 2. **Quote Sharing:** Add an option to share the quote on social media. 3. **Daily Notifications:** Send a daily notification with the quote of the day. 4. **User Preferences:** Allow users to choose categories (e.g., success, happiness, perseverance) for the quotes they receive. Would you like some code snippets or guidance on implementing any of these features?
HTTP
# OpenAI Streaming - Assistant and Threads
An example of using OpenAI to stream back a chat with an assistant. This example sends two messages to the assistant and stre
3. **Mini Todo List:** Create a simple to-do list app with add, edit, and delete functionalities.
import OpenAI from "npm:openai";
const openai = new OpenAI();
const assistant = await openai.beta.assistants.create({
const thread = await openai.beta.threads.create();
export default async function(req: Request): Promise<Response> {
const message = await openai.beta.threads.messages.create(
const run = openai.beta.threads.runs.stream(thread.id, {
owen avatar
runHnBotTask
@owen
An interactive, runnable TypeScript val by owen
Script
import { fetch } from "https://esm.town/v/std/fetch";
export async function runHnBotTask(interval) {
console.log("interval", interval);
return fetch("https://task.owenyoung.com/runHackernewszhTask");
janpaul123 avatar
jadeMacaw
@janpaul123
An interactive, runnable TypeScript val by janpaul123
Script
import _ from "npm:lodash";
import OpenAI from "npm:openai";
export default async function semanticSearchPublicVals(query) {
const allValsBlobEmbeddingsMeta = (await blob.getJSON("allValsBlobEmbeddingsMeta")) ?? {};
db.add({ id, embedding, metadata: {} });
const openai = new OpenAI();
const embedding = await openai.embeddings.create({
model: "text-embedding-3-small",
gigmx avatar
zyloxAIChatApp
@gigmx
@jsxImportSource https://esm.sh/react@18.2.0
HTTP
import { createRoot } from "https://esm.sh/react-dom@18.2.0/client";
import OpenAI from "https://esm.sh/openai@4.28.4";
function App() {
const [messages, setMessages] = useState([]);
</div>
function client() {
createRoot(document.getElementById("root")).render(<App />);
if (typeof document !== "undefined") { client(); }
export default async function server(request: Request): Promise<Response> {
if (request.method === "POST" && new URL(request.url).pathname === "/chat") {
const { OpenAI } = await import("https://esm.town/v/std/openai");
const openai = new OpenAI();
const { message, characterPrompt } = await request.json();
const stream = await openai.chat.completions.create({
model: "gpt-4o-mini",
stevekrouse avatar
gpt4Example
@stevekrouse
GPT4 Example This uses the brand new gpt-4-1106-preview . To use this, set OPENAI_API_KEY in your Val Town Secrets .
Script
This uses the brand new `gpt-4-1106-preview`.
To use this, set `OPENAI_API_KEY` in your [Val Town Secrets](https://www.val.town/settings/secrets).
import { OpenAI } from "npm:openai";
const openai = new OpenAI();
let chatCompletion = await openai.chat.completions.create({
messages: [{
ale_annini avatar
images
@ale_annini
An interactive, runnable TypeScript val by ale_annini
Script
import { openaiImages } from "https://esm.town/v/ale_annini/openaiImages";
export const images = openaiImages({ prompt: "a dog", n: 2 });
eric avatar
metaCall
@eric
An interactive, runnable TypeScript val by eric
Script
export let metaCall = function() {
return this
ajax avatar
annoy
@ajax
An interactive, runnable TypeScript val by ajax
Script
import { resume as resume2 } from "https://esm.town/v/ajax/resume";
export async function annoy() {
const resume = resume2;
console.log({ prompt });
const response = await fetch("https://api.openai.com/v1/completions", {
method: "POST",
"Content-Type": "application/json",
"Authorization": "Bearer " + process.env.OPENAI_API_KEY, // Replace with your OpenAI API Key
body: JSON.stringify({
stevekrouse avatar
autoGPT_Test
@stevekrouse
An interactive, runnable TypeScript val by stevekrouse
Script
export let autoGPT_Test = (async () => {
const { Configuration, OpenAIApi } = await import("npm:openai@3.2.1");
const configuration = new Configuration({
apiKey: process.env.openai,
const openai = new OpenAIApi(configuration);
const completion = await openai.createChatCompletion({
model: "gpt-4",