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

Model component enhancements #1517

Merged
merged 14 commits into from
Apr 18, 2024
6 changes: 6 additions & 0 deletions agenta-backend/agenta_backend/models/api/evaluation_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ class LMProvidersEnum(str, Enum):
azure_key = "AZURE_API_KEY"
aakrem marked this conversation as resolved.
Show resolved Hide resolved
togetherai = "TOGETHERAI_API_KEY"
mistralai = "MISTRAL_API_KEY"
perplexityai = "PERPLEXITYAI_API_KEY"
anyscale = "ANYSCALE_API_KEY"
fireworksai = "FIREWORKS_AI_API_KEY"
deepinfra = "DEEPINFRA_API_KEY"
alephalpha = "ALEPHALPHA_API_KEY"
openrouter = "OPENROUTER_API_KEY"


class NewEvaluation(BaseModel):
Expand Down
7 changes: 7 additions & 0 deletions agenta-backend/agenta_backend/routers/app_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,13 @@ async def create_app_and_variant_from_template(
"OPENAI_API_KEY",
"MISTRAL_API_KEY",
"COHERE_API_KEY",
"ANTHROPIC_API_KEY",
"ANYSCALE_API_KEY",
"PERPLEXITYAI_API_KEY",
"DEEPINFRA_API_KEY",
"TOGETHERAI_API_KEY",
"ALEPHALPHA_API_KEY",
"OPENROUTER_API_KEY",
]
missing_keys = [
key for key in supported_llm_prodviders_keys if not os.environ.get(key)
Expand Down
1 change: 1 addition & 0 deletions agenta-web/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const nextConfig = {
reactStrictMode: true,
pageExtensions: ["ts", "tsx", "js", "jsx", "md", "mdx"],
productionBrowserSourceMaps: true,
transpilePackages: ["@lobehub/icons"],
swcMinify: true,

async redirects() {
Expand Down
380 changes: 371 additions & 9 deletions agenta-web/package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion agenta-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"@headlessui/react": "^1.7.18",
"@headlessui/tailwindcss": "^0.2.0",
"@heroicons/react": "^2.0.17",
"@lobehub/icons": "^1.18.0",
"@mdx-js/loader": "^2.3.0",
"@mdx-js/react": "^2.3.0",
"@monaco-editor/react": "^4.5.2",
Expand Down Expand Up @@ -91,6 +92,6 @@
"@types/node": "^20.8.10",
"cypress": "^13.4.0",
"node-mocks-http": "^1.12.2",
"prettier": "^3.0.0"
"prettier": "^3.2.5"
aakrem marked this conversation as resolved.
Show resolved Hide resolved
}
}
97 changes: 97 additions & 0 deletions agenta-web/src/components/Playground/Views/GroupedSelect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
import React from "react"
import {createUseStyles} from "react-jss"
import {Select} from "antd"

import {
IconType,
OpenAI,
Mistral,
Cohere,
Anthropic,
Perplexity,
Together,
OpenRouter,
Fireworks,
} from "@lobehub/icons"

const useStyles = createUseStyles({
select: {
width: "100%",
},
option: {
display: "flex",
alignItems: "center",
gap: "8px",
},
})

interface IconMap {
[key: string]: IconType
}

interface GroupedSelectProps {
choices: {[group: string]: string[]}
defaultValue: string
handleChange: (value: string) => void
}

const iconMap: {[key: string]: React.ComponentType<any>} = {
"Open AI": OpenAI,
"Mistral AI": Mistral.Color,
Cohere: Cohere.Color,
Anthropic: Anthropic,
"Perplexity AI": Perplexity.Color,
"Together AI": Together.Color,
OpenRouter: OpenRouter,
}

const getTextContent = (element: React.ReactNode): string => {
if (typeof element === "string") {
return element
} else if (React.isValidElement(element) && element.props.children) {
return React.Children.toArray(element.props.children).reduce<string>(
(acc, child) => acc + getTextContent(child),
"",
)
}
return ""
}

const filterOption = (input: string, option?: {label: React.ReactNode; value: string}) =>
getTextContent(option?.label).toLowerCase().includes(input.toLowerCase())

export const GroupedSelect: React.FC<GroupedSelectProps> = ({
choices,
defaultValue,
handleChange,
}) => {
const classes = useStyles()

const options = Object.entries(choices).map(([groupLabel, groupChoices]) => ({
label: (
<div className={classes.option}>
{iconMap[groupLabel] ? React.createElement(iconMap[groupLabel]) : null}
{groupLabel}
</div>
),
options: groupChoices.map((choice) => ({
label: (
<div className={classes.option}>
{iconMap[groupLabel] ? React.createElement(iconMap[groupLabel]) : null}
{choice}
</div>
),
value: choice,
})),
}))
return (
<Select
showSearch
defaultValue={defaultValue}
className={classes.select}
onChange={handleChange}
filterOption={filterOption}
options={options as any}
/>
)
}
74 changes: 27 additions & 47 deletions agenta-web/src/components/Playground/Views/ParametersCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {createUseStyles} from "react-jss"
import {renameVariables} from "@/lib/helpers/utils"
import {Parameter, InputParameter} from "@/lib/Types"
import {DownOutlined} from "@ant-design/icons"

import {
Row,
Card,
Expand All @@ -17,6 +18,7 @@ import {
Menu,
Space,
} from "antd"
import {GroupedSelect} from "./GroupedSelect"

const useStyles = createUseStyles({
row1: {
Expand Down Expand Up @@ -66,38 +68,14 @@ const useStyles = createUseStyles({
marginBottom: 8,
},
inputNumber: {
margin: "0 16px",
width: "100%",
margin: "0 0 0 16px",
width: "calc(100% - 16px)",
},
select: {
width: "100%",
},
})

interface GroupedSelectProps {
choices: {[group: string]: string[]}
defaultValue: string
handleChange: (value: string) => void
}

const GroupedSelect: React.FC<GroupedSelectProps> = ({choices, defaultValue, handleChange}) => {
const classes = useStyles()
return (
<Select
defaultValue={defaultValue}
className={classes.select}
onChange={handleChange}
options={Object.entries(choices).map(([groupLabel, groupChoices]) => ({
label: groupLabel,
options: groupChoices.map((choice) => ({
label: choice,
value: choice,
})),
}))}
/>
)
}

interface ModelParametersProps {
optParams: Parameter[] | null
onChange: (param: Parameter, value: number | string) => void
Expand Down Expand Up @@ -135,7 +113,7 @@ export const ModelParameters: React.FC<ModelParametersProps> = ({
{renameVariables(param.name)}
</h4>
</Col>
<Col span={8}>
<Col span={param.type === "grouped_choice" ? 10 : 8}>
{param.type === "number" && (
<Slider
min={param.minimum}
Expand Down Expand Up @@ -197,26 +175,28 @@ export const ModelParameters: React.FC<ModelParametersProps> = ({
/>
)}
</Col>
<Col>
{param.type === "number" && (
<InputNumber
min={0}
max={10000}
className={classes.inputNumber}
value={param.default}
onChange={(value) => onChange(param, value)}
/>
)}
{param.type === "integer" && (
<InputNumber
min={param.minimum}
max={param.maximum}
className={classes.inputNumber}
value={param.default}
onChange={(value) => onChange(param, value)}
/>
)}
</Col>
{param.type !== "grouped_choice" && (
aakrem marked this conversation as resolved.
Show resolved Hide resolved
<Col span={2}>
{param.type === "number" && (
<InputNumber
min={0}
max={10000}
className={classes.inputNumber}
value={param.default}
onChange={(value) => onChange(param, value)}
/>
)}
{param.type === "integer" && (
<InputNumber
min={param.minimum}
max={param.maximum}
className={classes.inputNumber}
value={param.default}
onChange={(value) => onChange(param, value)}
/>
)}
</Col>
)}
<Row />
</Row>
))}
Expand Down
13 changes: 9 additions & 4 deletions agenta-web/src/lib/helpers/llmProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ export type LlmProvider = {

export const llmAvailableProviders: LlmProvider[] = [
{title: "OpenAI", key: "", name: "OPENAI_API_KEY"},
{title: "Replicate", key: "", name: "REPLICATE_API_KEY"},
{title: "Hugging Face", key: "", name: "HUGGING_FACE_API_KEY"},
{title: "Mistral AI", key: "", name: "MISTRAL_API_KEY"},
{title: "Cohere", key: "", name: "COHERE_API_KEY"},
{title: "Anthropic", key: "", name: "ANTHROPIC_API_KEY"},
{title: "Azure", key: "", name: "AZURE_API_KEY"},
{title: "Anyscale", key: "", name: "ANYSCALE_API_KEY"},
{title: "Perplexity AI", key: "", name: "PERPLEXITYAI_API_KEY"},
{title: "DeepInfra", key: "", name: "DEEPINFRA_API_KEY"},
{title: "TogetherAI", key: "", name: "TOGETHERAI_API_KEY"},
{title: "Mistral AI", key: "", name: "MISTRAL_API_KEY"},
{title: "Aleph Alpha", key: "", name: "ALEPHALPHA_API_KEY"},
{title: "OpenRouter", key: "", name: "OPENROUTER_API_KEY"},
{title: "Replicate", key: "", name: "REPLICATE_API_KEY"},
{title: "Hugging Face", key: "", name: "HUGGING_FACE_API_KEY"},
{title: "Azure", key: "", name: "AZURE_API_KEY"},
]

export const getApikeys = () => {
Expand Down
Loading