Skip to content

Commit 81d9181

Browse files
authored
Fix url building when using a provider (#1187)
1 parent 77427c7 commit 81d9181

File tree

5 files changed

+31
-17
lines changed

5 files changed

+31
-17
lines changed

common/providers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,9 @@ export function getPresetConnection(
201201
if (provider) {
202202
const conn = getProviderConnection(provider)
203203

204+
// We always disable this feature when using a provider
205+
copy.thirdPartyUrlNoSuffix = false
206+
204207
if (conn.service) {
205208
copy.service = conn.service
206209
copy.thirdPartyFormat = undefined

common/requests/util.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ export function getOaiCompatibleUrl(
166166
isThirdParty?: boolean
167167
) {
168168
if (isThirdParty && preset.thirdPartyUrl) {
169-
if (preset.thirdPartyUrlNoSuffix) return { url: preset.thirdPartyUrl, changed: true }
169+
if (!preset.providerId && preset.thirdPartyUrlNoSuffix) {
170+
return { url: preset.thirdPartyUrl, changed: true }
171+
}
170172

171173
// If the user provides a versioned API URL for their third-party API, use that. Otherwise
172174
// fall back to the standard /v1 URL.

srv/adapter/kobold.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,12 @@ async function dispatch(opts: AdapterProps, body: any) {
151151
case 'llamacpp':
152152
case 'vllm': {
153153
body.messages = opts.imageData ? opts.messages : undefined
154-
const url = opts.gen.thirdPartyUrlNoSuffix
155-
? baseURL
156-
: body.messages
157-
? `${baseURL}/v1/chat/completions`
158-
: `${baseURL}/v1/completions`
154+
const url =
155+
!opts.gen.providerId && opts.gen.thirdPartyUrlNoSuffix
156+
? baseURL
157+
: body.messages
158+
? `${baseURL}/v1/chat/completions`
159+
: `${baseURL}/v1/completions`
159160
return opts.gen.streamResponse
160161
? streamGenerator({ ...base, url, format: opts.gen.thirdPartyFormat })
161162
: fullCompletion({ ...base, url, service: opts.gen.thirdPartyFormat })
@@ -229,12 +230,13 @@ async function dispatch(opts: AdapterProps, body: any) {
229230
body.messages = opts.messages
230231
}
231232
const url = getOaiCompatibleUrl(opts.gen, true)
232-
const fullUrl = opts.gen.thirdPartyUrlNoSuffix
233-
? url.url
234-
: joinUrl(
235-
url.url,
236-
opts.gen.thirdPartyFormat === 'openai' ? 'completions' : 'chat/completions'
237-
)
233+
const fullUrl =
234+
!opts.gen.providerId && opts.gen.thirdPartyUrlNoSuffix
235+
? url.url
236+
: joinUrl(
237+
url.url,
238+
opts.gen.thirdPartyFormat === 'openai' ? 'completions' : 'chat/completions'
239+
)
238240

239241
return opts.gen.streamResponse
240242
? streamGenerator({ ...base, url: fullUrl, format: opts.gen.thirdPartyFormat })

srv/adapter/openai.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,12 @@ export const handleOAI: ModelAdapter = async function* (opts) {
170170
log.debug(body, 'OpenAI payload')
171171
}
172172

173-
const url = gen.thirdPartyUrlNoSuffix
174-
? base.url
175-
: useChat
176-
? joinUrl(base.url, 'chat/completions')
177-
: joinUrl(base.url, 'completions')
173+
const url =
174+
!gen.providerId && !!gen.thirdPartyUrlNoSuffix
175+
? base.url
176+
: useChat
177+
? joinUrl(base.url, 'chat/completions')
178+
: joinUrl(base.url, 'completions')
178179

179180
if (opts.conn.provider?.provider === 'known-mistral' && body.messages) {
180181
const merged = ensureMessagesAlternate(body.messages, { userFirst: true, userLast: true })

srv/db/util.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { defaultChars } from '../../common/characters'
77
const ALGO = 'aes-192-cbc'
88
const KEY = crypto.scryptSync(config.jwtSecret, 'salt', 24)
99
const KEY_LB = crypto.scryptSync(`${config.jwtSecret}\n`, 'salt', 24)
10+
// const KEY_TRIM = crypto.scryptSync(`${config.jwtSecret}\\n`, 'salt', 24)
1011

1112
export function now() {
1213
return new Date().toISOString()
@@ -41,6 +42,11 @@ export function decryptText(text: string, noError?: boolean) {
4142
throw new Error('IV not found')
4243
}
4344

45+
// try {
46+
// const decipher = crypto.createDecipheriv(ALGO, KEY_TRIM as any, Buffer.from(iv, 'hex') as any)
47+
// return decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8')
48+
// } catch (ex) {}
49+
4450
try {
4551
const decipher = crypto.createDecipheriv(ALGO, KEY as any, Buffer.from(iv, 'hex') as any)
4652
return decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8')

0 commit comments

Comments
 (0)