generated from chibat/chrome-extension-typescript-starter
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
8 changed files
with
132 additions
and
0 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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { IconBaseProps } from 'react-icons' | ||
import Logo from '@/common/assets/images/deepseek.svg?react' | ||
import { createUseStyles } from 'react-jss' | ||
|
||
const useStyles = createUseStyles({ | ||
icon: { | ||
'& path': { | ||
fill: 'currentColor', | ||
}, | ||
}, | ||
}) | ||
|
||
export function DeepSeekIcon(props: IconBaseProps) { | ||
const styles = useStyles() | ||
return <Logo className={styles.icon} width={props.size} height={props.size} /> | ||
} |
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,59 @@ | ||
import { getSettings } from '../utils' | ||
import { AbstractOpenAI } from './abstract-openai' | ||
import { IModel } from './interfaces' | ||
|
||
export class DeepSeek extends AbstractOpenAI { | ||
async listModels(apiKey_: string | undefined): Promise<IModel[]> { | ||
let apiKey = apiKey_ | ||
if (!apiKey) { | ||
apiKey = await this.getAPIKey() | ||
} | ||
const apiURL = await this.getAPIURL() | ||
if (!apiKey || !apiURL) { | ||
return [] | ||
} | ||
const url = `${apiURL}/v1/models` | ||
const response = await fetch(url, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
'Authorization': `Bearer ${apiKey}`, | ||
}, | ||
}) | ||
if (response.status !== 200) { | ||
if (response.status === 401) { | ||
throw new Error('Invalid API key') | ||
} | ||
if (response.status === 404) { | ||
throw new Error('Invalid API URL') | ||
} | ||
if (response.status === 403) { | ||
throw new Error('Invalid API Key') | ||
} | ||
throw new Error(`Failed to list models: ${response.statusText}`) | ||
} | ||
const json = await response.json() | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
return json.data.map((model: any) => { | ||
return { | ||
id: model.id, | ||
name: model.id, | ||
} | ||
}) | ||
} | ||
|
||
async getAPIModel(): Promise<string> { | ||
const settings = await getSettings() | ||
return settings.deepSeekAPIModel | ||
} | ||
async getAPIKey(): Promise<string> { | ||
const settings = await getSettings() | ||
return settings.deepSeekAPIKey | ||
} | ||
async getAPIURL(): Promise<string> { | ||
return 'https://api.deepseek.com' | ||
} | ||
async getAPIURLPath(): Promise<string> { | ||
return '/v1/chat/completions' | ||
} | ||
} |
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 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