-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
2,567 additions
and
261 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,50 @@ | ||
/** | ||
* AI integration with DeepSeek API | ||
*/ | ||
import OpenAI from 'openai' | ||
import log from '../common/log.js' | ||
import defaultSettings from '../common/config-default.js' | ||
|
||
// Initialize OpenAI with DeepSeek configuration | ||
const initAIClient = async (config) => { | ||
return new OpenAI(config) | ||
} | ||
|
||
export const AIchat = async ( | ||
prompt, | ||
model = defaultSettings.modelAI, | ||
role = defaultSettings.roleAI, | ||
baseURL = defaultSettings.baseURLAI, | ||
apiKey | ||
) => { | ||
try { | ||
const client = await initAIClient({ | ||
baseURL, | ||
apiKey | ||
}) | ||
const completion = await client.chat.completions.create({ | ||
messages: [ | ||
{ | ||
role: 'system', | ||
content: role | ||
}, | ||
{ | ||
role: 'user', | ||
content: prompt | ||
} | ||
], | ||
model | ||
}) | ||
|
||
return { | ||
response: completion.choices[0].message.content | ||
} | ||
} catch (e) { | ||
log.error('AI chat error') | ||
log.error(e) | ||
return { | ||
error: e.message, | ||
stack: e.stack | ||
} | ||
} | ||
} |
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
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