Skip to content

Commit

Permalink
chore: add message prompt that GPT conversation backend is deprecated (
Browse files Browse the repository at this point in the history
…#815)

* chore: add message prompt that OSS-GPT conversation backend is deprecated

* chore: some minor text changes
  • Loading branch information
andyhuang18 authored May 15, 2024
1 parent fe1cdcc commit 4be0e69
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 23 deletions.
3 changes: 3 additions & 0 deletions src/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -337,5 +337,8 @@
},
"OSS_GPT_notAvailable": {
"message": "OSS-GPT currently is **NOT AVAILABLE** for %v. If you want docs support for the repository, please check [this issue](https://github.com/hypertrons/hypertrons-crx/issues/609) and make a request there :)\n\nSee [all available docs](https://oss.x-lab.info/hypercrx/docsgpt_active_docs.json)\n\nThis chat widget can also be enabled/disabled in the extension options page whenever you want."
},
"OSS_GPT_errorMessage": {
"message": "Sorry, due to cost reasons, the OSS-GPT function is currently not available. Please follow [HyperCRX](https://github.com/hypertrons/hypertrons-crx) for the latest news."
}
}
3 changes: 3 additions & 0 deletions src/locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -337,5 +337,8 @@
},
"OSS_GPT_notAvailable": {
"message": "OSS-GPT 暂未支持 %v。如果您想使此仓库得到文档问答支持,请前往[该 issue](https://github.com/hypertrons/hypertrons-crx/issues/609) 提交需求 :)\n\n查看[所有已支持文档](https://oss.x-lab.info/hypercrx/docsgpt_active_docs.json)\n\n您也可以随时在扩展选项页面中启用/禁用此聊天小部件。"
},
"OSS_GPT_errorMessage": {
"message": "很抱歉,由于成本原因,目前 OSS-GPT 功能处于停用状态。请关注 [HyperCRX](https://github.com/hypertrons/hypertrons-crx) 获取最新消息。"
}
}
47 changes: 26 additions & 21 deletions src/pages/ContentScripts/features/oss-gpt/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,31 @@ export const getAnswer = async (
question: string,
history: [string, string]
) => {
const response = await fetch(`${DOCS_GPT_ENDPOINT}/answer`, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
active_docs: activeDocs,
api_key: null,
embeddings_key: null,
history: JSON.stringify(history),
question,
}),
mode: 'cors',
});
if (!response.ok) {
return 'Oops, something went wrong.';
} else {
const data = await response.json();
const anwser = data.answer;
return anwser;
try {
const response = await fetch(`${DOCS_GPT_ENDPOINT}/answer`, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
active_docs: activeDocs,
api_key: null,
embeddings_key: null,
history: JSON.stringify(history),
question,
}),
mode: 'cors',
});
if (!response.ok) {
return 'Oops, something went wrong.';
} else {
const data = await response.json();
const answer = data.answer;
return answer;
}
} catch (error) {
console.error('Error:', error);
return 'error';
}
};
13 changes: 11 additions & 2 deletions src/pages/ContentScripts/features/oss-gpt/view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ const displayNotAvailable = (repoName: string, locale: string) => {
);
};

// Due to cost reasons, backend is not available now. This part can be removed when the backend is restored.
const backendNotAvailable = (locale: string) => {
addResponseMessage(getMessageByLocale('OSS_GPT_errorMessage', locale));
};

const View = ({ theme, currentRepo, currentDocsName }: Props): JSX.Element => {
const [options, setOptions] = useState<HypercrxOptions>(defaults);
const [history, setHistory] = useState<[string, string]>(['', '']);
Expand Down Expand Up @@ -132,8 +137,12 @@ const View = ({ theme, currentRepo, currentDocsName }: Props): JSX.Element => {

if (currentDocsName) {
const answer = await getAnswer(currentDocsName, newMessage, history);
addResponseMessage(answer);
setHistory([newMessage, answer]); // update history
if (answer == 'error') {
backendNotAvailable(options.locale);
} else {
addResponseMessage(answer);
setHistory([newMessage, answer]); // update history
}
} else {
displayNotAvailable(currentRepo, options.locale);
}
Expand Down

0 comments on commit 4be0e69

Please sign in to comment.