Fix: ensure AI command model support json response_format (#365)
* ensure AI command model support json response_format * update models list * update tts model list
This commit is contained in:
@@ -2,6 +2,7 @@ import { ChatOpenAI } from "@langchain/openai";
|
||||
import { ChatPromptTemplate } from "@langchain/core/prompts";
|
||||
import { zodToJsonSchema } from "zod-to-json-schema";
|
||||
import { z } from "zod";
|
||||
import { RESPONSE_JSON_FORMAT_MODELS } from "@/constants";
|
||||
|
||||
export const extractStoryCommand = async (
|
||||
content: string,
|
||||
@@ -12,12 +13,12 @@ export const extractStoryCommand = async (
|
||||
baseUrl?: string;
|
||||
}
|
||||
): Promise<{ words: string[]; idioms: string[] }> => {
|
||||
const {
|
||||
key,
|
||||
modelName = "gpt-3.5-turbo-1106",
|
||||
temperature = 0,
|
||||
baseUrl,
|
||||
} = options;
|
||||
const { key, temperature = 0, baseUrl } = options;
|
||||
let { modelName = "gpt-4-turbo-preview" } = options;
|
||||
|
||||
if (RESPONSE_JSON_FORMAT_MODELS.indexOf(modelName) === -1) {
|
||||
modelName = "gpt-4-turbo-preview";
|
||||
}
|
||||
|
||||
const saveExtraction = z.object({
|
||||
words: z.array(z.string().describe("extracted word")),
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
StructuredOutputParser,
|
||||
OutputFixingParser,
|
||||
} from "langchain/output_parsers";
|
||||
import { RESPONSE_JSON_FORMAT_MODELS } from "@/constants";
|
||||
|
||||
export const ipaCommand = async (
|
||||
text: string,
|
||||
@@ -15,12 +16,12 @@ export const ipaCommand = async (
|
||||
baseUrl?: string;
|
||||
}
|
||||
): Promise<{ words?: { word?: string; ipa?: string }[] }> => {
|
||||
const {
|
||||
key,
|
||||
modelName = "gpt-3.5-turbo-1106",
|
||||
temperature = 0,
|
||||
baseUrl,
|
||||
} = options;
|
||||
const { key, temperature = 0, baseUrl } = options;
|
||||
let { modelName = "gpt-4-turbo-preview" } = options;
|
||||
|
||||
if (RESPONSE_JSON_FORMAT_MODELS.indexOf(modelName) === -1) {
|
||||
modelName = "gpt-4-turbo-preview";
|
||||
}
|
||||
|
||||
const responseSchema = z.object({
|
||||
words: z.array(
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
StructuredOutputParser,
|
||||
OutputFixingParser,
|
||||
} from "langchain/output_parsers";
|
||||
import { RESPONSE_JSON_FORMAT_MODELS } from "@/constants";
|
||||
|
||||
export const lookupCommand = async (
|
||||
params: {
|
||||
@@ -28,12 +29,13 @@ export const lookupCommand = async (
|
||||
translation?: string;
|
||||
lemma?: string;
|
||||
}> => {
|
||||
const {
|
||||
key,
|
||||
modelName = "gpt-3.5-turbo-1106",
|
||||
temperature = 0,
|
||||
baseUrl,
|
||||
} = options;
|
||||
const { key, temperature = 0, baseUrl } = options;
|
||||
let { modelName = "gpt-4-turbo-preview" } = options;
|
||||
|
||||
if (RESPONSE_JSON_FORMAT_MODELS.indexOf(modelName) === -1) {
|
||||
modelName = "gpt-4-turbo-preview";
|
||||
}
|
||||
|
||||
const { word, context, meaningOptions } = params;
|
||||
|
||||
const responseSchema = z.object({
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { ChatOpenAI } from "@langchain/openai";
|
||||
import { ChatPromptTemplate } from "@langchain/core/prompts";
|
||||
import { RESPONSE_JSON_FORMAT_MODELS } from "@/constants";
|
||||
|
||||
export const translateCommand = async (
|
||||
text: string,
|
||||
@@ -10,12 +11,12 @@ export const translateCommand = async (
|
||||
baseUrl?: string;
|
||||
}
|
||||
): Promise<string> => {
|
||||
const {
|
||||
key,
|
||||
modelName = "gpt-3.5-turbo-1106",
|
||||
temperature = 0,
|
||||
baseUrl,
|
||||
} = options;
|
||||
const { key, temperature = 0, baseUrl } = options;
|
||||
let { modelName = "gpt-4-turbo-preview" } = options;
|
||||
|
||||
if (RESPONSE_JSON_FORMAT_MODELS.indexOf(modelName) === -1) {
|
||||
modelName = "gpt-4-turbo-preview";
|
||||
}
|
||||
|
||||
const chatModel = new ChatOpenAI({
|
||||
openAIApiKey: key,
|
||||
|
||||
Reference in New Issue
Block a user