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

frontend: Fix Agent model being set #819

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions src/backend/routers/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ async def update_agent(
db_deployment, db_model = get_deployment_model_from_agent(new_agent, session)
deployment_config = new_agent.deployment_config
is_default_deployment = new_agent.is_default_deployment
# remove association fields
# Remove association fields - handled manually
new_agent_cleaned = new_agent.dict(
exclude={
"model",
Expand All @@ -290,7 +290,6 @@ async def update_agent(
"is_default_model",
}
)
# TODO Eugene - if no deployment or model is provide or if the deployment or model is not found, should we raise an error?
if db_deployment and db_model:
current_association = agent_crud.get_agent_model_deployment_association(
session, agent, db_model.id, db_deployment.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const UpdateAgent: React.FC<Props> = ({ agent }) => {
request: { ...fields, tools_metadata },
agentId: agent.id,
});
setIsSubmitting(false); // Reset button to allow new update after previous one
info(`Updated ${newAgent?.name}`);
} catch (e) {
setIsSubmitting(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ import { useState } from 'react';

import { AgentSettingsFields } from '@/components/AgentSettingsForm';
import { Dropdown } from '@/components/UI';
import { DEFAULT_AGENT_MODEL } from '@/constants';
import { useListAllDeployments } from '@/hooks';

type Props = {
fields: AgentSettingsFields;
isNewAssistant: boolean;
nameError?: string;
setFields: (fields: AgentSettingsFields) => void;
};

export const ConfigStep: React.FC<Props> = ({ fields, setFields }) => {
const [selectedValue, setSelectedValue] = useState<string | undefined>(DEFAULT_AGENT_MODEL);
const [selectedValue, setSelectedValue] = useState<string | undefined>(fields.model);

const { data: deployments } = useListAllDeployments();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export const AgentSettingsForm: React.FC<Props> = (props) => {
const { data: listToolsData, status: listToolsStatus } = useListTools();
const isAgentNameUnique = useIsAgentNameUnique();
const params = useSearchParams();
const defaultStep = params.has('datasources');
const defaultState = params.has('state');

useEffect(() => {
Expand All @@ -78,7 +77,7 @@ export const AgentSettingsForm: React.FC<Props> = (props) => {

const [currentStep, setCurrentStep] = useState<
'define' | 'config' | 'dataSources' | 'tools' | 'visibility' | undefined
>(() => (defaultStep ? 'dataSources' : 'define'));
>('define');

const [googleFiles, setGoogleFiles] = useState<DataSourceArtifact[]>(
fields.tools_metadata?.find((metadata) => metadata.tool_name === TOOL_GOOGLE_DRIVE_ID)
Expand Down Expand Up @@ -208,12 +207,7 @@ export const AgentSettingsForm: React.FC<Props> = (props) => {
isExpanded={currentStep === 'config'}
setIsExpanded={(expanded) => setCurrentStep(expanded ? 'config' : undefined)}
>
<ConfigStep
fields={fields}
setFields={setFields}
nameError={nameError}
isNewAssistant={source === 'create'}
/>
<ConfigStep fields={fields} setFields={setFields} nameError={nameError} />
<StepButtons
handleNext={() => setCurrentStep('dataSources')}
hide={source !== 'create'}
Expand Down
5 changes: 4 additions & 1 deletion src/interfaces/assistants_web/src/hooks/use-agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,11 @@ export const useIsAgentNameUnique = () => {
export const useUpdateAgent = () => {
const cohereClient = useCohereClient();
const queryClient = useQueryClient();

return useMutation<AgentPublic, ApiError, { request: UpdateAgentRequest; agentId: string }>({
mutationFn: ({ request, agentId }) => cohereClient.updateAgent(request, agentId),
mutationFn: ({ request, agentId }) => {
return cohereClient.updateAgent(request, agentId);
},
onSettled: (agent) => {
queryClient.invalidateQueries({ queryKey: ['agent', agent?.id] });
queryClient.invalidateQueries({ queryKey: ['listAgents'] });
Expand Down
Loading