184): Promise<CompletionResponse> {
185// Implement function calling for Google
186// Note: Gemini has different function calling format than OpenAI
187throw new Error("Function calling not yet implemented for Google provider");
188}
LlmDashboardllm-provider-openai24 matches
1/**
2* llm-provider-openai.ts
3* OpenAI-specific provider implementation
4*/
56import { OpenAI } from "https://esm.town/v/std/openai";
7import type {
8BaseModel,
1617/**
18* OpenAI-specific parameter extensions
19*/
20export interface OpenAIParams {
21reasoningEffort?: number; // For models with reasoning capabilities
22jsonMode?: boolean; // Force JSON output
2526/**
27* OpenAI model configuration with provider-specific params
28*/
29export type OpenAIConfig = WithProviderParams<BaseModelConfig, OpenAIParams>;
3031/**
32* OpenAI-specific model interface
33*/
34interface OpenAIModel extends BaseModel {
35providerSpecific: OpenAIParams;
36}
3738export class OpenAIProvider implements BaseProvider {
39readonly id = "openai";
40readonly name = "OpenAI";
41private client: OpenAI;
4243constructor() {
44this.client = new OpenAI();
45}
4647models: OpenAIModel[] = [
48{
49id: "gpt-4",
123prompt: string | Message[],
124modelId?: string,
125config?: OpenAIConfig,
126): Promise<CompletionResponse> {
127const model = this.models.find(m => m.id === (modelId || this.defaultModel));
167};
168} catch (error) {
169throw new Error(`OpenAI API error: ${error.message}`);
170}
171}
175functions: FunctionDefinition[],
176modelId?: string,
177config?: OpenAIConfig,
178): Promise<CompletionResponse> {
179const model = this.models.find(m => m.id === (modelId || this.defaultModel));
223};
224} catch (error) {
225throw new Error(`OpenAI API error: ${error.message}`);
226}
227}
228229private calculateCost(
230model: OpenAIModel,
231inputTokens: number,
232outputTokens: number,
241prompt: string | Message[],
242modelId?: string,
243config?: OpenAIConfig,
244): AsyncIterableIterator<CompletionResponse> {
245const model = this.models.find(m => m.id === (modelId || this.defaultModel));
282}
283} catch (error) {
284throw new Error(`OpenAI API error: ${error.message}`);
285}
286}
287}
288289export default OpenAIProvider;
chatGPTClonemain.tsx4 matches
89export default async function server(request: Request): Promise<Response> {
90if (request.method === 'POST' && new URL(request.url).pathname === '/chat') {
91const { OpenAI } = await import("https://esm.town/v/std/openai");
92const openai = new OpenAI();
9394try {
95const { messages } = await request.json();
96
97const completion = await openai.chat.completions.create({
98messages: messages,
99model: "gpt-4o-mini",
107});
108} catch (error) {
109console.error('OpenAI Error:', error);
110return new Response(JSON.stringify({
111message: 'Sorry, there was an error processing your request.'
BikramNpExplorerAppmain.tsx3 matches
79export default async function server(request: Request): Promise<Response> {
80if (request.method === 'POST' && new URL(request.url).pathname === '/chat') {
81const { OpenAI } = await import("https://esm.town/v/std/openai");
82const openai = new OpenAI();
8384const body = await request.json();
85const completion = await openai.chat.completions.create({
86messages: [
87{
emailSummaryHandlermain.tsx3 matches
2import { email } from "https://esm.town/v/std/email";
3import { extractValInfo } from "https://esm.town/v/stevekrouse/extractValInfo";
4import { OpenAI } from "npm:openai";
56function stripHtmlBackticks(html: string): string {
910export default async function(e: Email) {
11const openai = new OpenAI();
12console.log(`from: ${e.from} to: ${e.to} subject: ${e.subject}, cc: ${e.cc}, bcc: ${e.bcc}`);
1325}
2627const summary = await openai.chat.completions.create({
28messages: [
29{
surprisingEmbeddingsbots5 matches
61},
62"ChatGPT-User": {
63"operator": "[OpenAI](https://openai.com)",
64"respect": "Yes",
65"function": "Takes action based on user prompts.",
169},
170"GPTBot": {
171"operator": "[OpenAI](https://openai.com)",
172"respect": "Yes",
173"function": "Scrapes data to train OpenAI's products.",
174"frequency": "No information.",
175"description":
239},
240"OAI-SearchBot": {
241"operator": "[OpenAI](https://openai.com)",
242"respect": "[Yes](https://platform.openai.com/docs/bots)",
243"function": "Search result generation.",
244"frequency": "No information.",
regexToBrainrotmain.tsx4 matches
300{ getRandomRegexExplanation, saveRegexExplanation, getRegexExplanationById },
301ReactMarkdown,
302{ OpenAI },
303{ renderToString },
304{ jsx, jsxs, Fragment },
306import("https://esm.town/v/stainless_em/brainrotdb"),
307import("npm:react-markdown@7"),
308import("https://esm.town/v/std/openai"),
309import("npm:react-dom@19/server.browser"),
310import("npm:react@19/jsx-runtime"),
336}
337338const openai = new OpenAI();
339340const abortController = new AbortController();
341const completion = await openai.chat.completions.create({
342messages: [
343{
dogfoodingmain.tsx3 matches
86/>
87<FeatureItem
88href="https://www.val.town/v/std/openaiproxy"
89title="OpenAI Proxy"
90description="Provide a secure and efficient proxy for OpenAI API calls"
91/>
92<FeatureItem
1# OpenAI - [Docs ↗](https://docs.val.town/std/openai)
23Use OpenAI's chat completion API with [`std/openai`](https://www.val.town/v/std/openai). This integration enables access to OpenAI's language models without needing to acquire API keys.
45For free Val Town users, [all calls are sent to `gpt-4o-mini`](https://www.val.town/v/std/openaiproxy?v=12#L85).
67## Basic Usage
89```ts title="Example" val
10import { OpenAI } from "https://esm.town/v/std/openai";
1112const openai = new OpenAI();
1314const completion = await openai.chat.completions.create({
15messages: [
16{ role: "user", content: "Say hello in a creative way" },
58## Limits
5960While our wrapper simplifies the integration of OpenAI, there are a few limitations to keep in mind:
6162* **Usage Quota**: We limit each user to 10 requests per minute.
65If these limits are too low, let us know! You can also get around the limitation by using your own keys:
66671. Create your own API key on [OpenAI's website](https://platform.openai.com/api-keys)
682. Create an [environment variable](https://www.val.town/settings/environment-variables?adding=true) named `OPENAI_API_KEY`
693. Use the `OpenAI` client from `npm:openai`:
7071```ts title="Example" val
72import { OpenAI } from "npm:openai";
7374const openai = new OpenAI();
75```
767778[📝 Edit docs](https://github.com/val-town/val-town-docs/edit/main/src/content/docs/std/openai.mdx)
1import { type ClientOptions, OpenAI as RawOpenAI } from "npm:openai";
23/**
4* API Client for interfacing with the OpenAI API. Uses Val Town credentials.
5*/
6export class OpenAI {
7private rawOpenAIClient: RawOpenAI;
89/**
10* API Client for interfacing with the OpenAI API. Uses Val Town credentials.
11*
12* @param {number} [opts.timeout=10 minutes] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
19*/
20constructor(options: Omit<ClientOptions, "baseURL" | "apiKey" | "organization"> = {}) {
21this.rawOpenAIClient = new RawOpenAI({
22...options,
23baseURL: "https://std-openaiproxy.web.val.run/v1",
24apiKey: Deno.env.get("valtown"),
25organization: null,
2829get chat() {
30return this.rawOpenAIClient.chat;
31}
3233get beta() {
34return {
35chat: this.rawOpenAIClient.beta.chat,
36};
37}