mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-04-21 21:52:07 +02:00
New Model Support: Qwen
This commit is contained in:
parent
13cbf2b582
commit
379ce2d5e7
2 changed files with 12 additions and 8 deletions
|
@ -11,6 +11,7 @@ export default
|
||||||
// "./profiles/claude.json",
|
// "./profiles/claude.json",
|
||||||
// "./profiles/gemini.json",
|
// "./profiles/gemini.json",
|
||||||
// "./profiles/llama.json",
|
// "./profiles/llama.json",
|
||||||
|
// "./profiles/qwen.json",
|
||||||
|
|
||||||
// using more than 1 profile requires you to /msg each bot indivually
|
// using more than 1 profile requires you to /msg each bot indivually
|
||||||
],
|
],
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
import OpenAIApi from 'openai';
|
import OpenAIApi from 'openai';
|
||||||
import { getKey, hasKey } from '../utils/keys.js';
|
import { getKey } from '../utils/keys.js';
|
||||||
import { strictFormat } from '../utils/text.js';
|
import { strictFormat } from '../utils/text.js';
|
||||||
|
|
||||||
import axios from 'axios';
|
|
||||||
|
|
||||||
export class Qwen {
|
export class Qwen {
|
||||||
constructor(model_name, url) {
|
constructor(model_name, url) {
|
||||||
this.model_name = model_name;
|
this.model_name = model_name;
|
||||||
|
@ -34,12 +32,12 @@ export class Qwen {
|
||||||
try {
|
try {
|
||||||
console.log('Awaiting Qwen API response...');
|
console.log('Awaiting Qwen API response...');
|
||||||
let completion = await this.openai.chat.completions.create(pack);
|
let completion = await this.openai.chat.completions.create(pack);
|
||||||
if (completion.choices[0].finish_reason == 'length')
|
if (completion.choices[0].finish_reason === 'length')
|
||||||
throw new Error('Context length exceeded');
|
throw new Error('Context length exceeded');
|
||||||
console.log('Received.');
|
console.log('Received.');
|
||||||
res = completion.choices[0].message.content;
|
res = completion.choices[0].message.content;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if ((err.message == 'Context length exceeded' || err.code == 'context_length_exceeded') && turns.length > 1) {
|
if ((err.message === 'Context length exceeded' || err.code === 'context_length_exceeded') && turns.length > 1) {
|
||||||
console.log('Context length exceeded, trying again with shorter context.');
|
console.log('Context length exceeded, trying again with shorter context.');
|
||||||
return await this.sendRequest(turns.slice(1), systemMessage, stop_seq);
|
return await this.sendRequest(turns.slice(1), systemMessage, stop_seq);
|
||||||
} else {
|
} else {
|
||||||
|
@ -70,11 +68,16 @@ export class Qwen {
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await axios.post(this.url, data, { headers });
|
const response = await fetch(this.url, {
|
||||||
if (!response || !response.data || !response.data.output || !response.data.output.embeddings) {
|
method: 'POST',
|
||||||
|
headers: headers,
|
||||||
|
body: JSON.stringify(data)
|
||||||
|
});
|
||||||
|
const responseData = await response.json();
|
||||||
|
if (!responseData || !responseData.output || !responseData.output.embeddings) {
|
||||||
throw new Error('Invalid response from embedding API');
|
throw new Error('Invalid response from embedding API');
|
||||||
}
|
}
|
||||||
return response.data.output.embeddings[0].embedding;
|
return responseData.output.embeddings[0].embedding;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error occurred:', err);
|
console.error('Error occurred:', err);
|
||||||
return 'An error occurred while processing your embedding request. Please try again.';
|
return 'An error occurred while processing your embedding request. Please try again.';
|
||||||
|
|
Loading…
Add table
Reference in a new issue