Skip to content

Commit

Permalink
Merge branch 'josStorer:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
okkidwi committed Jul 27, 2023
2 parents 627bd63 + 819eb16 commit 09ccc96
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 8 deletions.
13 changes: 12 additions & 1 deletion src/config/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ export const chatgptApiModelKeys = [
'chatgptApi35',
'chatgptApi35_16k',
'chatgptApi35_0613',
'chatgptApi35_16k_0613',
'chatgptApi4_8k',
'chatgptApi4_8k_0613',
'chatgptApi4_32k',
'chatgptApi4_32k_0613',
]
export const customApiModelKeys = ['customModel']
export const azureOpenAiApiModelKeys = ['azureOpenAi']
Expand Down Expand Up @@ -71,18 +74,24 @@ export const Models = {
chatgptApi35: { value: 'gpt-3.5-turbo', desc: 'ChatGPT (GPT-3.5-turbo)' },
chatgptApi35_16k: { value: 'gpt-3.5-turbo-16k', desc: 'ChatGPT (GPT-3.5-turbo-16k)' },
chatgptApi35_0613: { value: 'gpt-3.5-turbo-0613', desc: 'ChatGPT (GPT-3.5-turbo 0613)' },
chatgptApi35_16k_0613: {
value: 'gpt-3.5-turbo-16k-0613',
desc: 'ChatGPT (GPT-3.5-turbo-16k 0613)',
},
bingFree4: { value: '', desc: 'Bing (Web, GPT-4)' },
bingFreeSydney: { value: '', desc: 'Bing (Web, GPT-4, Sydney)' },
bardWebFree: { value: '', desc: 'Bard (Web)' },
poeAiWebSage: { value: 'sage', desc: 'Poe AI (Web, Sage)' },
poeAiWebSage: { value: 'Assistant', desc: 'Poe AI (Web, Assistant)' },
poeAiWebGPT4: { value: 'gpt-4', desc: 'Poe AI (Web, GPT-4)' },
poeAiWebGPT4_32k: { value: 'gpt-4-32k', desc: 'Poe AI (Web, GPT-4-32k)' },
poeAiWebClaudePlus: { value: 'claude-2-100k', desc: 'Poe AI (Web, Claude 2 100k)' },
poeAiWebClaude: { value: 'claude-instant', desc: 'Poe AI (Web, Claude instant)' },
poeAiWebClaude100k: { value: 'claude-instant-100k', desc: 'Poe AI (Web, Claude instant 100k)' },
poeAiWebGooglePaLM: { value: 'Google-PaLM', desc: 'Poe AI (Web, Google-PaLM)' },
chatgptApi4_8k: { value: 'gpt-4', desc: 'ChatGPT (GPT-4-8k)' },
chatgptApi4_8k_0613: { value: 'gpt-4', desc: 'ChatGPT (GPT-4-8k 0613)' },
chatgptApi4_32k: { value: 'gpt-4-32k', desc: 'ChatGPT (GPT-4-32k)' },
chatgptApi4_32k_0613: { value: 'gpt-4-32k', desc: 'ChatGPT (GPT-4-32k 0613)' },
gptApiDavinci: { value: 'text-davinci-003', desc: 'GPT-3.5' },
customModel: { value: '', desc: 'Custom Model' },
azureOpenAi: { value: '', desc: 'ChatGPT (Azure)' },
Expand Down Expand Up @@ -188,6 +197,7 @@ export const defaultConfig = {
'stackoverflow',
'juejin',
'mp.weixin.qq',
'followin',
],
accessToken: '',
tokenSavedOn: 0,
Expand Down Expand Up @@ -233,6 +243,7 @@ export const defaultConfig = {
'stackoverflow',
'juejin',
'mp.weixin.qq',
'followin',
],
}

Expand Down
28 changes: 28 additions & 0 deletions src/content-script/site-adapters/followin/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { cropText } from '../../../utils'

