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

Add support for kimi.moonshot.cn #656

Merged
merged 2 commits into from
Mar 22, 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
10 changes: 10 additions & 0 deletions src/background/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
chatgptApiModelKeys,
chatgptWebModelKeys,
claudeWebModelKeys,
moonshotWebModelKeys,
customApiModelKeys,
defaultConfig,
getUserConfig,
Expand All @@ -46,6 +47,7 @@ import { registerCommands } from './commands.mjs'
import { generateAnswersWithBardWebApi } from '../services/apis/bard-web.mjs'
import { generateAnswersWithClaudeWebApi } from '../services/apis/claude-web.mjs'
import { generateAnswersWithMoonshotCompletionApi } from '../services/apis/moonshot-api.mjs'
import { generateAnswersWithMoonshotWebApi } from '../services/apis/moonshot-web.mjs'

function setPortProxy(port, proxyTabId) {
port.proxy = Browser.tabs.connect(proxyTabId)
Expand Down Expand Up @@ -161,6 +163,14 @@ async function executeApi(session, port, config) {
config.apiKey,
session.modelName,
)
} else if (moonshotWebModelKeys.includes(session.modelName)) {
await generateAnswersWithMoonshotWebApi(
port,
session.question,
session,
config,
session.modelName,
)
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/config/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const chatgptWebModelKeys = [
export const bingWebModelKeys = ['bingFree4', 'bingFreeSydney']
export const bardWebModelKeys = ['bardWebFree']
export const claudeWebModelKeys = ['claude2WebFree']
export const moonshotWebModelKeys = ['moonshotWebFree']
export const gptApiModelKeys = ['gptApiInstruct', 'gptApiDavinci']
export const chatgptApiModelKeys = [
'chatgptApi35',
Expand Down Expand Up @@ -107,6 +108,8 @@ export const Models = {
bingFree4: { value: '', desc: 'Bing (Web, GPT-4)' },
bingFreeSydney: { value: '', desc: 'Bing (Web, GPT-4, Sydney)' },

moonshotWebFree: { value: '', desc: 'Kimi.Moonshot (Web, 100k)' },

bardWebFree: { value: '', desc: 'Gemini (Web)' },

chatglmTurbo: { value: 'chatglm_turbo', desc: 'ChatGLM (ChatGLM-Turbo)' },
Expand Down Expand Up @@ -234,6 +237,7 @@ export const defaultConfig = {
'chatgptApi4_8k',
'claude2WebFree',
'bingFree4',
'moonshotWebFree',
'chatglmTurbo',
'customModel',
'azureOpenAi',
Expand All @@ -259,6 +263,8 @@ export const defaultConfig = {
chatgptTabId: 0,
chatgptArkoseReqUrl: '',
chatgptArkoseReqForm: '',
kimiMoonShotRefreshToken: '',
kimiMoonShotAccessToken: '',

// unchangeable

Expand Down Expand Up @@ -340,6 +346,11 @@ export function isUsingAzureOpenAi(configOrSession) {
export function isUsingClaude2Api(configOrSession) {
return claudeApiModelKeys.includes(configOrSession.modelName)
}

export function isUsingMoonshotWeb(configOrSession) {
return moonshotWebModelKeys.includes(configOrSession.modelName)
}

export function isUsingGithubThirdPartyApi(configOrSession) {
return githubThirdPartyApiModelKeys.includes(configOrSession.modelName)
}
Expand Down
10 changes: 9 additions & 1 deletion src/content-script/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getPreferredLanguageKey,
getUserConfig,
setAccessToken,
setUserConfig,
} from '../config/index.mjs'
import {
createElementAtPosition,
Expand Down Expand Up @@ -289,7 +290,14 @@ async function prepareForStaticCard() {
}

async function overwriteAccessToken() {
if (location.hostname !== 'chat.openai.com') return
if (location.hostname !== 'chat.openai.com') {
if (location.hostname === 'kimi.moonshot.cn') {
setUserConfig({
kimiMoonShotRefreshToken: window.localStorage.refresh_token,
})
}
return
}

let data
if (location.pathname === '/api/auth/session') {
Expand Down
1 change: 1 addition & 0 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"https://*.poe.com/*",
"https://*.google.com/*",
"https://claude.ai/*",
"https://*.moonshot.cn/*",
"<all_urls>"
],
"permissions": [
Expand Down
1 change: 1 addition & 0 deletions src/manifest.v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"https://*.poe.com/",
"https://*.google.com/",
"https://claude.ai/",
"https://*.moonshot.cn/*",
"<all_urls>"
],
"background": {
Expand Down
Loading