From fe9a876ffce727a53ace00946d14a640b7b2e2ce Mon Sep 17 00:00:00 2001 From: Vineeth Voruganti <13438633+VVoruganti@users.noreply.github.com> Date: Thu, 5 Dec 2024 09:38:23 -0500 Subject: [PATCH] fix: Openrouter provider order --- www/app/api/chat/route.ts | 20 +++++++++--- www/package.json | 2 +- www/pnpm-lock.yaml | 66 +++++++++++++++++++++------------------ 3 files changed, 53 insertions(+), 35 deletions(-) diff --git a/www/app/api/chat/route.ts b/www/app/api/chat/route.ts index 76c7b55..9fe2eee 100644 --- a/www/app/api/chat/route.ts +++ b/www/app/api/chat/route.ts @@ -3,7 +3,8 @@ import { NextRequest, NextResponse } from 'next/server'; import { thinkCall, respondCall } from './actions'; import { honcho, getHonchoApp, getHonchoUser } from '@/utils/honcho'; import { streamText } from 'ai'; -import { createOpenAI } from '@ai-sdk/openai'; +// import { createOpenAI } from '@ai-sdk/openai'; +import { createOpenRouter } from '@openrouter/ai-sdk-provider' import * as Sentry from '@sentry/nextjs'; @@ -14,15 +15,26 @@ export const dynamic = 'force-dynamic'; // always run dynamically const OPENROUTER_API_KEY = process.env.OPENAI_API_KEY; const MODEL = process.env.MODEL || 'gpt-3.5-turbo'; -const openrouter = createOpenAI({ +const openrouter = createOpenRouter({ // custom settings, e.g. - baseURL: 'https://openrouter.ai/api/v1', + // baseURL: 'https://openrouter.ai/api/v1', apiKey: OPENROUTER_API_KEY, - compatibility: 'compatible', // strict mode, enable when using the OpenAI API + // compatibility: 'compatible', // strict mode, enable when using the OpenAI API headers: { 'HTTP-Referer': 'https://chat.bloombot.ai', 'X-Title': 'Bloombot', }, + extraBody: { + provider: { + order: [ + "DeepInfra", + "Hyperbolic", + "Fireworks", + "Together", + "Lambda" + ] + } + } }); async function saveHistory({ diff --git a/www/package.json b/www/package.json index 683d97d..5e2eb8f 100644 --- a/www/package.json +++ b/www/package.json @@ -11,7 +11,7 @@ "sync-stripe": "node scripts/stripeSync.mjs" }, "dependencies": { - "@ai-sdk/openai": "^1.0.6", + "@openrouter/ai-sdk-provider": "^0.0.6", "@radix-ui/react-label": "^2.1.0", "@radix-ui/react-slot": "^1.1.0", "@radix-ui/react-tabs": "^1.1.1", diff --git a/www/pnpm-lock.yaml b/www/pnpm-lock.yaml index 614ebc8..c8269e2 100644 --- a/www/pnpm-lock.yaml +++ b/www/pnpm-lock.yaml @@ -8,9 +8,9 @@ importers: .: dependencies: - '@ai-sdk/openai': - specifier: ^1.0.6 - version: 1.0.6(zod@3.23.8) + '@openrouter/ai-sdk-provider': + specifier: ^0.0.6 + version: 0.0.6(zod@3.23.8) '@radix-ui/react-label': specifier: ^2.1.0 version: 2.1.0(@types/react-dom@18.2.7)(@types/react@18.2.21)(react-dom@18.2.0(react@18.3.1))(react@18.3.1) @@ -186,11 +186,14 @@ importers: packages: - '@ai-sdk/openai@1.0.6': - resolution: {integrity: sha512-AhNILXn/hVD91mrokg9Wph78BiWNP/N0tJiua+UCS5TYXCbSeeqKqiodRiNxw6tDA5sGnrC6yCv8TjgY1CwzWg==} + '@ai-sdk/provider-utils@1.0.22': + resolution: {integrity: sha512-YHK2rpj++wnLVc9vPGzGFP3Pjeld2MwhKinetA0zKXOoHAT/Jit5O8kZsxcSlJPu9wvcGT1UGZEjZrtO7PfFOQ==} engines: {node: '>=18'} peerDependencies: zod: ^3.0.0 + peerDependenciesMeta: + zod: + optional: true '@ai-sdk/provider-utils@2.0.0': resolution: {integrity: sha512-uITgVJByhtzuQU2ZW+2CidWRmQqTUTp6KADevy+4aRnmILZxY2LCt+UZ/ZtjJqq0MffwkuQPPY21ExmFAQ6kKA==} @@ -201,23 +204,14 @@ packages: zod: optional: true - '@ai-sdk/provider-utils@2.0.2': - resolution: {integrity: sha512-IAvhKhdlXqiSmvx/D4uNlFYCl8dWT+M9K+IuEcSgnE2Aj27GWu8sDIpAf4r4Voc+wOUkOECVKQhFo8g9pozdjA==} + '@ai-sdk/provider@0.0.26': + resolution: {integrity: sha512-dQkfBDs2lTYpKM8389oopPdQgIU007GQyCbuPPrV+K6MtSII3HBfE0stUIMXUb44L+LK1t6GXPP7wjSzjO6uKg==} engines: {node: '>=18'} - peerDependencies: - zod: ^3.0.0 - peerDependenciesMeta: - zod: - optional: true '@ai-sdk/provider@1.0.0': resolution: {integrity: sha512-Sj29AzooJ7SYvhPd+AAWt/E7j63E9+AzRnoMHUaJPRYzOd/WDrVNxxv85prF9gDcQ7XPVlSk9j6oAZV9/DXYpA==} engines: {node: '>=18'} - '@ai-sdk/provider@1.0.1': - resolution: {integrity: sha512-mV+3iNDkzUsZ0pR2jG0sVzU6xtQY5DtSCBy3JFycLp6PwjyLw/iodfL3MwdmMCRJWgs3dadcHejRnMvF9nGTBg==} - engines: {node: '>=18'} - '@ai-sdk/react@1.0.0': resolution: {integrity: sha512-BDrZqQA07Btg64JCuhFvBgYV+tt2B8cXINzEqWknGoxqcwgdE8wSLG2gkXoLzyC2Rnj7oj0HHpOhLUxDCmoKZg==} engines: {node: '>=18'} @@ -1131,6 +1125,12 @@ packages: resolution: {integrity: sha512-nn5ozdjYQpUCZlWGuxcJY/KpxkWQs4DcbMCmKojjyrYDEAGy4Ce19NN4v5MduafTwJlbKc99UA8YhSVqq9yPZA==} engines: {node: '>=12.4.0'} + '@openrouter/ai-sdk-provider@0.0.6': + resolution: {integrity: sha512-gQY8xIAjL+KnralHetMhNRcSf0Xx2gRSKUQNadXSXQhcrSnjT53qJtYELLSR1elkOCiDkggV4ce7ROqDYOaJ+w==} + engines: {node: '>=18'} + peerDependencies: + zod: ^3.0.0 + '@opentelemetry/api-logs@0.52.1': resolution: {integrity: sha512-qnSqB2DQ9TPP96dl8cDubDvrUyWc0/sK81xHTK8eSUspzDM3bsewX903qclQFvVhgStjRWdC5bLb3kQqMkfV5A==} engines: {node: '>=14'} @@ -3128,6 +3128,10 @@ packages: resolution: {integrity: sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==} engines: {node: '>=0.8.x'} + eventsource-parser@1.1.2: + resolution: {integrity: sha512-v0eOBUbiaFojBu2s2NPBfYUoRR9GjcDNvCXVaqEf5vVfpIAh9f8RCo4vXTP8c63QRKCFwoLpMpTdPwwhEKVgzA==} + engines: {node: '>=14.18'} + eventsource-parser@3.0.0: resolution: {integrity: sha512-T1C0XCUimhxVQzW4zFipdx0SficT651NnkR0ZSH3yQwh+mFMdLfgjABVi4YtMTtaL4s168593DaoaRLMqryavA==} engines: {node: '>=18.0.0'} @@ -5913,10 +5917,13 @@ packages: snapshots: - '@ai-sdk/openai@1.0.6(zod@3.23.8)': + '@ai-sdk/provider-utils@1.0.22(zod@3.23.8)': dependencies: - '@ai-sdk/provider': 1.0.1 - '@ai-sdk/provider-utils': 2.0.2(zod@3.23.8) + '@ai-sdk/provider': 0.0.26 + eventsource-parser: 1.1.2 + nanoid: 3.3.7 + secure-json-parse: 2.7.0 + optionalDependencies: zod: 3.23.8 '@ai-sdk/provider-utils@2.0.0(zod@3.23.8)': @@ -5928,20 +5935,11 @@ snapshots: optionalDependencies: zod: 3.23.8 - '@ai-sdk/provider-utils@2.0.2(zod@3.23.8)': - dependencies: - '@ai-sdk/provider': 1.0.1 - eventsource-parser: 3.0.0 - nanoid: 3.3.7 - secure-json-parse: 2.7.0 - optionalDependencies: - zod: 3.23.8 - - '@ai-sdk/provider@1.0.0': + '@ai-sdk/provider@0.0.26': dependencies: json-schema: 0.4.0 - '@ai-sdk/provider@1.0.1': + '@ai-sdk/provider@1.0.0': dependencies: json-schema: 0.4.0 @@ -7045,6 +7043,12 @@ snapshots: '@nolyfill/is-core-module@1.0.39': {} + '@openrouter/ai-sdk-provider@0.0.6(zod@3.23.8)': + dependencies: + '@ai-sdk/provider': 0.0.26 + '@ai-sdk/provider-utils': 1.0.22(zod@3.23.8) + zod: 3.23.8 + '@opentelemetry/api-logs@0.52.1': dependencies: '@opentelemetry/api': 1.9.0 @@ -9580,6 +9584,8 @@ snapshots: events@3.3.0: {} + eventsource-parser@1.1.2: {} + eventsource-parser@3.0.0: {} execa@5.1.1: