Skip to content

replace prompts with inquirer #489

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
43 changes: 24 additions & 19 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",
Expand Down Expand Up @@ -56,42 +56,47 @@ export async function askAnthropicQuestions({
},
};

if (!config.apiKey) {
const { key } = await prompts(
if (!config.apiKey && !process.env.CI) {
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):",
message: askModels
? "Please provide your Anthropic API key (or leave blank to use ANTHROPIC_API_KEY env variable):"
: "Please provide your Anthropic API key (leave blank to skip):",
validate: (value: string) => {
if (askModels && !value) {
if (process.env.ANTHROPIC_API_KEY) {
return true;
}
return "ANTHROPIC_API_KEY env variable is not set - key is required";
}
return true;
},
},
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[
Expand Down
47 changes: 33 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" },
Expand Down Expand Up @@ -66,29 +65,49 @@ export async function askAzureQuestions({
},
};

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

if (!config.endpoint) {
const { endpoint } = await inquirer.prompt([
{
type: "input",
name: "endpoint",
message:
"Please provide your Azure OpenAI endpoint (or leave blank to use AZURE_OPENAI_ENDPOINT env variable):",
},
]);
config.endpoint = endpoint || process.env.AZURE_OPENAI_ENDPOINT;
}

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);
}
Expand All @@ -98,14 +117,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,
}));
}
Expand Down
41 changes: 23 additions & 18 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 = {
Expand Down Expand Up @@ -41,41 +41,46 @@ 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):",
message: askModels
? "Please provide your Google API key (or leave blank to use GOOGLE_API_KEY env variable):"
: "Please provide your Google API key (leave blank to skip):",
validate: (value: string) => {
if (askModels && !value) {
if (process.env.GOOGLE_API_KEY) {
return true;
}
return "GOOGLE_API_KEY env variable is not set - key is required";
}
return true;
},
},
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;
}
Expand Down
41 changes: 23 additions & 18 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";
Expand Down Expand Up @@ -97,43 +97,48 @@ 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):",
message: askModels
? "Please provide your Groq API key (or leave blank to use GROQ_API_KEY env variable):"
: "Please provide your Groq API key (leave blank to skip):",
validate: (value: string) => {
if (askModels && !value) {
if (process.env.GROQ_API_KEY) {
return true;
}
return "GROQ_API_KEY env variable is not set - key is required";
}
return true;
},
},
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[
Expand Down
34 changes: 21 additions & 13 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 = {
Expand Down Expand Up @@ -37,29 +37,37 @@ export async function askHuggingfaceQuestions({
},
};

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

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?",
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;
}
Expand Down
Loading
Loading