You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Added functionality to allow users to set custom api keys (#276)
* Added functionality to allow users to set custom api keys
* Added error handling
* Changed token to apiKey
* Changed apiKey to oaiApiKey
* added azure openai ui
* Removed logging
* Changed configure to Use
* Made checked position more rounded
* Made setting api key optional if it is openai
* Modified error handling
* Add support for insufficient_quota errors
* Fixed faulty error detection
* removed logging
Copy file name to clipboardExpand all lines: client/src/components/Messages/Message.jsx
+28-2Lines changed: 28 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,15 @@ import { useGetConversationByIdQuery } from '~/data-provider';
12
12
import{cn}from'~/utils/';
13
13
importstorefrom'~/store';
14
14
15
+
functionisJson(str){
16
+
try{
17
+
JSON.parse(str);
18
+
}catch(e){
19
+
returnfalse;
20
+
}
21
+
returntrue;
22
+
}
23
+
15
24
exportdefaultfunctionMessage({
16
25
conversation,
17
26
message,
@@ -62,6 +71,23 @@ export default function Message({
62
71
}
63
72
};
64
73
74
+
constgetError=text=>{
75
+
constmatch=text.match(/\{[^{}]*\}/);
76
+
varjson=match ? match[0] : ''
77
+
if(isJson(json)){
78
+
json=JSON.parse(json);
79
+
if(json.code==='invalid_api_key'){
80
+
return'Invalid API key. Please check your API key and try again. You can access your API key by clicking on the model logo in the top-left corner of the textbox.';
81
+
}elseif(json.type==='insufficient_quota'){
82
+
return"We're sorry, but the default API key has reached its limit. To continue using this service, please set up your own API key. You can do this by clicking on the model logo in the top-left corner of the textbox.";
83
+
}else{
84
+
return`Oops! Something went wrong. Please try again in a few moments. Here's the specific error message we encountered: ${text}`;
85
+
}
86
+
}else{
87
+
return`Oops! Something went wrong. Please try again in a few moments. Here's the specific error message we encountered: ${text}`;
88
+
}
89
+
};
90
+
65
91
constprops={
66
92
className:
67
93
'w-full border-b border-black/10 dark:border-gray-900/50 text-gray-800 bg-white dark:text-gray-100 group dark:bg-gray-800'
@@ -98,7 +124,7 @@ export default function Message({
0 commit comments