feat: add DeepSeek LLM class and documentation (#1071)

This commit is contained in:
Erik
2024-07-25 22:15:34 +04:00
committed by GitHub
parent 5d5716b339
commit 086b94038e
5 changed files with 98 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
---
"llamaindex": minor
"docs": minor
---
add DeepSeek LLM class and documentation
+6
View File
@@ -0,0 +1,6 @@
---
"llamaindex": minor
"docs": minor
---
Add deepseek llm class
@@ -0,0 +1,50 @@
# DeepSeek LLM
## Usage
```ts
import { DeepSeekLLM, Settings } from "llamaindex";
Settings.llm = new DeepSeekLLM({
apiKey: "<YOUR_API_KEY>",
model: "deepseek-coder", // or "deepseek-chat"
});
```
## Example
```ts
import { DeepSeekLLM, Document, VectorStoreIndex, Settings } from "llamaindex";
const deepseekLlm = new DeepSeekLLM({
apiKey: "<YOUR_API_KEY>",
model: "deepseek-coder", // or "deepseek-chat"
});
async function main() {
const response = await llm.deepseekLlm.chat({
messages: [
{
role: "system",
content: "You are an AI assistant",
},
{
role: "user",
content: "Tell me about San Francisco",
},
],
stream: false,
});
console.log(response);
}
```
# Limitations
Currently does not support function calling.
[Currently does not support json-output param while still is very good at json generating.](https://platform.deepseek.com/api-docs/faq#does-your-api-support-json-output)
## API platform
- [DeepSeek platform](https://platform.deepseek.com/)
+35
View File
@@ -0,0 +1,35 @@
import { getEnv } from "@llamaindex/env";
import { OpenAI } from "./openai.js";
export const DEEPSEEK_MODELS = {
"deepseek-coder": { contextWindow: 128000 },
"deepseek-chat": { contextWindow: 128000 },
};
type DeepSeekModelName = keyof typeof DEEPSEEK_MODELS;
const DEFAULT_MODEL: DeepSeekModelName = "deepseek-coder";
export class DeepSeekLLM extends OpenAI {
constructor(init?: Partial<OpenAI> & { model?: DeepSeekModelName }) {
const {
apiKey = getEnv("DEEPSEEK_API_KEY"),
additionalSessionOptions = {},
model = DEFAULT_MODEL,
...rest
} = init ?? {};
if (!apiKey) {
throw new Error("Set DeepSeek Key in DEEPSEEK_API_KEY env variable");
}
additionalSessionOptions.baseURL =
additionalSessionOptions.baseURL ?? "https://api.deepseek.com/v1";
super({
apiKey,
additionalSessionOptions,
model,
...rest,
});
}
}
+1
View File
@@ -34,5 +34,6 @@ export {
ReplicateSession,
} from "./replicate_ai.js";
export { DeepSeekLLM } from "./deepseek.js";
export { TogetherLLM } from "./together.js";
export * from "./types.js";