-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Switch LLM streaming to OpenAI client #11138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,24 @@ | ||
| import { createAnthropic } from '@ai-sdk/anthropic'; | ||
| import OpenAI from 'openai'; | ||
|
|
||
| export function getAnthropicModel(apiKey: string) { | ||
| const anthropic = createAnthropic({ | ||
| apiKey, | ||
| }); | ||
| const BASE_URL = 'https://integrate.api.nvidia.com/v1'; | ||
| const MODEL_NAME = 'moonshotai/kimi-k2-instruct-0905'; | ||
|
|
||
| return anthropic('claude-3-5-sonnet-20240620'); | ||
| let cachedClient: { apiKey: string; client: OpenAI } | undefined; | ||
|
|
||
| export function getOpenAIClient(apiKey: string) { | ||
| if (!cachedClient || cachedClient.apiKey !== apiKey) { | ||
| cachedClient = { | ||
| apiKey, | ||
| client: new OpenAI({ | ||
| apiKey, | ||
| baseURL: BASE_URL, | ||
| }), | ||
| }; | ||
| } | ||
|
|
||
| return cachedClient.client; | ||
| } | ||
|
|
||
| export function getModelName() { | ||
| return MODEL_NAME; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,16 @@ interface Logger { | |
| setLevel: (level: DebugLevel) => void; | ||
| } | ||
|
|
||
| let currentLevel: DebugLevel = import.meta.env.VITE_LOG_LEVEL ?? import.meta.env.DEV ? 'debug' : 'info'; | ||
| const DEBUG_LEVELS: DebugLevel[] = ['trace', 'debug', 'info', 'warn', 'error']; | ||
| const isProduction = process.env.NODE_ENV === 'production'; | ||
| const envDebugLevel = | ||
| (process.env.NEXT_PUBLIC_LOG_LEVEL as DebugLevel | undefined) ?? | ||
| (process.env.LOG_LEVEL as DebugLevel | undefined); | ||
|
Comment on lines
+14
to
+18
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This module now reads Useful? React with 👍 / 👎. |
||
| const resolvedEnvLevel = envDebugLevel && DEBUG_LEVELS.includes(envDebugLevel as DebugLevel) | ||
| ? (envDebugLevel as DebugLevel) | ||
| : undefined; | ||
|
|
||
| let currentLevel: DebugLevel = resolvedEnvLevel ?? (isProduction ? 'info' : 'debug'); | ||
|
|
||
| const isWorker = 'HTMLRewriter' in globalThis; | ||
| const supportsColor = !isWorker; | ||
|
|
@@ -37,7 +46,7 @@ export function createScopedLogger(scope: string): Logger { | |
| } | ||
|
|
||
| function setLevel(level: DebugLevel) { | ||
| if ((level === 'trace' || level === 'debug') && import.meta.env.PROD) { | ||
| if ((level === 'trace' || level === 'debug') && isProduction) { | ||
| return; | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new streaming implementation targets NVIDIA’s OpenAI-compatible endpoint, yet
getAPIKeystill returnsANTHROPIC_API_KEYwhen no NVIDIA key is set. In environments that only configured the old Anthropic key (the previous default), the call will proceed with that key and fail at runtime with an opaque 401 instead of failing fast with a clear configuration error. Now thatEnvdeclaresNVIDIA_API_KEYas required, this function should throw when that key is missing rather than silently accepting an incompatible one.Useful? React with 👍 / 👎.