export default {
inputQuery: async () => {
try {
const author = document.querySelector('main article a > span')?.textContent
const description =
document.querySelector('#article-content')?.textContent ||
document.querySelector('#thead-gallery')?.textContent
if (author && description) {
const title = document.querySelector('main article h1')?.textContent
if (title) {
return await cropText(
`以下是一篇文章,请给出文章的结论和3到5个要点.标题是:"${title}",作者是:"${author}",内容是:\n"${description}".
`,
)
} else {
return await cropText(
`以下是一篇长推文,请给出文章的结论和3到5个要点.作者是:"${author}",内容是:\n"${description}".
`,
)
}
}
} catch (e) {
console.log(e)
}
},
}
7 changes: 7 additions & 0 deletions src/content-script/site-adapters/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import quora from './quora'
import stackoverflow from './stackoverflow'
import juejin from './juejin'
import weixin from './weixin'
import followin from './followin'

/**
* @typedef {object} SiteConfigAction
Expand Down Expand Up @@ -185,4 +186,10 @@ export const config = {
appendContainerQuery: [],
resultsContainerQuery: ['#js_content'],
},
followin: {
inputQuery: followin.inputQuery,
sidebarContainerQuery: [],
appendContainerQuery: [],
resultsContainerQuery: ['#article-content', '#thead-gallery'],
},
}
11 changes: 11 additions & 0 deletions src/content-script/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

[data-theme='auto'] {
@import 'github-markdown-css/github-markdown.css';

@media screen and (prefers-color-scheme: dark) {
@import 'highlight.js/scss/github-dark.scss';
--font-color: #c9d1d9;
Expand All @@ -13,6 +14,7 @@
--color-neutral-muted: rgba(110, 118, 129, 0.4);
--code-background-color: rgb(13, 17, 23);
}

@media screen and (prefers-color-scheme: light) {
@import 'highlight.js/scss/github.scss';
--font-color: #24292f;
Expand Down Expand Up @@ -98,26 +100,32 @@
background-color: var(--theme-color);
width: 9px;
}

::-webkit-scrollbar-thumb {
background-color: var(--theme-border-color);
border-radius: 20px;
border: transparent;
}

::-webkit-scrollbar-corner {
background: transparent;
}

&::-webkit-scrollbar {
background-color: var(--theme-color);
width: 9px;
}

&::-webkit-scrollbar-thumb {
background-color: var(--theme-border-color);
border-radius: 20px;
border: transparent;
}

&::-webkit-scrollbar-corner {
background: transparent;
}

p {
color: var(--font-color);
}
Expand All @@ -133,6 +141,7 @@

li {
counter-increment: item;
margin-bottom: 0px;

&::marker {
content: counter(item) '. ';
Expand Down Expand Up @@ -288,11 +297,13 @@
background-color: var(--theme-color);
width: 9px;
}

&::-webkit-scrollbar-thumb {
background-color: var(--theme-border-color);
border-radius: 20px;
border: transparent;
}

&::-webkit-scrollbar-corner {
background: transparent;
}
Expand Down
1 change: 1 addition & 0 deletions src/services/apis/azure-openai-api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export async function generateAnswersWithAzureOpenaiApi(port, question, session)
},
async onStart() {},
async onEnd() {
port.postMessage({ done: true })
port.onMessage.removeListener(messageListener)
port.onDisconnect.removeListener(disconnectListener)
},
Expand Down
3 changes: 2 additions & 1 deletion src/services/apis/chatgpt-web.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export async function generateAnswersWithChatgptWebApi(port, question, session,
}),
onMessage(message) {
console.debug('sse message', message)
if (message === '[DONE]') {
if (message.trim() === '[DONE]') {
pushRecord(session, question, answer)
console.debug('conversation history', { content: session.conversationRecords })
port.postMessage({ answer: null, done: true, session: session })
Expand All @@ -148,6 +148,7 @@ export async function generateAnswersWithChatgptWebApi(port, question, session,
// sendModerations(accessToken, question, session.conversationId, session.messageId)
},
async onEnd() {
port.postMessage({ done: true })
port.onMessage.removeListener(messageListener)
port.onDisconnect.removeListener(disconnectListener)
},
Expand Down
3 changes: 2 additions & 1 deletion src/services/apis/custom-api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export async function generateAnswersWithCustomApi(port, question, session, apiK
}),
onMessage(message) {
console.debug('sse message', message)
if (message === '[DONE]') {
if (message.trim() === '[DONE]') {
pushRecord(session, question, answer)
console.debug('conversation history', { content: session.conversationRecords })
port.postMessage({ answer: null, done: true, session: session })
Expand All @@ -72,6 +72,7 @@ export async function generateAnswersWithCustomApi(port, question, session, apiK
},
async onStart() {},
async onEnd() {
port.postMessage({ done: true })
port.onMessage.removeListener(messageListener)
port.onDisconnect.removeListener(disconnectListener)
},
Expand Down
6 changes: 4 additions & 2 deletions src/services/apis/openai-api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function generateAnswersWithGptCompletionApi(
}),
onMessage(message) {
console.debug('sse message', message)
if (message === '[DONE]') {
if (message.trim() === '[DONE]') {
pushRecord(session, question, answer)
console.debug('conversation history', { content: session.conversationRecords })
port.postMessage({ answer: null, done: true, session: session })
Expand All @@ -73,6 +73,7 @@ export async function generateAnswersWithGptCompletionApi(
},
async onStart() {},
async onEnd() {
port.postMessage({ done: true })
port.onMessage.removeListener(messageListener)
port.onDisconnect.removeListener(disconnectListener)
},
Expand Down Expand Up @@ -122,7 +123,7 @@ export async function generateAnswersWithChatgptApi(port, question, session, api
}),
onMessage(message) {
console.debug('sse message', message)
if (message === '[DONE]') {
if (message.trim() === '[DONE]') {
pushRecord(session, question, answer)
console.debug('conversation history', { content: session.conversationRecords })
port.postMessage({ answer: null, done: true, session: session })
Expand All @@ -144,6 +145,7 @@ export async function generateAnswersWithChatgptApi(port, question, session, api
},
async onStart() {},
async onEnd() {
port.postMessage({ done: true })
port.onMessage.removeListener(messageListener)
port.onDisconnect.removeListener(disconnectListener)
},
Expand Down
3 changes: 2 additions & 1 deletion src/services/apis/waylaidwanderer-api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function generateAnswersWithWaylaidwandererApi(port, question, sess
}),
onMessage(message) {
console.debug('sse message', message)
if (message === '[DONE]') {
if (message.trim() === '[DONE]') {
pushRecord(session, question, answer)
console.debug('conversation history', { content: session.conversationRecords })
port.postMessage({ answer: null, done: true, session: session })
Expand Down Expand Up @@ -64,6 +64,7 @@ export async function generateAnswersWithWaylaidwandererApi(port, question, sess
},
async onStart() {},
async onEnd() {
port.postMessage({ done: true })
port.onMessage.removeListener(messageListener)
port.onDisconnect.removeListener(disconnectListener)
},
Expand Down
4 changes: 2 additions & 2 deletions src/services/clients/poe/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class PoeAiClient {
await this.getCredentials()
}
if (!this.bot) {
await this.initBot(model || 'sage')
await this.initBot(model || 'Assistant')
}
if (!this.chatId) {
await this.getChatId(this.bot)
Expand Down Expand Up @@ -131,7 +131,7 @@ export default class PoeAiClient {
}

async initBot(bot) {
if (bot === 'sage') {
if (bot === 'Assistant') {
bot = 'capybara'
} else if (bot === 'gpt-4') {
bot = 'beaver'
Expand Down

0 comments on commit 09ccc96

Please sign in to comment.