Search

141 results found for openai (582ms)

Code
139

*/
import { OpenAI } from "https://esm.town/v/std/openai";
import type { DiscordChannel, DiscordMessage, DiscordService } from "../discord.ts";
import { isThreadAlreadyExistsError } from "../errors.ts";
): Promise<AIThreadResult | null> {
try {
const openai = new OpenAI();
const MAX_CONTEXT_CHARS = 3500;
{"thread_name": "...", "summary": "• Point 1\\n• Point 2\\n• Point 3"}`;
const completion = await openai.chat.completions.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: prompt }],
const responseText = completion.choices[0]?.message?.content?.trim();
if (!responseText) {
console.warn(`⚠️ [Autothread:AI] Empty response from OpenAI`);
return null;
}
name: {
displayName: "Name",
purpose: "What the todo says. May be cleaned up by AI if OpenAI is configured.",
category: "core",
required: true,
</dd>
{/* OpenAI */}
<dt>
<strong>OpenAI</strong>
</dt>
<dd>
<details>
<summary>
{healthData.connections.openai.status === "connected" ? (
<code className="pico-background-green-100">
Connected
</code>
) : healthData.connections.openai.status === "error" ? (
<code
className="pico-background-red-500"
<article>
<dl>
{healthData.connections.openai.status === "error" && (
<>
<dt>Error</dt>
<dd>{healthData.connections.openai.error}</dd>
</>
)}
<dt>Environment variable</dt>
<dd>
<code>{healthData.connections.openai.envVar}</code>
</dd>
</dl>
{healthData.connections.openai.status !== "connected" && (
<p>
To connect to OpenAI, add to your{" "}
{envUrl ? (
<a href={envUrl} target="_blank">
<br />
<code>
{healthData.connections.openai.envVar}=your-api-key
</code>
</p>
<pre>
{JSON.stringify(
healthData.connections.openai,
null,
2
}));
// 6. Check OpenAI connection (validate API key with actual API call)
const openaiApiKey = Deno.env.get('OPENAI_API_KEY');
let openaiStatus: 'connected' | 'not_configured' | 'error' = 'not_configured';
let openaiError: string | null = null;
if (openaiApiKey) {
const openaiResult = await aiService.validateOpenAIConnection();
if (openaiResult.success) {
openaiStatus = 'connected';
} else {
openaiStatus = 'error';
openaiError = openaiResult.error || 'Failed to connect to OpenAI';
}
}
...(databaseError ? { error: databaseError } : {})
},
openai: {
envVar: 'OPENAI_API_KEY',
status: openaiStatus,
error: openaiError
}
},
1. Click [**Remix**](/?intent=remix)
2. Add environment variables:
- `OPENAI_API_KEY` — for AI lead qualification
- `GITHUB_TOKEN` — for accessing GitHub API
([create one here](https://github.com/settings/tokens))
app.post("/", async (c) => {
// Early API key check to avoid confusing when using the tester ui
if (!Deno.env.get("OPENAI_API_KEY")) {
return c.json(
{ error: "Add OPENAI_API_KEY in Environment Variables" },
503,
);
// Test endpoint for the welcome UI
app.post("/test", async (c) => {
if (!Deno.env.get("OPENAI_API_KEY")) {
return c.json(
{ error: "Add OPENAI_API_KEY in Environment Variables" },
503,
);
// Reanalyze a lead
app.post("/lead/:id/reanalyze", async (c) => {
if (!Deno.env.get("OPENAI_API_KEY")) {
return c.json(
{ error: "Add OPENAI_API_KEY in Environment Variables" },
503,
);
import { readFile } from "https://esm.town/v/std/utils/index.ts";
import { Agent, run, webSearchTool } from "npm:@openai/agents@0.3.0";
import { getLeadById, storeLead, updateLeadOutput } from "./db.ts";
const { message, history } = await request.json();
const { OpenAI } = await import("https://esm.town/v/std/openai");
const openai = new OpenAI({ apiKey: Deno.env.get("OPENAI_API_KEY") });
// System prompt includes info about Abdullah Abdulkareem
];
const completion = await openai.chat.completions.create({
model: "gpt-4o-mini",
messages,
# OpenAI Agents Template
A Val Town template for using the OpenAI Agents SDK.
## Get Started
1. **Remix this val**
1. **Set the `OPENAI_API_KEY` environment variable.** Get your OpenAI API key
here: <https://platform.openai.com/api-keys>
1. **Customize your agent:** Edit the agent configuration in `main.ts`. You can
provide custom `instructions`, choose a different model, or add custom tools.
## Learn More
- [OpenAI Agents SDK Documentation](https://openai.github.io/openai-agents-js/)
- [OpenAI Agents Quickstart](https://openai.github.io/openai-agents-js/guides/quickstart/)
- [Val Town Documentation](https://docs.val.town/)
import { Agent, run, webSearchTool } from "npm:@openai/agents@0.3.0";
const instructions = `You research the web looking for news stories
openai-agents
kidjs
openai-agents
Template to use the OpenAI Agents SDK
Public
openai-agents
EatPraySin
openai-agents
Template to use the OpenAI Agents SDK
Public

Users

No users found

Docs

No docs found