Fix AI engine setting for OpenAI (#894)
* fix default models settings * fix type warning
This commit is contained in:
@@ -55,11 +55,16 @@ export const DefaultEngineSettings = () => {
|
||||
const onSubmit = async (data: z.infer<typeof gptEngineSchema>) => {
|
||||
const { name, models } = data;
|
||||
|
||||
models.default ||= providers[name].models[0];
|
||||
let options = [...providers[name].models];
|
||||
if (name === "openai" && openai?.models) {
|
||||
options = openai.models.split(",");
|
||||
}
|
||||
|
||||
models.default ||= options[0];
|
||||
Object.keys(models).forEach((key: keyof typeof models) => {
|
||||
if (!providers[name].models.includes(models[key])) {
|
||||
if (!options.includes(models[key])) {
|
||||
if (key === "default") {
|
||||
models[key] = providers[name].models[0];
|
||||
models[key] = options[0];
|
||||
} else {
|
||||
delete models[key];
|
||||
}
|
||||
@@ -150,13 +155,15 @@ export const DefaultEngineSettings = () => {
|
||||
></SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{providers[form.watch("name")].models.map(
|
||||
(model: string) => (
|
||||
<SelectItem key={model} value={model}>
|
||||
{model}
|
||||
</SelectItem>
|
||||
)
|
||||
)}
|
||||
{(form.watch("name") === "openai"
|
||||
? openai?.models?.split(",") ||
|
||||
providers.openai.models
|
||||
: providers.enjoyai.models
|
||||
).map((model: string) => (
|
||||
<SelectItem key={model} value={model}>
|
||||
{model}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
@@ -185,13 +192,15 @@ export const DefaultEngineSettings = () => {
|
||||
></SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{providers[form.watch("name")].models.map(
|
||||
(model: string) => (
|
||||
<SelectItem key={model} value={model}>
|
||||
{model}
|
||||
</SelectItem>
|
||||
)
|
||||
)}
|
||||
{(form.watch("name") === "openai"
|
||||
? openai?.models?.split(",") ||
|
||||
providers.openai.models
|
||||
: providers.enjoyai.models
|
||||
).map((model: string) => (
|
||||
<SelectItem key={model} value={model}>
|
||||
{model}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
@@ -218,13 +227,15 @@ export const DefaultEngineSettings = () => {
|
||||
></SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{providers[form.watch("name")].models.map(
|
||||
(model: string) => (
|
||||
<SelectItem key={model} value={model}>
|
||||
{model}
|
||||
</SelectItem>
|
||||
)
|
||||
)}
|
||||
{(form.watch("name") === "openai"
|
||||
? openai?.models?.split(",") ||
|
||||
providers.openai.models
|
||||
: providers.enjoyai.models
|
||||
).map((model: string) => (
|
||||
<SelectItem key={model} value={model}>
|
||||
{model}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
@@ -251,13 +262,15 @@ export const DefaultEngineSettings = () => {
|
||||
></SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{providers[form.watch("name")].models.map(
|
||||
(model: string) => (
|
||||
<SelectItem key={model} value={model}>
|
||||
{model}
|
||||
</SelectItem>
|
||||
)
|
||||
)}
|
||||
{(form.watch("name") === "openai"
|
||||
? openai?.models?.split(",") ||
|
||||
providers.openai.models
|
||||
: providers.enjoyai.models
|
||||
).map((model: string) => (
|
||||
<SelectItem key={model} value={model}>
|
||||
{model}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
@@ -284,13 +297,15 @@ export const DefaultEngineSettings = () => {
|
||||
></SelectValue>
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{providers[form.watch("name")].models.map(
|
||||
(model: string) => (
|
||||
<SelectItem key={model} value={model}>
|
||||
{model}
|
||||
</SelectItem>
|
||||
)
|
||||
)}
|
||||
{(form.watch("name") === "openai"
|
||||
? openai?.models?.split(",") ||
|
||||
providers.openai.models
|
||||
: providers.enjoyai.models
|
||||
).map((model: string) => (
|
||||
<SelectItem key={model} value={model}>
|
||||
{model}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
@@ -136,7 +136,6 @@ export const AISettingsProvider = ({
|
||||
? Object.assign(gptEngine, {
|
||||
key: openai.key,
|
||||
baseUrl: openai.baseUrl,
|
||||
models: openai.models,
|
||||
})
|
||||
: Object.assign(gptEngine, {
|
||||
key: user?.accessToken,
|
||||
|
||||
@@ -21,9 +21,7 @@ export const useConversation = () => {
|
||||
const { EnjoyApp, webApi, user, apiUrl, learningLanguage } = useContext(
|
||||
AppSettingsProviderContext
|
||||
);
|
||||
const { openai, currentEngine } = useContext(
|
||||
AISettingsProviderContext
|
||||
);
|
||||
const { openai, currentEngine } = useContext(AISettingsProviderContext);
|
||||
|
||||
const pickLlm = (conversation: ConversationType) => {
|
||||
const {
|
||||
@@ -152,7 +150,7 @@ export const useConversation = () => {
|
||||
const chain = new ConversationChain({
|
||||
llm: llm as any,
|
||||
memory,
|
||||
prompt,
|
||||
prompt: prompt as any,
|
||||
verbose: true,
|
||||
});
|
||||
let response: LLMResult["generations"][0] = [];
|
||||
|
||||
Reference in New Issue
Block a user