Search
Code3,267
1. **Website Discovery**: If no website is provided, searches DuckDuckGo to find the company's official website2. **HTML Fetching**: Retrieves the raw HTML from the company's homepage3. **AI Logo Extraction**: Uses OpenAI's GPT-4o-mini with enhanced logic to locate the company logo4. **Format Prioritization**: Prefers Inline SVG > SVG files > PNG > other image formats5. **Inline SVG Conversion**: Converts inline SVG elements to base64 encoded data URLs2. **Page Discovery**: Tries multiple pages including homepage, /about, /contact, /about-us, /contact-us, /company, /locations, /office, /headquarters3. **HTML Analysis**: Fetches HTML from each page until an address is found4. **AI Address Extraction**: Uses OpenAI to locate and format the company's physical address## Example Usage## Rate LimitsThis API uses OpenAI's services, so it's subject to OpenAI's rate limits. For production use, consider implementing caching and rate limiting.## Technical Details- Built with Hono framework on Val Town- Uses OpenAI GPT-4o-mini for logo and address extraction- Supports both provided websites and automatic website discovery- Handles relative and absolute URL conversion
import { Hono } from "https://esm.sh/hono@3.11.7";import { OpenAI } from "https://esm.town/v/std/openai";const app = new Hono();}// Helper function to extract logo URL using OpenAIasync function extractLogoUrl(html: string, websiteUrl: string): Promise<string | null> { try { // Use custom API key if provided, otherwise use Val Town's built-in integration const apiKey = Deno.env.get('OPENAI_API_KEY'); const openai = apiKey ? new OpenAI({ apiKey }) : new OpenAI(); const prompt = `I will provide you with the HTML source code of a company's website. Please examine the HTML to locate the company logo and return the appropriate URL or data.${html.substring(0, 25000)}`; // Increased for better SVG detection const completion = await openai.chat.completions.create({ messages: [ { role: "user", content: prompt } return result; } catch (error) { console.error('Error extracting logo URL with OpenAI:', error); return null; }}// Helper function to extract company address using OpenAIasync function extractCompanyAddress(html: string, websiteUrl: string): Promise<string | null> { try { // Use custom API key if provided, otherwise use Val Town's built-in integration const apiKey = Deno.env.get('OPENAI_API_KEY'); const openai = apiKey ? new OpenAI({ apiKey }) : new OpenAI(); const prompt = `I will provide you with the HTML source code of a company's website. Please examine the HTML to locate the company's physical address/headquarters address.${html.substring(0, 15000)}`; const completion = await openai.chat.completions.create({ messages: [ { role: "user", content: prompt } return result; } catch (error) { console.error('Error extracting company address with OpenAI:', error); return null; } console.log(`Extracting logo URL from HTML (${html.length} characters)...`); // Extract logo URL using OpenAI const logoUrl = await extractLogoUrl(html, websiteUrl);
// @ts-ignoreimport { OpenAI } from "https://esm.town/v/std/openai?v=4";// @ts-ignoreimport { Hono } from "npm:hono@4.4.12";}// --- BACKEND LOGIC: HONO ROUTER & OPENAI INTEGRATION ---const app = new Hono();app.post("/generate-config-ui", async (c) => { try { const openai = new OpenAI(); // The kernel matrices are too large to be useful in the prompt, so they are omitted. .replace("<SVG_SOURCE>", SVG_SOURCE_CODE); const completion = await openai.chat.completions.create({ model: "gpt-4o", messages: [
// @ts-ignoreimport { OpenAI } from "https://esm.town/v/std/openai?v=4";import { Hono } from "npm:hono@4.4.12"; try { const openai = new OpenAI(); const completion = await openai.chat.completions.create({ model: "gpt-4o", // Using gpt-4o for better spatial reasoning and precise output messages: [
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.### OpenAI```tsimport { OpenAI } from "https://esm.town/v/std/openai";const openai = new OpenAI();const completion = await openai.chat.completions.create({ messages: [ { role: "user", content: "Say hello in a creative way" },
FilesToolHandlers, KVToolHandlers, OpenAIToolHandlers, AdminToolHandlers,} from "../tools/handlers/index.ts"; private filesHandlers: FilesToolHandlers; private codeHandlers: CodeToolHandlers; private openaiHandlers: OpenAIToolHandlers; private adminHandlers: AdminToolHandlers; this.kvHandlers = new KVToolHandlers(docClient, DYNAMODB_TABLE); this.filesHandlers = new FilesToolHandlers(s3Client, S3_BUCKET); this.openaiHandlers = new OpenAIToolHandlers(); this.adminHandlers = new AdminToolHandlers(docClient, DYNAMODB_TABLE, this.filesHandlers, s3Client, S3_BUCKET); }, { name: "openai-chat-completion", handler: (args: any, authContext: AuthContext) => this.openaiHandlers.handleChatCompletion(args, authContext), }, { return await toolErrorWrapper(this.codeHandlers.handleListSkills(args, authContext)); // OpenAI tools case "openai-chat-completion": return await toolErrorWrapper(this.openaiHandlers.handleChatCompletion(args, authContext)); // Admin tools (only available in admin mode)
import { Bot, webhookCallback } from "https://deno.land/x/grammy@v1.35.0/mod.ts";import { OpenAI } from "https://esm.town/v/std/openai";// הטוקן הראשי עדיין נחוץ כדי שהבוט ידע מי הוא const currentMode = userModes[chatId] || "tutor"; console.log(`ChatID ${chatId} in mode '${currentMode}' sent: ${text}`); const response = await getOpenAIResponse(text, currentMode); ctx.reply(response);});async function getOpenAIResponse(text: string, mode: string) { const personality = botPersonalities[mode]; if (!personality) return "Error: Invalid mode selected."; const openai = new OpenAI(); const completion = await openai.chat.completions.create({ messages: [ { role: "system", content: personality.prompt },
// /api/story-options.ts – Edge runtimeimport { OpenAI } from "https://esm.town/v/std/openai";const openai = new OpenAI();// More robust version that handles edge cases }, ]; /* ───── OpenAI call ───── */ const completion = await openai.chat.completions.create({ model: "gpt-4o", messages,
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.### OpenAI```tsimport { OpenAI } from "https://esm.town/v/std/openai";const openai = new OpenAI();const completion = await openai.chat.completions.create({messages: [{ role: "user", content: "Say hello in a creative way" },
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.### OpenAI```tsimport { OpenAI } from "https://esm.town/v/std/openai";const openai = new OpenAI();const completion = await openai.chat.completions.create({ messages: [ { role: "user", content: "Say hello in a creative way" },
reconsumeralization
import { OpenAI } from "https://esm.town/v/std/openai";
import { sqlite } from "https://esm.town/v/stevekrouse/sqlite";
/**
* Practical Implementation of Collective Content Intelligence
* Bridging advanced AI with collaborative content creation
*/
exp
kwhinnery_openai
lost1991
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",
No docs found