Skip to content

Commit

Permalink
chore (examples): Use openai-compatible over openai where relevant. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
shaper authored Jan 3, 2025
1 parent e9d5a04 commit 453d139
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const perplexity = createOpenAICompatible({
});

const { text } = await generateText({
model: perplexity('llama-3.1-sonar-large-32k-online'),
model: perplexity('llama-3.1-sonar-small-128k-online'),
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});
```
Expand Down
10 changes: 6 additions & 4 deletions examples/ai-core/src/generate-text/deepseek.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { createOpenAI } from '@ai-sdk/openai';
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { generateText } from 'ai';
import 'dotenv/config';

const deepSeek = createOpenAI({
const deepSeek = createOpenAICompatible({
name: 'deepseek',
baseURL: 'https://api.deepseek.com',
apiKey: process.env.DEEPSEEK_API_KEY!,
headers: {
Authorization: `Bearer ${process.env.DEEPSEEK_API_KEY ?? ''}`,
},
});

async function main() {
const { text, usage } = await generateText({
model: deepSeek('deepseek-coder'),
model: deepSeek('deepseek-chat'),
prompt: 'Write a "Hello, World!" program in TypeScript.',
});

Expand Down
8 changes: 5 additions & 3 deletions examples/ai-core/src/stream-text/baseten.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createOpenAI } from '@ai-sdk/openai';
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { streamText } from 'ai';
import 'dotenv/config';

Expand All @@ -11,9 +11,11 @@ const basetenExtraPayload = {
deployment_id: BASETEN_DEPLOYMENT_ID,
};

const baseten = createOpenAI({
const baseten = createOpenAICompatible({
name: 'baseten',
apiKey: process.env.BASETEN_API_KEY ?? '',
headers: {
Authorization: `Bearer ${process.env.BASETEN_API_KEY ?? ''}`,
},
baseURL: 'https://bridge.baseten.co/v1/direct',
fetch: async (url, request) => {
if (!request || !request.body) {
Expand Down
4 changes: 2 additions & 2 deletions examples/ai-core/src/stream-text/lmstudio.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createOpenAI } from '@ai-sdk/openai';
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { streamText } from 'ai';
import 'dotenv/config';

const lmstudio = createOpenAI({
const lmstudio = createOpenAICompatible({
name: 'lmstudio',
baseURL: 'http://localhost:1234/v1',
});
Expand Down
10 changes: 6 additions & 4 deletions examples/ai-core/src/stream-text/perplexity.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { createOpenAI } from '@ai-sdk/openai';
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { streamText } from 'ai';
import 'dotenv/config';

const perplexity = createOpenAI({
const perplexity = createOpenAICompatible({
name: 'perplexity',
apiKey: process.env.PERPLEXITY_API_KEY ?? '',
headers: {
Authorization: `Bearer ${process.env.PERPLEXITY_API_KEY ?? ''}`,
},
baseURL: 'https://api.perplexity.ai/',
});

async function main() {
const result = streamText({
model: perplexity('llama-3.1-sonar-large-32k-online'),
model: perplexity('llama-3.1-sonar-small-128k-online'),
prompt:
'List the top 5 San Francisco news from the past week.' +
'You must include the date of each article.',
Expand Down
1 change: 1 addition & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"AWS_REGION",
"AWS_ACCESS_KEY_ID",
"AWS_SECRET_ACCESS_KEY",
"BASETEN_API_KEY",
"COHERE_API_KEY",
"DEEPINFRA_API_KEY",
"DEEPSEEK_API_KEY",
Expand Down

0 comments on commit 453d139

Please sign in to comment.