-
Notifications
You must be signed in to change notification settings - Fork 59.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
1,015 additions
and
656 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { getClientConfig } from "@/app/config/client"; | ||
import { ACCESS_CODE_PREFIX } from "@/app/constant"; | ||
import { useAccessStore } from "@/app/store"; | ||
|
||
export function bearer(value: string) { | ||
return `Bearer ${value.trim()}`; | ||
} | ||
|
||
export function getAuthHeaders(apiKey = "") { | ||
const accessStore = useAccessStore.getState(); | ||
const isApp = !!getClientConfig()?.isApp; | ||
|
||
let headers: Record<string, string> = {}; | ||
|
||
if (apiKey) { | ||
// use user's api key first | ||
headers.Authorization = bearer(apiKey); | ||
} else if ( | ||
accessStore.enabledAccessControl() && | ||
!isApp && | ||
!!accessStore.accessCode | ||
) { | ||
// or use access code | ||
headers.Authorization = bearer(ACCESS_CODE_PREFIX + accessStore.accessCode); | ||
} | ||
|
||
return headers; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const COMMON_PROVIDER_CONFIG = { | ||
customModels: "", | ||
models: [] as string[], | ||
autoFetchModels: false, // fetch available models from server or not | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { getClientConfig } from "@/app/config/client"; | ||
import { ChatMessage } from "@/app/store"; | ||
|
||
export async function shareToShareGPT( | ||
messages: ChatMessage[], | ||
avatarUrl: string | null = null, | ||
) { | ||
const msgs = messages | ||
.map((m) => ({ | ||
from: m.role === "user" ? "human" : "gpt", | ||
value: m.content, | ||
})) | ||
.concat([ | ||
{ | ||
from: "human", | ||
// 敬告二开开发者们,为了开源大模型的发展,请不要修改上述消息,此消息用于后续数据清洗使用 | ||
// Please do not modify this message | ||
value: | ||
"Share from [ChatGPT Next Web]: https://github.com/Yidadaa/ChatGPT-Next-Web", | ||
}, | ||
]); | ||
|
||
console.log("[Share]", messages, msgs); | ||
const clientConfig = getClientConfig(); | ||
const proxyUrl = "/sharegpt"; | ||
const rawUrl = "https://sharegpt.com/api/conversations"; | ||
const shareUrl = clientConfig?.isApp ? rawUrl : proxyUrl; | ||
const res = await fetch(shareUrl, { | ||
body: JSON.stringify({ | ||
avatarUrl, | ||
items: msgs, | ||
}), | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
method: "POST", | ||
}); | ||
|
||
const resJson = await res.json(); | ||
console.log("[Share]", resJson); | ||
if (resJson.id) { | ||
return `https://shareg.pt/${resJson.id}`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { MaskConfig, ProviderConfig } from "../store"; | ||
import { shareToShareGPT } from "./common/share"; | ||
import { createOpenAiClient } from "./openai"; | ||
import { ChatControllerPool } from "./common/controller"; | ||
|
||
export const LLMClients = { | ||
openai: createOpenAiClient, | ||
}; | ||
|
||
export function createLLMClient( | ||
config: ProviderConfig, | ||
maskConfig: MaskConfig, | ||
) { | ||
return LLMClients[maskConfig.provider as any as keyof typeof LLMClients]( | ||
config, | ||
maskConfig.modelConfig, | ||
); | ||
} | ||
|
||
export function createApi() { | ||
return { | ||
createLLMClient, | ||
shareToShareGPT, | ||
controllerManager: ChatControllerPool, | ||
}; | ||
} | ||
|
||
export const api = createApi(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./types"; | ||
export * from "./core"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { COMMON_PROVIDER_CONFIG } from "../common/config"; | ||
|
||
export const OpenAIConfig = { | ||
model: { | ||
model: "gpt-3.5-turbo" as string, | ||
summarizeModel: "gpt-3.5-turbo", | ||
|
||
temperature: 0.5, | ||
top_p: 1, | ||
max_tokens: 2000, | ||
presence_penalty: 0, | ||
frequency_penalty: 0, | ||
}, | ||
provider: { | ||
endpoint: "https://api.openai.com", | ||
apiKey: "", | ||
...COMMON_PROVIDER_CONFIG, | ||
}, | ||
}; |
Oops, something went wrong.