Search

3,377 results found for openai (4125ms)

Code
3,282

from openai import OpenAI
import os
client = OpenAI(
api_key=os.environ.get(
"OPENAI_API_KEY", "<your OpenAI API key if not set as env var>"
)
)
import { type ClientOptions, OpenAI as RawOpenAI } from "npm:openai";
/**
* API Client for interfacing with the OpenAI API. Uses Val Town credentials.
*/
export class OpenAI {
private rawOpenAIClient: RawOpenAI;
/**
* API Client for interfacing with the OpenAI API. Uses Val Town credentials.
*
* @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) th
*/
constructor(options: Omit<ClientOptions, "baseURL" | "apiKey" | "organization"> = {}) {
this.rawOpenAIClient = new RawOpenAI({
...options,
baseURL: "https://std-openaiproxy.web.val.run/v1",
apiKey: Deno.env.get("valtown"),
organization: null,
get chat() {
return this.rawOpenAIClient.chat;
}
get beta() {
return {
chat: this.rawOpenAIClient.beta.chat,
};
}
# OpenAI - [Docs ↗](https://docs.val.town/std/openai)
Use OpenAI's chat completion API with [`std/openai`](https://www.val.town/v/std/openai). This in
lls are sent to `gpt-4o-mini`](https://www.val.town/v/std/openaiproxy?v=12#L85).
## Basic Usage
```ts title="Example" val
import { 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" },
## Limits
While our wrapper simplifies the integration of OpenAI, there are a few limitations to keep in m
* **Usage Quota**: We limit each user to 10 requests per minute.
If these limits are too low, let us know! You can also get around the limitation by using your o
1. Create your own API key on [OpenAI's website](https://platform.openai.com/api-keys)
l.town/settings/environment-variables?adding=true) named `OPENAI_API_KEY`
3. Use the `OpenAI` client from `npm:openai`:
```ts title="Example" val
import { OpenAI } from "npm:openai";
const openai = new OpenAI();
```
com/val-town/val-town-docs/edit/main/src/content/docs/std/openai.mdx)
Migrated from folder: openai/openai
# OpenAI - [Docs ↗](https://docs.val.town/std/openai)
Use OpenAI's chat completion API with [`std/openai`](https://www.val.town/v/std/openai). This in
lls are sent to `gpt-4o-mini`](https://www.val.town/v/std/openaiproxy?v=12#L85).
## Basic Usage
```ts title="Example" val
import { 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" },
## Limits
While our wrapper simplifies the integration of OpenAI, there are a few limitations to keep in m
* **Usage Quota**: We limit each user to 10 requests per minute.
If these limits are too low, let us know! You can also get around the limitation by using your o
1. Create your own API key on [OpenAI's website](https://platform.openai.com/api-keys)
l.town/settings/environment-variables?adding=true) named `OPENAI_API_KEY`
3. Use the `OpenAI` client from `npm:openai`:
```ts title="Example" val
import { OpenAI } from "npm:openai";
const openai = new OpenAI();
```
com/val-town/val-town-docs/edit/main/src/content/docs/std/openai.mdx)
Migrated from folder: openai/openai
import { type ClientOptions, OpenAI as RawOpenAI } from "npm:openai";
/**
* API Client for interfacing with the OpenAI API. Uses Val Town credentials.
*/
export class OpenAI {
private rawOpenAIClient: RawOpenAI;
/**
* API Client for interfacing with the OpenAI API. Uses Val Town credentials.
*
* @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) th
*/
constructor(options: Omit<ClientOptions, "baseURL" | "apiKey" | "organization"> = {}) {
this.rawOpenAIClient = new RawOpenAI({
...options,
baseURL: "https://std-openaiproxy.web.val.run/v1",
apiKey: Deno.env.get("valtown"),
organization: null,
get chat() {
return this.rawOpenAIClient.chat;
}
get beta() {
return {
chat: this.rawOpenAIClient.beta.chat,
};
}
import { type ClientOptions, OpenAI as RawOpenAI } from "npm:openai";
/**
* API Client for interfacing with the OpenAI API. Uses Val Town credentials.
*/
export class OpenAI {
private rawOpenAIClient: RawOpenAI;
/**
* API Client for interfacing with the OpenAI API. Uses Val Town credentials.
*
* @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) th
*/
constructor(options: Omit<ClientOptions, "baseURL" | "apiKey" | "organization"> = {}) {
this.rawOpenAIClient = new RawOpenAI({
...options,
baseURL: "https://std-openaiproxy.web.val.run/v1",
apiKey: Deno.env.get("valtown"),
organization: null,
get chat() {
return this.rawOpenAIClient.chat;
}
get beta() {
return {
chat: this.rawOpenAIClient.beta.chat,
};
}
import { type ClientOptions, OpenAI as RawOpenAI } from "npm:openai";
/**
* API Client for interfacing with the OpenAI API. Uses Val Town credentials.
*/
export class OpenAI {
private rawOpenAIClient: RawOpenAI;
/**
* API Client for interfacing with the OpenAI API. Uses Val Town credentials.
*
* @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) th
*/
constructor(options: Omit<ClientOptions, "baseURL" | "apiKey" | "organization"> = {}) {
this.rawOpenAIClient = new RawOpenAI({
...options,
baseURL: "https://std-openaiproxy.web.val.run/v1",
apiKey: Deno.env.get("valtown"),
organization: null,
get chat() {
return this.rawOpenAIClient.chat;
}
get beta() {
return {
chat: this.rawOpenAIClient.beta.chat,
};
}
import { fetch } from "https://esm.town/v/std/fetch";
import { OpenAI } from "https://esm.town/v/std/openai";
import { z } from "npm:zod";
import { Logger } from "./logger.ts";
const llm = async (sysPrompt, userPrompt, log, tid, model = "gpt-4o") => {
log("DEBUG", "LLM", `Calling OpenAI for TID ${tid}`);
try {
const oa = new OpenAI();
const completion = await oa.chat.completions.create({
model,
});
const content = completion.choices[0]?.message?.content;
if (!content) throw new Error("OpenAI returned no content.");
return JSON.parse(content);
} catch (err) {
log("ERROR", "LLM", `OpenAI API call failed for TID ${tid}`, { error: err.message });
throw new Error(`AI model error: ${err.message}`);
}
legal/med/main.tsx
5 matches
import { fetch } from "https://esm.town/v/std/fetch";
import { OpenAI } from "https://esm.town/v/std/openai";
import { z } from "npm:zod";
// --- CORE BACKEND LOGIC ---
const llm = async (sysPrompt, userPrompt, log, tid, model = "gpt-4o") => {
log("DEBUG", "LLM", `Calling OpenAI for TID ${tid}`);
try {
const oa = new OpenAI();
const completion = await oa.chat.completions.create({
model,
});
const content = completion.choices[0]?.message?.content;
if (!content) throw new Error("OpenAI returned no content.");
return JSON.parse(content);
} catch (err) {
log("ERROR", "LLM", `OpenAI API call failed for TID ${tid}`, { error: err.message });
throw new Error(`AI model error: ${err.message}`);
}
Note: When changing a SQLite table's schema, change the table's name (e.g., add _2 or _3) to cre
### OpenAI
```ts
import { 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" },