28
29Bu uygulama şunları kullanır:
30- OpenAI GPT-4o Vision API (yemek tanıma)
31- Web kamera API'si
32- Hono.js (backend framework)
100Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to create a fresh table.
101
102### OpenAI
103```ts
104import { OpenAI } from "https://esm.town/v/std/openai";
105const openai = new OpenAI();
106const completion = await openai.chat.completions.create({
107 messages: [
108 { role: "user", content: "Say hello in a creative way" },
1import {generateObject, LanguageModel, tool} from "npm:ai"
2import {openai} from "npm:@ai-sdk/openai"
3import {google} from "npm:@ai-sdk/google"
4import {
105 constructor(provider?: AIProvider) {
106 const envProvider = Deno.env.get("AI_PROVIDER") as AIProvider | undefined
107 this.provider = provider || envProvider || "openai"
108
109 if (this.provider === "openai") {
110 if (!Deno.env.get("OPENAI_API_KEY")) {
111 console.warn("OPENAI_API_KEY environment variable not set. OpenAI calls may fail.")
112 }
113 this.model = openai("gpt-4o") as LanguageModel
114 } else if (this.provider === "gemini") {
115 if (!Deno.env.get("GOOGLE_GENERATIVE_AI_API_KEY") && !Deno.env.get("GOOGLE_API_KEY")) {
4 "npm:@ai-sdk/google@*": "0.0.23_zod@3.23.8",
5 "npm:@ai-sdk/google@0.0.23": "0.0.23_zod@3.23.8",
6 "npm:@ai-sdk/openai@*": "0.0.36_zod@3.23.8",
7 "npm:@ai-sdk/openai@0.0.36": "0.0.36_zod@3.23.8",
8 "npm:@libsql/client@*": "0.15.6",
9 "npm:@types/node@*": "22.12.0",
29 ]
30 },
31 "@ai-sdk/openai@0.0.36_zod@3.23.8": {
32 "integrity": "sha512-6IcvR35UMuuQEQPkVjzUtqDAuz6vy+PMCEL0PAS2ufHXdPPm81OTKVetqjgOPjebsikhVP0soK1pKPEe2cztAQ==",
33 "dependencies": [
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { cors } from "https://esm.sh/hono@3.11.7/middleware";
3import { OpenAI } from "https://esm.town/v/std/openai";
4import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
5
32 }
33
34 const openai = new OpenAI();
35
36 try {
37 const completion = await openai.chat.completions.create({
38 model: "gpt-4o-mini",
39 messages: [
67 enhancedPrompt
68 });
69 } catch (openaiError) {
70 console.error("OpenAI API error:", openaiError);
71 return c.json({
72 error: "OpenAI service error",
73 message: "There was an issue with the AI service. Please try again later."
74 }, 503);
6
7- Simple, clean interface for entering prompts
8- AI-powered enhancement using OpenAI
9- Before/after comparison
10- Copy-to-clipboard functionality
151. Enter your basic prompt in the input area
162. Click "Enhance Prompt"
173. The application uses OpenAI to analyze and improve your prompt
184. View the enhanced version and copy it for use with your preferred AI system
19
21
22- Frontend: HTML, JavaScript with Tailwind CSS for styling
23- Backend: TypeScript API using Hono framework and OpenAI integration
24- Deployed on Val Town
25
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { OpenAI } from "https://esm.town/v/std/openai";
3import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
4import { parseProject } from "https://esm.town/v/std/utils@85-main/index.ts";
50 }
51
52 const openai = new OpenAI();
53
54 // Create different prompts based on the content type
65 }
66
67 const completion = await openai.chat.completions.create({
68 messages: [
69 {
1import { OpenAI } from "https://esm.town/v/std/openai";
2import { readFile } from "https://esm.town/v/std/utils@85-main/index.ts";
3import { LicenseInfo, ScanResponse } from "../shared/types.ts";
125 const dataURI = `data:${imageFile.type};base64,${base64Image}`;
126
127 // Process with OpenAI
128 const licenseInfo = await extractLicenseInfo(dataURI);
129
183
184/**
185 * Extracts license information from an image using OpenAI's Vision capabilities
186 */
187async function extractLicenseInfo(imageDataUri: string): Promise<LicenseInfo> {
188 const openai = new OpenAI();
189
190 const response = await openai.chat.completions.create({
191 model: "gpt-4o",
192 messages: [
242 return JSON.parse(jsonString) as LicenseInfo;
243 } catch (error) {
244 console.error("Error parsing OpenAI response:", error);
245 return { rawText: content };
246 }
108
109 <footer class="mt-12 text-center text-sm text-gray-500">
110 <p>This application processes images using OpenAI's API. Images are not stored permanently.</p>
111 <p class="mt-1">
112 <a
16
171. Upload an image of a driver's license
182. The application uses OpenAI's Vision capabilities to analyze the image
193. The extracted information is returned in a structured JSON format
20
33## Privacy Notice
34
35This application processes images using OpenAI's API. Images are not stored permanently but are transmitted to OpenAI for processing. Please ensure you have appropriate consent before uploading any personal identification documents.