-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(engine): add DeepSeekEngine (#446)
Add DeepSeekEngine to support DeepSeek API. This includes a new DeepSeekConfig interface and updates to the engine selection logic. feat(README.md, src/commands/config.ts): Add DeepSeek support Adds support for the DeepSeek AI provider. Updates the README, config validation, and model list to include DeepSeek. This allows users to utilize DeepSeek models with the OpenCommit tool. fix(deepseek.ts): update DeepSeek API base URL to include version number v1 refactor(deepseek.ts): improve DeepSeekEngine constructor The DeepSeekEngine constructor is refactored to use the spread syntax for better readability and maintainability when merging config parameters. The baseURL is now explicitly set within the constructor. fix(README.md): remove Groq from the list of supported AI providers refactor(deepseek.ts): rename interface DeepseekConfig to DeepSeekEngineeekConfig and fix typo Revert "refactor(deepseek.ts): rename interface DeepseekConfig to DeepSeekEngineeekConfig and fix typo" This reverts commit f492367. refactor(deepseek.ts): Rename DeepseekConfig to DeepSeekConfig for consistency ✨ feat(engine): add DeepSeekEngine to support DeepSeek API ♻️ refactor(engine): improve OpenAiEngine and create a new DeepSeekEngine class to handle DeepSeek API requests. The DeepSeekEngine class inherits from OpenAiEngine and overrides the generateCommitMessage method to use the DeepSeek API. This change improves code organization and maintainability. 🐛 Fix: Correct DeepSeekEngine import and class name The import path and class name for DeepSeekEngine were incorrect, causing a runtime error. This commit corrects the import path and class name to `DeepseekEngine` to resolve the issue. Revert "🐛 Fix: Correct DeepSeekEngine import and class name" This reverts commit 738fd36. 🐛 Fix: Correct DeepSeekEngine import and class name The import path and class name for DeepSeekEngine were corrected to match the actual file and class name. This fixes a runtime error. Restore ./out directory to master state
- Loading branch information
1 parent
6816379
commit b55bcd5
Showing
4 changed files
with
77 additions
and
5 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 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,60 @@ | ||
import axios from 'axios'; | ||
import { OpenAI } from 'openai'; | ||
import { GenerateCommitMessageErrorEnum } from '../generateCommitMessageFromGitDiff'; | ||
import { tokenCount } from '../utils/tokenCount'; | ||
import { OpenAiEngine, OpenAiConfig } from './openAI'; | ||
|
||
export interface DeepseekConfig extends OpenAiConfig {} | ||
|
||
export class DeepseekEngine extends OpenAiEngine { | ||
constructor(config: DeepseekConfig) { | ||
// Call OpenAIEngine constructor with forced Deepseek baseURL | ||
super({ | ||
...config, | ||
baseURL: 'https://api.deepseek.com/v1' | ||
}); | ||
} | ||
|
||
// Identical method from OpenAiEngine, re-implemented here | ||
public generateCommitMessage = async ( | ||
messages: Array<OpenAI.Chat.Completions.ChatCompletionMessageParam> | ||
): Promise<string | null> => { | ||
const params = { | ||
model: this.config.model, | ||
messages, | ||
temperature: 0, | ||
top_p: 0.1, | ||
max_tokens: this.config.maxTokensOutput | ||
}; | ||
|
||
try { | ||
const REQUEST_TOKENS = messages | ||
.map((msg) => tokenCount(msg.content as string) + 4) | ||
.reduce((a, b) => a + b, 0); | ||
|
||
if ( | ||
REQUEST_TOKENS > | ||
this.config.maxTokensInput - this.config.maxTokensOutput | ||
) | ||
throw new Error(GenerateCommitMessageErrorEnum.tooMuchTokens); | ||
|
||
const completion = await this.client.chat.completions.create(params); | ||
|
||
const message = completion.choices[0].message; | ||
|
||
return message?.content; | ||
} catch (error) { | ||
const err = error as Error; | ||
if ( | ||
axios.isAxiosError<{ error?: { message: string } }>(error) && | ||
error.response?.status === 401 | ||
) { | ||
const openAiError = error.response.data.error; | ||
|
||
if (openAiError) throw new Error(openAiError.message); | ||
} | ||
|
||
throw err; | ||
} | ||
}; | ||
} |
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