From eee5977e0849e20290bd6577a87c8f2876af962c Mon Sep 17 00:00:00 2001 From: YanceyOfficial Date: Thu, 10 Oct 2024 16:55:40 +0800 Subject: [PATCH] refactor: use the sdk of openai and azure openai --- package.json | 1 + pnpm-lock.yaml | 93 +++++++ src/components/ChatBox/ContactHeader.tsx | 2 +- src/components/ChatBox/InputBox.tsx | 2 +- src/components/ChatBox/Markdown.tsx | 18 +- .../{TextCompletion.tsx => Completion.tsx} | 36 +-- src/components/Configuration/index.ts | 6 +- src/components/Sidebar/Items.tsx | 2 +- .../{textCompletion.ts => completion.ts} | 4 +- src/configurations/imageGeneration.ts | 4 +- src/configurations/index.ts | 12 +- src/hooks/index.ts | 10 +- src/hooks/useAppData.ts | 10 +- src/hooks/useAudio.ts | 92 +++++-- src/hooks/useChatCompletion.ts | 253 ++++++++++++------ src/hooks/useClients.ts | 22 ++ src/hooks/useCompletion.ts | 98 +++++++ src/hooks/useImageGeneration.ts | 76 ++---- src/hooks/useOpenAI.ts | 16 -- src/hooks/useRequest.ts | 22 +- src/hooks/useSevices.ts | 69 ----- src/hooks/useTextCompletion.ts | 63 ----- src/types/conversation.ts | 4 +- src/types/global.ts | 10 +- 24 files changed, 553 insertions(+), 372 deletions(-) rename src/components/Configuration/{TextCompletion.tsx => Completion.tsx} (91%) rename src/configurations/{textCompletion.ts => completion.ts} (86%) create mode 100644 src/hooks/useClients.ts create mode 100644 src/hooks/useCompletion.ts delete mode 100644 src/hooks/useOpenAI.ts delete mode 100644 src/hooks/useSevices.ts delete mode 100644 src/hooks/useTextCompletion.ts diff --git a/package.json b/package.json index 7ee7639..8d961a6 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s" }, "dependencies": { + "@azure/openai": "1.0.0-beta.12", "@emoji-mart/data": "^1.2.1", "@emoji-mart/react": "^1.1.1", "@emotion/react": "^11.13.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fc2d237..b0b7418 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,6 +5,9 @@ settings: excludeLinksFromLockfile: false dependencies: + '@azure/openai': + specifier: 1.0.0-beta.12 + version: 1.0.0-beta.12 '@emoji-mart/data': specifier: ^1.2.1 version: 1.2.1 @@ -226,6 +229,96 @@ packages: is-potential-custom-element-name: 1.0.1 dev: false + /@azure-rest/core-client@1.4.0: + resolution: {integrity: sha512-ozTDPBVUDR5eOnMIwhggbnVmOrka4fXCs8n8mvUo4WLLc38kki6bAOByDoVZZPz/pZy2jMt2kwfpvy/UjALj6w==} + engines: {node: '>=18.0.0'} + dependencies: + '@azure/abort-controller': 2.1.2 + '@azure/core-auth': 1.8.0 + '@azure/core-rest-pipeline': 1.17.0 + '@azure/core-tracing': 1.2.0 + '@azure/core-util': 1.10.0 + tslib: 2.7.0 + transitivePeerDependencies: + - supports-color + dev: false + + /@azure/abort-controller@2.1.2: + resolution: {integrity: sha512-nBrLsEWm4J2u5LpAPjxADTlq3trDgVZZXHNKabeXZtpq3d3AbN/KGO82R87rdDz5/lYB024rtEf10/q0urNgsA==} + engines: {node: '>=18.0.0'} + dependencies: + tslib: 2.7.0 + dev: false + + /@azure/core-auth@1.8.0: + resolution: {integrity: sha512-YvFMowkXzLbXNM11yZtVLhUCmuG0ex7JKOH366ipjmHBhL3vpDcPAeWF+jf0X+jVXwFqo3UhsWUq4kH0ZPdu/g==} + engines: {node: '>=18.0.0'} + dependencies: + '@azure/abort-controller': 2.1.2 + '@azure/core-util': 1.10.0 + tslib: 2.7.0 + dev: false + + /@azure/core-rest-pipeline@1.17.0: + resolution: {integrity: sha512-62Vv8nC+uPId3j86XJ0WI+sBf0jlqTqPUFCBNrGtlaUeQUIXWV/D8GE5A1d+Qx8H7OQojn2WguC8kChD6v0shA==} + engines: {node: '>=18.0.0'} + dependencies: + '@azure/abort-controller': 2.1.2 + '@azure/core-auth': 1.8.0 + '@azure/core-tracing': 1.2.0 + '@azure/core-util': 1.10.0 + '@azure/logger': 1.1.4 + http-proxy-agent: 7.0.2 + https-proxy-agent: 7.0.5 + tslib: 2.7.0 + transitivePeerDependencies: + - supports-color + dev: false + + /@azure/core-sse@2.1.3: + resolution: {integrity: sha512-KSSdIKy8kvWCpYr8Hzpu22j3wcXsVTYE0IlgmI1T/aHvBDsLgV91y90UTfVWnuiuApRLCCVC4gS09ApBGOmYQA==} + engines: {node: '>=18.0.0'} + dependencies: + tslib: 2.7.0 + dev: false + + /@azure/core-tracing@1.2.0: + resolution: {integrity: sha512-UKTiEJPkWcESPYJz3X5uKRYyOcJD+4nYph+KpfdPRnQJVrZfk0KJgdnaAWKfhsBBtAf/D58Az4AvCJEmWgIBAg==} + engines: {node: '>=18.0.0'} + dependencies: + tslib: 2.7.0 + dev: false + + /@azure/core-util@1.10.0: + resolution: {integrity: sha512-dqLWQsh9Nro1YQU+405POVtXnwrIVqPyfUzc4zXCbThTg7+vNNaiMkwbX9AMXKyoFYFClxmB3s25ZFr3+jZkww==} + engines: {node: '>=18.0.0'} + dependencies: + '@azure/abort-controller': 2.1.2 + tslib: 2.7.0 + dev: false + + /@azure/logger@1.1.4: + resolution: {integrity: sha512-4IXXzcCdLdlXuCG+8UKEwLA1T1NHqUfanhXYHiQTn+6sfWCZXduqbtXDGceg3Ce5QxTGo7EqmbV6Bi+aqKuClQ==} + engines: {node: '>=18.0.0'} + dependencies: + tslib: 2.7.0 + dev: false + + /@azure/openai@1.0.0-beta.12: + resolution: {integrity: sha512-qKblxr6oVa8GsyNzY+/Ub9VmEsPYKhBrUrPaNEQiM+qrxnBPVm9kaeqGFFb/U78Q2zOabmhF9ctYt3xBW0nWnQ==} + engines: {node: '>=18.0.0'} + dependencies: + '@azure-rest/core-client': 1.4.0 + '@azure/core-auth': 1.8.0 + '@azure/core-rest-pipeline': 1.17.0 + '@azure/core-sse': 2.1.3 + '@azure/core-util': 1.10.0 + '@azure/logger': 1.1.4 + tslib: 2.7.0 + transitivePeerDependencies: + - supports-color + dev: false + /@babel/code-frame@7.25.7: resolution: {integrity: sha512-0xZJFNE5XMpENsgfHYTw8FbX4kv53mFLn2i3XPoq69LyhYSCBJtitaHx9QnsVTrsogI4Z3+HtEfZ2/GFPOtf5g==} engines: {node: '>=6.9.0'} diff --git a/src/components/ChatBox/ContactHeader.tsx b/src/components/ChatBox/ContactHeader.tsx index 18fe0eb..9ea3a73 100644 --- a/src/components/ChatBox/ContactHeader.tsx +++ b/src/components/ChatBox/ContactHeader.tsx @@ -172,7 +172,7 @@ const ContactHeader: FC = () => {

{