Skip to content

Commit

Permalink
Merge pull request #7 from TarsLab/vendor-deepSeek
Browse files Browse the repository at this point in the history
增加供应商deepseek
  • Loading branch information
ae86jack committed Jul 20, 2024
2 parents 1fe5c90 + f2eb54c commit c89daea
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 5 deletions.
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"id": "tars",
"name": "Tars",
"version": "0.2.0",
"version": "0.2.1",
"minAppVersion": "1.5.8",
"description": "Use Kimi and other Chinese LLMs for text generation based on tag suggestions.",
"author": "Tarslab",
"authorUrl": "https://github.com/tarslab",
"isDesktopOnly": true
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-tars",
"version": "0.2.0",
"version": "0.2.1",
"description": "Use Kimi and other Chinese LLMs for text generation based on tag suggestions.",
"main": "main.js",
"scripts": {
Expand Down
45 changes: 45 additions & 0 deletions src/providers/deepSeek.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import OpenAI from 'openai'
import { t } from 'src/lang/helper'
import { BaseOptions, Message, SendRequest, Vendor } from '.'

const sendRequestFunc = (settings: BaseOptions): SendRequest =>
async function* (messages: Message[]) {
const { parameters, ...optionsExcludingParams } = settings
const options = { ...optionsExcludingParams, ...parameters }
const { apiKey, baseURL, model, ...remains } = options
if (!apiKey) throw new Error(t('API key is required'))

const client = new OpenAI({
apiKey,
baseURL,
dangerouslyAllowBrowser: true
})

const stream = await client.chat.completions.create({
model,
messages,
stream: true,
...remains
})

for await (const part of stream) {
const text = part.choices[0]?.delta?.content
if (!text) continue
yield text
}
}

const models = ['deepseek-chat', 'deepseek-coder']

export const deepSeekVendor: Vendor = {
name: 'DeepSeek',
defaultOptions: {
apiKey: '',
baseURL: 'https://api.deepseek.com',
model: models[0],
parameters: {}
},
sendRequestFunc,
models,
websiteToObtainKey: 'https://platform.deepseek.com'
}
4 changes: 3 additions & 1 deletion src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ProviderSettings, Vendor } from './providers'
import { deepSeekVendor } from './providers/deepSeek'
import { doubaoVendor } from './providers/doubao'
import { kimiVendor } from './providers/kimi'
import { openAIVendor } from './providers/openAI'
Expand Down Expand Up @@ -28,5 +29,6 @@ export const availableVendors: Vendor[] = [
openAIVendor,
qianFanVendor,
qwenVendor,
zhipuVendor
zhipuVendor,
deepSeekVendor
]
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"0.1.0": "1.5.8",
"0.1.1": "1.5.8",
"0.1.2": "1.5.8",
"0.2.0": "1.5.8"
"0.2.0": "1.5.8",
"0.2.1": "1.5.8"
}

0 comments on commit c89daea

Please sign in to comment.