@@ -16,24 +16,23 @@ import { generateAnswersWithClaudeApi } from '../services/apis/claude-api.mjs'
16
16
import { generateAnswersWithChatGLMApi } from '../services/apis/chatglm-api.mjs'
17
17
import { generateAnswersWithWaylaidwandererApi } from '../services/apis/waylaidwanderer-api.mjs'
18
18
import {
19
- azureOpenAiApiModelKeys ,
20
- claudeApiModelKeys ,
21
- chatglmApiModelKeys ,
22
- bardWebModelKeys ,
23
- bingWebModelKeys ,
24
- chatgptApiModelKeys ,
25
- chatgptWebModelKeys ,
26
- claudeWebModelKeys ,
27
- moonshotWebModelKeys ,
28
- customApiModelKeys ,
29
- ollamaApiModelKeys ,
30
19
defaultConfig ,
31
20
getUserConfig ,
32
- githubThirdPartyApiModelKeys ,
33
- gptApiModelKeys ,
34
- poeWebModelKeys ,
35
21
setUserConfig ,
36
- moonshotApiModelKeys ,
22
+ isUsingChatgptWebModel ,
23
+ isUsingBingWebModel ,
24
+ isUsingGptCompletionApiModel ,
25
+ isUsingChatgptApiModel ,
26
+ isUsingCustomModel ,
27
+ isUsingOllamaApiModel ,
28
+ isUsingAzureOpenAiApiModel ,
29
+ isUsingClaudeApiModel ,
30
+ isUsingChatGLMApiModel ,
31
+ isUsingGithubThirdPartyApiModel ,
32
+ isUsingGeminiWebModel ,
33
+ isUsingClaudeWebModel ,
34
+ isUsingMoonshotApiModel ,
35
+ isUsingMoonshotWebModel ,
37
36
} from '../config/index.mjs'
38
37
import '../_locales/i18n'
39
38
import { openUrl } from '../utils/open-url'
@@ -50,6 +49,7 @@ import { generateAnswersWithBardWebApi } from '../services/apis/bard-web.mjs'
50
49
import { generateAnswersWithClaudeWebApi } from '../services/apis/claude-web.mjs'
51
50
import { generateAnswersWithMoonshotCompletionApi } from '../services/apis/moonshot-api.mjs'
52
51
import { generateAnswersWithMoonshotWebApi } from '../services/apis/moonshot-web.mjs'
52
+ import { isUsingModelName } from '../utils/model-name-convert.mjs'
53
53
54
54
function setPortProxy ( port , proxyTabId ) {
55
55
port . proxy = Browser . tabs . connect ( proxyTabId )
@@ -77,7 +77,26 @@ function setPortProxy(port, proxyTabId) {
77
77
async function executeApi ( session , port , config ) {
78
78
console . debug ( 'modelName' , session . modelName )
79
79
console . debug ( 'apiMode' , session . apiMode )
80
- if ( chatgptWebModelKeys . includes ( session . modelName ) ) {
80
+ if ( isUsingCustomModel ( session ) ) {
81
+ if ( ! session . apiMode )
82
+ await generateAnswersWithCustomApi (
83
+ port ,
84
+ session . question ,
85
+ session ,
86
+ config . customModelApiUrl ,
87
+ config . customApiKey ,
88
+ config . customModelName ,
89
+ )
90
+ else
91
+ await generateAnswersWithCustomApi (
92
+ port ,
93
+ session . question ,
94
+ session ,
95
+ session . apiMode . customUrl ,
96
+ session . apiMode . apiKey ,
97
+ session . apiMode . customName ,
98
+ )
99
+ } else if ( isUsingChatgptWebModel ( session ) ) {
81
100
let tabId
82
101
if (
83
102
config . chatgptTabId &&
@@ -95,87 +114,40 @@ async function executeApi(session, port, config) {
95
114
const accessToken = await getChatGptAccessToken ( )
96
115
await generateAnswersWithChatgptWebApi ( port , session . question , session , accessToken )
97
116
}
98
- } else if (
99
- // `.some` for multi mode models. e.g. bingFree4-balanced
100
- bingWebModelKeys . some ( ( n ) => session . modelName . includes ( n ) )
101
- ) {
117
+ } else if ( isUsingClaudeWebModel ( session ) ) {
118
+ const sessionKey = await getClaudeSessionKey ( )
119
+ await generateAnswersWithClaudeWebApi ( port , session . question , session , sessionKey )
120
+ } else if ( isUsingMoonshotWebModel ( session ) ) {
121
+ await generateAnswersWithMoonshotWebApi ( port , session . question , session , config )
122
+ } else if ( isUsingBingWebModel ( session ) ) {
102
123
const accessToken = await getBingAccessToken ( )
103
- if ( session . modelName . includes ( 'bingFreeSydney' ) )
124
+ if ( isUsingModelName ( 'bingFreeSydney' , session ) )
104
125
await generateAnswersWithBingWebApi ( port , session . question , session , accessToken , true )
105
126
else await generateAnswersWithBingWebApi ( port , session . question , session , accessToken )
106
- } else if ( gptApiModelKeys . includes ( session . modelName ) ) {
107
- await generateAnswersWithGptCompletionApi (
108
- port ,
109
- session . question ,
110
- session ,
111
- config . apiKey ,
112
- session . modelName ,
113
- )
114
- } else if ( chatgptApiModelKeys . includes ( session . modelName ) ) {
115
- await generateAnswersWithChatgptApi (
116
- port ,
117
- session . question ,
118
- session ,
119
- config . apiKey ,
120
- session . modelName ,
121
- )
122
- } else if ( customApiModelKeys . includes ( session . modelName ) ) {
123
- await generateAnswersWithCustomApi (
124
- port ,
125
- session . question ,
126
- session ,
127
- config . customApiKey ,
128
- config . customModelName ,
129
- )
130
- } else if ( ollamaApiModelKeys . includes ( session . modelName ) ) {
131
- await generateAnswersWithOllamaApi ( port , session . question , session )
132
- } else if ( azureOpenAiApiModelKeys . includes ( session . modelName ) ) {
133
- await generateAnswersWithAzureOpenaiApi ( port , session . question , session )
134
- } else if ( claudeApiModelKeys . includes ( session . modelName ) ) {
135
- await generateAnswersWithClaudeApi ( port , session . question , session )
136
- } else if ( chatglmApiModelKeys . includes ( session . modelName ) ) {
137
- await generateAnswersWithChatGLMApi ( port , session . question , session , session . modelName )
138
- } else if ( githubThirdPartyApiModelKeys . includes ( session . modelName ) ) {
139
- await generateAnswersWithWaylaidwandererApi ( port , session . question , session )
140
- } else if ( poeWebModelKeys . includes ( session . modelName ) ) {
141
- throw new Error ( 'Due to the new verification, Poe Web API is currently not supported.' )
142
- // if (session.modelName === 'poeAiWebCustom')
143
- // await generateAnswersWithPoeWebApi(port, session.question, session, config.poeCustomBotName)
144
- // else
145
- // await generateAnswersWithPoeWebApi(
146
- // port,
147
- // session.question,
148
- // session,
149
- // Models[session.modelName].value,
150
- // )
151
- } else if ( bardWebModelKeys . includes ( session . modelName ) ) {
127
+ } else if ( isUsingGeminiWebModel ( session ) ) {
152
128
const cookies = await getBardCookies ( )
153
129
await generateAnswersWithBardWebApi ( port , session . question , session , cookies )
154
- } else if ( claudeWebModelKeys . includes ( session . modelName ) ) {
155
- const sessionKey = await getClaudeSessionKey ( )
156
- await generateAnswersWithClaudeWebApi (
157
- port ,
158
- session . question ,
159
- session ,
160
- sessionKey ,
161
- session . modelName ,
162
- )
163
- } else if ( moonshotApiModelKeys . includes ( session . modelName ) ) {
130
+ } else if ( isUsingChatgptApiModel ( session ) ) {
131
+ await generateAnswersWithChatgptApi ( port , session . question , session , config . apiKey )
132
+ } else if ( isUsingClaudeApiModel ( session ) ) {
133
+ await generateAnswersWithClaudeApi ( port , session . question , session )
134
+ } else if ( isUsingMoonshotApiModel ( session ) ) {
164
135
await generateAnswersWithMoonshotCompletionApi (
165
136
port ,
166
137
session . question ,
167
138
session ,
168
139
config . moonshotApiKey ,
169
- session . modelName ,
170
- )
171
- } else if ( moonshotWebModelKeys . includes ( session . modelName ) ) {
172
- await generateAnswersWithMoonshotWebApi (
173
- port ,
174
- session . question ,
175
- session ,
176
- config ,
177
- session . modelName ,
178
140
)
141
+ } else if ( isUsingChatGLMApiModel ( session ) ) {
142
+ await generateAnswersWithChatGLMApi ( port , session . question , session )
143
+ } else if ( isUsingOllamaApiModel ( session ) ) {
144
+ await generateAnswersWithOllamaApi ( port , session . question , session )
145
+ } else if ( isUsingAzureOpenAiApiModel ( session ) ) {
146
+ await generateAnswersWithAzureOpenaiApi ( port , session . question , session )
147
+ } else if ( isUsingGptCompletionApiModel ( session ) ) {
148
+ await generateAnswersWithGptCompletionApi ( port , session . question , session , config . apiKey )
149
+ } else if ( isUsingGithubThirdPartyApiModel ( session ) ) {
150
+ await generateAnswersWithWaylaidwandererApi ( port , session . question , session )
179
151
}
180
152
}
181
153
0 commit comments