Skip to content

Commit

Permalink
✨ Fix issues where maxTokens not taken into consideration for execute…
Browse files Browse the repository at this point in the history
… task
  • Loading branch information
asim-shrestha committed Jun 29, 2023
1 parent d5774aa commit 5586b22
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion next/src/services/agent/agent-work/execute-task-work.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class ExecuteTaskWork implements AgentWork {
goal: this.parent.model.getGoal(),
task: this.task.value,
analysis: this.analysis,
model_settings: toApiModelSettings(this.parent.modelSettings),
model_settings: toApiModelSettings(this.parent.modelSettings, this.parent.session),
},
this.parent.$api.props.session?.accessToken || "",
() => {
Expand Down
2 changes: 1 addition & 1 deletion next/src/services/agent/autonomous-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AutonomousAgent {
this.modelSettings = modelSettings;
this.session = session;
this.$api = new AgentApi({
model_settings: toApiModelSettings(modelSettings),
model_settings: toApiModelSettings(modelSettings, session),
goal: this.model.getGoal(),
session,
});
Expand Down
6 changes: 5 additions & 1 deletion next/src/stores/modelSettingsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ export const useModelSettingsStore = createSelectors(
name: "agentgpt-settings-storage-v2",
storage: createJSONStorage(() => localStorage),
partialize: (state) => ({
modelSettings: state.modelSettings,
modelSettings: {
...state.modelSettings,
customModelName: "gpt-3.5-turbo",
maxTokens: Math.min(state.modelSettings.maxTokens, 4000),
},
}),
}
)
Expand Down
19 changes: 12 additions & 7 deletions next/src/utils/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Analysis } from "../services/agent/analysis";
import type { GPTModelNames, ModelSettings } from "../types";
import type { Session } from "next-auth";

export interface ApiModelSettings {
language: string;
Expand All @@ -8,13 +9,17 @@ export interface ApiModelSettings {
max_tokens: number;
}

export const toApiModelSettings = (modelSettings: ModelSettings) => ({
language: modelSettings.language.name,
model: modelSettings.customModelName,
temperature: modelSettings.customTemperature,
max_tokens: modelSettings.maxTokens,
custom_api_key: modelSettings.customApiKey,
});
export const toApiModelSettings = (modelSettings: ModelSettings, session?: Session) => {
const allowCustomization = session?.user;

return {
language: modelSettings.language.name,
model: allowCustomization ? modelSettings.customModelName : "gpt-3.5-turbo",
temperature: modelSettings.customTemperature,
max_tokens: allowCustomization ? modelSettings.maxTokens : 500,
custom_api_key: modelSettings.customApiKey,
};
};

export interface RequestBody {
model_settings: ApiModelSettings;
Expand Down

1 comment on commit 5586b22

@vercel
Copy link

@vercel vercel bot commented on 5586b22 Jun 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./docs

docs-git-main-reworkd.vercel.app
docs.reworkd.ai
docs-reworkd.vercel.app

Please sign in to comment.