Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace prompts with inquirer #489

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions helpers/providers/anthropic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import prompts from "prompts";
import inquirer from "inquirer";
import { ModelConfigParams } from ".";
import { questionHandlers, toChoice } from "../../questions/utils";
import { toChoice } from "../../questions/utils";

const MODELS = [
"claude-3-opus",
@@ -57,41 +57,36 @@ export async function askAnthropicQuestions({
};

if (!config.apiKey) {
const { key } = await prompts(
const { key } = await inquirer.prompt([
{
type: "text",
type: "input",
name: "key",
message:
"Please provide your Anthropic API key (or leave blank to use ANTHROPIC_API_KEY env variable):",
},
questionHandlers,
);
]);
config.apiKey = key || process.env.ANTHROPIC_API_KEY;
}

if (askModels) {
const { model } = await prompts(
const { model } = await inquirer.prompt([
{
type: "select",
type: "list",
name: "model",
message: "Which LLM model would you like to use?",
choices: MODELS.map(toChoice),
initial: 0,
},
questionHandlers,
);
]);
config.model = model;

const { embeddingModel } = await prompts(
const { embeddingModel } = await inquirer.prompt([
{
type: "select",
type: "list",
name: "embeddingModel",
message: "Which embedding model would you like to use?",
choices: Object.keys(EMBEDDING_MODELS).map(toChoice),
initial: 0,
},
questionHandlers,
);
]);
config.embeddingModel = embeddingModel;
config.dimensions =
EMBEDDING_MODELS[
23 changes: 9 additions & 14 deletions helpers/providers/azure.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import prompts from "prompts";
import inquirer from "inquirer";
import { ModelConfigParams, ModelConfigQuestionsParams } from ".";
import { questionHandlers } from "../../questions/utils";

const ALL_AZURE_OPENAI_CHAT_MODELS: Record<string, { openAIModel: string }> = {
"gpt-35-turbo": { openAIModel: "gpt-3.5-turbo" },
@@ -67,28 +66,24 @@ export async function askAzureQuestions({
};

if (askModels) {
const { model } = await prompts(
const { model } = await inquirer.prompt([
{
type: "select",
type: "list",
name: "model",
message: "Which LLM model would you like to use?",
choices: getAvailableModelChoices(),
initial: 0,
},
questionHandlers,
);
]);
config.model = model;

const { embeddingModel } = await prompts(
const { embeddingModel } = await inquirer.prompt([
{
type: "select",
type: "list",
name: "embeddingModel",
message: "Which embedding model would you like to use?",
choices: getAvailableEmbeddingModelChoices(),
initial: 0,
},
questionHandlers,
);
]);
config.embeddingModel = embeddingModel;
config.dimensions = getDimensions(embeddingModel);
}
@@ -98,14 +93,14 @@ export async function askAzureQuestions({

function getAvailableModelChoices() {
return Object.keys(ALL_AZURE_OPENAI_CHAT_MODELS).map((key) => ({
title: key,
name: key,
value: key,
}));
}

function getAvailableEmbeddingModelChoices() {
return Object.keys(ALL_AZURE_OPENAI_EMBEDDING_MODELS).map((key) => ({
title: key,
name: key,
value: key,
}));
}
27 changes: 11 additions & 16 deletions helpers/providers/gemini.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import prompts from "prompts";
import inquirer from "inquirer";
import { ModelConfigParams } from ".";
import { questionHandlers, toChoice } from "../../questions/utils";
import { toChoice } from "../../questions/utils";

const MODELS = ["gemini-1.5-pro-latest", "gemini-pro", "gemini-pro-vision"];
type ModelData = {
@@ -41,41 +41,36 @@ export async function askGeminiQuestions({
};

if (!config.apiKey) {
const { key } = await prompts(
const { key } = await inquirer.prompt([
{
type: "text",
type: "input",
name: "key",
message:
"Please provide your Google API key (or leave blank to use GOOGLE_API_KEY env variable):",
},
questionHandlers,
);
]);
config.apiKey = key || process.env.GOOGLE_API_KEY;
}

if (askModels) {
const { model } = await prompts(
const { model } = await inquirer.prompt([
{
type: "select",
type: "list",
name: "model",
message: "Which LLM model would you like to use?",
choices: MODELS.map(toChoice),
initial: 0,
},
questionHandlers,
);
]);
config.model = model;

const { embeddingModel } = await prompts(
const { embeddingModel } = await inquirer.prompt([
{
type: "select",
type: "list",
name: "embeddingModel",
message: "Which embedding model would you like to use?",
choices: Object.keys(EMBEDDING_MODELS).map(toChoice),
initial: 0,
},
questionHandlers,
);
]);
config.embeddingModel = embeddingModel;
config.dimensions = EMBEDDING_MODELS[embeddingModel].dimensions;
}
27 changes: 11 additions & 16 deletions helpers/providers/groq.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import prompts from "prompts";
import inquirer from "inquirer";
import { ModelConfigParams } from ".";
import { questionHandlers, toChoice } from "../../questions/utils";
import { toChoice } from "../../questions/utils";

import got from "got";
import ora from "ora";
@@ -97,43 +97,38 @@ export async function askGroqQuestions({
};

if (!config.apiKey) {
const { key } = await prompts(
const { key } = await inquirer.prompt([
{
type: "text",
type: "input",
name: "key",
message:
"Please provide your Groq API key (or leave blank to use GROQ_API_KEY env variable):",
},
questionHandlers,
);
]);
config.apiKey = key || process.env.GROQ_API_KEY;
}

if (askModels) {
const modelChoices = await getAvailableModelChoicesGroq(config.apiKey!);

const { model } = await prompts(
const { model } = await inquirer.prompt([
{
type: "select",
type: "list",
name: "model",
message: "Which LLM model would you like to use?",
choices: modelChoices,
initial: 0,
},
questionHandlers,
);
]);
config.model = model;

const { embeddingModel } = await prompts(
const { embeddingModel } = await inquirer.prompt([
{
type: "select",
type: "list",
name: "embeddingModel",
message: "Which embedding model would you like to use?",
choices: Object.keys(EMBEDDING_MODELS).map(toChoice),
initial: 0,
},
questionHandlers,
);
]);
config.embeddingModel = embeddingModel;
config.dimensions =
EMBEDDING_MODELS[
20 changes: 8 additions & 12 deletions helpers/providers/huggingface.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import prompts from "prompts";
import inquirer from "inquirer";
import { ModelConfigParams } from ".";
import { questionHandlers, toChoice } from "../../questions/utils";
import { toChoice } from "../../questions/utils";

const MODELS = ["HuggingFaceH4/zephyr-7b-alpha"];
type ModelData = {
@@ -38,28 +38,24 @@ export async function askHuggingfaceQuestions({
};

if (askModels) {
const { model } = await prompts(
const { model } = await inquirer.prompt([
{
type: "select",
type: "list",
name: "model",
message: "Which Hugging Face model would you like to use?",
choices: MODELS.map(toChoice),
initial: 0,
},
questionHandlers,
);
]);
config.model = model;

const { embeddingModel } = await prompts(
const { embeddingModel } = await inquirer.prompt([
{
type: "select",
type: "list",
name: "embeddingModel",
message: "Which embedding model would you like to use?",
choices: Object.keys(EMBEDDING_MODELS).map(toChoice),
initial: 0,
},
questionHandlers,
);
]);
config.embeddingModel = embeddingModel;
config.dimensions = EMBEDDING_MODELS[embeddingModel].dimensions;
}
29 changes: 13 additions & 16 deletions helpers/providers/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import prompts from "prompts";
import { questionHandlers } from "../../questions/utils";
import inquirer from "inquirer";
import { ModelConfig, ModelProvider, TemplateFramework } from "../types";
import { askAnthropicQuestions } from "./anthropic";
import { askAzureQuestions } from "./azure";
@@ -29,29 +28,27 @@ export async function askModelConfig({
let modelProvider: ModelProvider = DEFAULT_MODEL_PROVIDER;
if (askModels) {
let choices = [
{ title: "OpenAI", value: "openai" },
{ title: "Groq", value: "groq" },
{ title: "Ollama", value: "ollama" },
{ title: "Anthropic", value: "anthropic" },
{ title: "Gemini", value: "gemini" },
{ title: "Mistral", value: "mistral" },
{ title: "AzureOpenAI", value: "azure-openai" },
{ name: "OpenAI", value: "openai" },
{ name: "Groq", value: "groq" },
{ name: "Ollama", value: "ollama" },
{ name: "Anthropic", value: "anthropic" },
{ name: "Gemini", value: "gemini" },
{ name: "Mistral", value: "mistral" },
{ name: "AzureOpenAI", value: "azure-openai" },
];

if (framework === "fastapi") {
choices.push({ title: "T-Systems", value: "t-systems" });
choices.push({ title: "Huggingface", value: "huggingface" });
choices.push({ name: "T-Systems", value: "t-systems" });
choices.push({ name: "Huggingface", value: "huggingface" });
}
const { provider } = await prompts(
const { provider } = await inquirer.prompt([
{
type: "select",
type: "list",
name: "provider",
message: "Which model provider would you like to use",
choices: choices,
initial: 0,
},
questionHandlers,
);
]);
modelProvider = provider;
}

Loading
Loading