191&& new URL(request.url).pathname === "/generate-blog"
192) {
193const { OpenAI } = await import("https://esm.town/v/std/openai");
194const openai = new OpenAI();
195196try {
199200if (topic === "RANDOM") {
201const randomTopicCompletion = await openai.chat.completions.create({
202messages: [
203{
220}
221222const completion = await openai.chat.completions.create({
223messages: [
224{
weatherGPTmain.tsx3 matches
1import { email } from "https://esm.town/v/std/email?v=11";
2import { OpenAI } from "npm:openai";
34let location = "Asia, Taipei";
8).then(r => r.json());
910const openai = new OpenAI();
11let chatCompletion = await openai.chat.completions.create({
12messages: [{
13role: "user",
getModelBuildermain.tsx14 matches
5export async function getModelBuilder(spec: {
6type?: "llm" | "chat" | "embedding";
7provider?: "openai" | "huggingface";
8} = { type: "llm", provider: "openai" }, options?: any) {
9// 3. 從 lodash-es 中導入函數
10const { extend, cond, matches, invoke } = await import("npm:lodash-es");
22// 5. 為每個提供者設置 API 密鑰
23const args = extend({ callbacks }, options);
24if (spec?.provider === "openai")
25args.openAIApiKey = process.env.OPENAI;
26else if (spec?.provider === "huggingface")
27args.apiKey = process.env.HUGGINGFACE;
30const setup = cond([
31[
32matches({ type: "llm", provider: "openai" }),
33async () => {
34const { OpenAI } = await import("npm:langchain/llms/openai");
35return new OpenAI(args);
36},
37],
38[
39matches({ type: "chat", provider: "openai" }),
40async () => {
41const { ChatOpenAI } = await import("npm:langchain/chat_models/openai");
42return new ChatOpenAI(args);
43},
44],
45[
46matches({ type: "embedding", provider: "openai" }),
47async () => {
48const { OpenAIEmbeddings } = await import(
49"npm:langchain/embeddings/openai"
50);
51return new OpenAIEmbeddings(args);
52},
53],
287export default async function server(request) {
288if (request.method === "POST" && new URL(request.url).pathname === "/chat") {
289const { OpenAI } = await import("https://esm.town/v/std/openai");
290const openai = new OpenAI();
291292try {
339}
340341const completion = await openai.chat.completions.create({
342messages: messages,
343model: imageFiles.length > 0 ? "chatgpt-4o-latest" : "gpt-4o",
350);
351} catch (error) {
352console.error("OpenAI API error:", error);
353return new Response(
354JSON.stringify({ error: "Failed to get AI response" }),
GROKPROMPTmain.tsx11 matches
526* Server-side logic for generating prompts.
527* The server expects a POST request to "/generate-prompts" with either text or image form data.
528* It uses OpenAI API to generate detailed and concise prompts.
529*/
530export default async function server(request: Request): Promise<Response> {
531if (request.method === "POST" && new URL(request.url).pathname === "/generate-prompts") {
532try {
533const { OpenAI } = await import("https://esm.town/v/std/openai");
534const openai = new OpenAI();
535const formData = await request.formData();
536const inputType = formData.get("inputType") as string;
627}
628629console.log("Sending request to OpenAI:", JSON.stringify(analysisMessages, null, 2));
630631const completion = await openai.chat.completions.create({
632model: "chatgpt-4o-latest",
633messages: analysisMessages,
635});
636637console.log("Received response from OpenAI:", JSON.stringify(completion, null, 2));
638639const content = completion.choices[0].message.content || "";
695if (request.method === "POST" && new URL(request.url).pathname === "/clarify-prompts") {
696try {
697const { OpenAI } = await import("https://esm.town/v/std/openai");
698const openai = new OpenAI();
699const { inputType, originalInput, clarificationAnswer } = await request.json();
700749const analysisMessages = [systemMessage, userMessage];
750751console.log("Sending clarification request to OpenAI:", JSON.stringify(analysisMessages, null, 2));
752753const completion = await openai.chat.completions.create({
754model: "chatgpt-4o-latest",
755messages: analysisMessages,
757});
758759console.log("Received clarification response from OpenAI:", JSON.stringify(completion, null, 2));
760761const content = completion.choices[0].message.content || "";
VEOPROMPTERmain.tsx5 matches
307const url = new URL(request.url);
308if (url.pathname === "/generate-prompts") {
309const { OpenAI } = await import("https://esm.sh/openai@4.11.1");
310const openai = new OpenAI({
311apiKey: Deno.env.get("OPENAI_API_KEY"),
312});
313316317try {
318const completion = await openai.chat.completions.create({
319model: "chatgpt-4o-latest", // Changed from "gpt-4o-latest" to "chatgpt-4o-latest"
320messages: [
364365if (!response) {
366throw new Error("No response from OpenAI");
367}
368
5options = {},
6) => {
7// Initialize OpenAI API stub
8const { Configuration, OpenAIApi } = await import(
9"https://esm.sh/openai@3.3.0"
10);
11const configuration = new Configuration({
12apiKey: process.env.OPENAI,
13});
14const openai = new OpenAIApi(configuration);
15// Request chat completion
16const messages = typeof prompt === "string"
17? [{ role: "user", content: prompt }]
18: prompt;
19const { data } = await openai.createChatCompletion({
20model: "gpt-3.5-turbo-0613",
21messages,
1112### Toolings
13* Llms can uses [tools](https://platform.openai.com/docs/guides/function-calling), meaning you can make this an agent and a whole lot more useful.
14
15
1import { zodResponseFormat } from "https://esm.sh/openai/helpers/zod";
2import { z } from "https://esm.sh/zod";
3import { email } from "https://esm.town/v/std/email";
4import { OpenAI } from "https://esm.town/v/std/openai";
56export default async function(e: Email) {
7const client = new OpenAI();
89const Messages = z.object({
chatgptchessmain.tsx4 matches
1import { OpenAI } from "https://esm.town/v/std/openai?v=5"
2import { sqlite } from "https://esm.town/v/std/sqlite?v=6"
3import { Chess } from "npm:chess.js"
131return c.html(`<body>
132<div class='p-4'>
133<h2 class='font-bold'>OpenAI Chess</h2>
134<p class='pb-4'>Play chess against ChatGPT-4</p>
135<div id="myBoard" style="width: 400px"></div>
171chess.move(san)
172173const openai = new OpenAI()
174175let messages = []
182args: [c.req.param().id, `Requesting response to ${san}`],
183})
184const completion = await openai.chat.completions.create({
185messages: [
186{