-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from VictorS67/encre-core-openai-community-1
Support community models in openai chat
- Loading branch information
Showing
5 changed files
with
158 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
process.env.OPENAI_API_KEY = "you_should_get_this_api_from_openai"; | ||
process.env.DEEPSEEK_API_KEY = "you_should_get_this_api_from_deepseek"; | ||
process.env.MOONSHOT_API_KEY = "you_should_get_this_api_from_moonshot"; |
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
45 changes: 45 additions & 0 deletions
45
...events/inference/chat/llms/openai/tests/community/__snapshots__/deepseek.int.test.ts.snap
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,45 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`DeepSeek test DeepSeek text 1`] = ` | ||
{ | ||
"generations": [ | ||
{ | ||
"info": { | ||
"finishReason": "stop", | ||
}, | ||
"message": { | ||
"_grp": 1, | ||
"_id": [ | ||
"events", | ||
"input", | ||
"load", | ||
"msgs", | ||
"assistant", | ||
"BotMessage", | ||
], | ||
"_kwargs": { | ||
"additional_kwargs": {}, | ||
"content": "Hello! I'm DeepSeek-V3, an artificial intelligence assistant created by DeepSeek. I'm at your service and would be delighted to assist you with any inquiries or tasks you may have.", | ||
}, | ||
"_type": "constructor", | ||
}, | ||
"output": "Hello! I'm DeepSeek-V3, an artificial intelligence assistant created by DeepSeek. I'm at your service and would be delighted to assist you with any inquiries or tasks you may have.", | ||
}, | ||
], | ||
"llmOutput": { | ||
"tokenUsage": { | ||
"completionTokens": 41, | ||
"promptTokens": 9, | ||
"totalTokens": 50, | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[`DeepSeek test DeepSeek text 2`] = ` | ||
{ | ||
"completionTokens": 45, | ||
"promptTokens": 12, | ||
"totalTokens": 57, | ||
} | ||
`; |
36 changes: 36 additions & 0 deletions
36
packages/core/src/events/inference/chat/llms/openai/tests/community/deepseek.int.test.ts
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,36 @@ | ||
import { describe, expect, test } from '@jest/globals'; | ||
|
||
import { HumanMessage } from '../../../../../../input/load/msgs/human.js'; | ||
import { ChatGenerationChunk } from '../../../../../../output/provide/message.js'; | ||
import { OpenAIChat } from '../../chat.js'; | ||
|
||
describe('DeepSeek', () => { | ||
const DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY; | ||
|
||
test('test DeepSeek text', async () => { | ||
const deepseek = new OpenAIChat({ | ||
openAIApiKey: DEEPSEEK_API_KEY, | ||
modelName: 'deepseek-chat', | ||
}); | ||
const messages = [new HumanMessage('Hello! Who are you?')]; | ||
|
||
const promptTokenNumber: number = await OpenAIChat.getNumTokensInChat( | ||
deepseek.modelName, | ||
messages | ||
); | ||
const llmResult = await deepseek.invoke(messages); | ||
const completionTokenNumber: number = | ||
await OpenAIChat.getNumTokensInGenerations( | ||
deepseek.modelName, | ||
llmResult.generations as ChatGenerationChunk[] | ||
); | ||
|
||
expect(llmResult).toMatchSnapshot(); | ||
|
||
expect({ | ||
completionTokens: completionTokenNumber, | ||
promptTokens: promptTokenNumber, | ||
totalTokens: promptTokenNumber + completionTokenNumber, | ||
}).toMatchSnapshot(); | ||
}); | ||
}); |