Skip to content
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

chore: remote models error handling #4059

Merged
merged 5 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/browser/extensions/engines/helpers/sse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
let errorCode = ErrorCode.Unknown
if (data.error) {
errorCode = data.error.code ?? data.error.type ?? ErrorCode.Unknown
} else if (response.status === 401) {
errorCode = ErrorCode.InvalidApiKey

Check warning on line 38 in core/src/browser/extensions/engines/helpers/sse.ts

View workflow job for this annotation

GitHub Actions / coverage-check

37-38 lines are not covered with tests
}
const error = {
message: data.error?.message ?? 'Error occurred.',
message: data.error?.message ?? data.message ?? 'Error occurred.',
code: errorCode,
}
subscriber.error(error)
Expand Down Expand Up @@ -71,27 +71,27 @@
for (const line of lines) {
try {
if (transformResponse) {
content += transformResponse(line)
subscriber.next(content ?? '')

Check warning on line 75 in core/src/browser/extensions/engines/helpers/sse.ts

View workflow job for this annotation

GitHub Actions / coverage-check

74-75 lines are not covered with tests
} else {
const toParse = cachedLines + line
if (!line.includes('data: [DONE]')) {
const data = JSON.parse(toParse.replace('data: ', ''))
content += data.choices[0]?.delta?.content ?? ''
if (content.startsWith('assistant: ')) {
content = content.replace('assistant: ', '')

Check warning on line 82 in core/src/browser/extensions/engines/helpers/sse.ts

View workflow job for this annotation

GitHub Actions / coverage-check

82 line is not covered with tests
}
if (content !== '') subscriber.next(content)
}
}
} catch {
cachedLines = line

Check warning on line 88 in core/src/browser/extensions/engines/helpers/sse.ts

View workflow job for this annotation

GitHub Actions / coverage-check

88 line is not covered with tests
}
}
}
}
subscriber.complete()
})
.catch((err) => subscriber.error(err))

Check warning on line 95 in core/src/browser/extensions/engines/helpers/sse.ts

View workflow job for this annotation

GitHub Actions / coverage-check

95 line is not covered with tests
})
}
4 changes: 3 additions & 1 deletion extensions/inference-cohere-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ export default class JanInferenceCohereExtension extends RemoteOAIEngine {
}

transformResponse = (data: any) => {
return typeof data === 'object' ? data.text : JSON.parse(data).text ?? ''
return typeof data === 'object'
? data.text
: (JSON.parse(data.replace('data: ', '').trim()).text ?? '')
}
}
2 changes: 1 addition & 1 deletion extensions/inference-openai-extension/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@janhq/inference-openai-extension",
"productName": "OpenAI Inference Engine",
"version": "1.0.3",
"version": "1.0.4",
"description": "This extension enables OpenAI chat completion API calls",
"main": "dist/index.js",
"module": "dist/module.js",
Expand Down
2 changes: 2 additions & 0 deletions extensions/inference-openai-extension/resources/models.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"parameters": {
"temperature": 1,
"top_p": 1,
"stream": true,
"max_tokens": 32768,
"frequency_penalty": 0,
"presence_penalty": 0
Expand Down Expand Up @@ -126,6 +127,7 @@
"temperature": 1,
"top_p": 1,
"max_tokens": 65536,
"stream": true,
"frequency_penalty": 0,
"presence_penalty": 0
},
Expand Down
1 change: 0 additions & 1 deletion extensions/inference-openai-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export default class JanInferenceOpenAIExtension extends RemoteOAIEngine {
return {
...params,
max_completion_tokens: max_tokens,
stream: false, // o1 only support stream = false
}
}
// Pass through for non-preview models
Expand Down
3 changes: 0 additions & 3 deletions web/containers/ErrorMessage/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ describe('ErrorMessage Component', () => {

render(<ErrorMessage message={message} />)

expect(
screen.getByText('Apologies, something’s amiss!')
).toBeInTheDocument()
expect(screen.getByText('troubleshooting assistance')).toBeInTheDocument()
})

Expand Down
8 changes: 3 additions & 5 deletions web/containers/ErrorMessage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

const getErrorTitle = () => {
switch (message.error_code) {
case ErrorCode.Unknown:
return 'Apologies, something’s amiss!'
case ErrorCode.InvalidApiKey:
case ErrorCode.AuthenticationError:
case ErrorCode.InvalidRequestError:
Expand All @@ -38,13 +36,13 @@
<button
className="font-medium text-[hsla(var(--app-link))] underline"
onClick={() => {
setMainState(MainViewState.Settings)

Check warning on line 39 in web/containers/ErrorMessage/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

39 line is not covered with tests

if (activeThread?.assistants[0]?.model.engine) {
const engine = EngineManager.instance().get(

Check warning on line 42 in web/containers/ErrorMessage/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

41-42 lines are not covered with tests
activeThread.assistants[0].model.engine
)
engine?.name && setSelectedSettingScreen(engine.name)

Check warning on line 45 in web/containers/ErrorMessage/index.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

45 line is not covered with tests
}
}}
>
Expand All @@ -55,17 +53,17 @@
)
default:
return (
<>
<p>
{message.content[0]?.text?.value && (
<AutoLink text={message.content[0].text.value} />
)}
</>
</p>
)
}
}

return (
<div className="mt-10">
<div className="mx-auto mt-10 max-w-[700px]">
{message.status === MessageStatus.Error && (
<div
key={message.id}
Expand Down
6 changes: 5 additions & 1 deletion web/containers/Providers/EventHandler.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ export default function EventHandler({ children }: { children: ReactNode }) {
setIsGeneratingResponse(false)
}
return
} else if (message.status === MessageStatus.Error) {
} else if (
message.status === MessageStatus.Error &&
activeModelRef.current?.engine &&
isLocalEngine(activeModelRef.current.engine)
) {
;(async () => {
if (
!(await extensionManager
Expand Down
Loading