Skip to content

Commit

Permalink
Request timeout can now be configured in settings modal
Browse files Browse the repository at this point in the history
  • Loading branch information
dezoito committed Mar 23, 2024
1 parent 7bf9160 commit 37fd68c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub async fn get_inference(
dbg!(&req);

// Process the inference; set a wrap for a timeout
let timeout = Duration::from_secs(30);
let timeout = Duration::from_secs(config.request_timeout);
let res = match time::timeout(timeout, ollama.generate(req)).await {
Ok(result) => result,
Err(_) => {
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub struct TParamIteration {
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "snake_case")]
pub struct IDefaultConfigs {
pub request_timeout: u64,
pub server_url: String,
pub system_prompt: String,
pub default_options: HashMap<String, Value>,
Expand Down
1 change: 1 addition & 0 deletions src/Atoms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const atomWithLocalStorage = (key: string, initialValue: unknown) => {
};

const defaultConfigs: IDefaultConfigs = {
request_timeout: 300,
server_url: "http://localhost:11434/",
system_prompt: "",
default_options: {
Expand Down
1 change: 1 addition & 0 deletions src/Interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type TParamIteration = {

// Interface for the default configuration options
export interface IDefaultConfigs {
request_timeout: number;
server_url: string;
system_prompt: string;
// default_options: {
Expand Down
21 changes: 20 additions & 1 deletion src/components/settings-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function SettingsDialog() {

// * default_options has to be valid JSON
const FormSchema = z.object({
request_timeout: z.coerce.number().min(5),
server_url: z.string().url(),
system_prompt: z.string(),
default_options: z.string().refine(
Expand Down Expand Up @@ -115,7 +116,7 @@ export function SettingsDialog() {
form here
*/}

<div className="grid gap-6 py-4">
<div className="grid max-h-[500px] gap-6 overflow-y-auto px-4 py-4">
<div className="flex flex-col gap-4">
<FormField
control={form.control}
Expand All @@ -134,6 +135,24 @@ export function SettingsDialog() {
)}
/>
</div>
<div className="flex flex-col gap-4">
<FormField
control={form.control}
name="request_timeout"
render={({ field }) => (
<FormItem>
<FormLabel>Request Timeout (secs)</FormLabel>
<FormControl>
<Input {...field} />
</FormControl>
<FormDescription>
The timeout in seconds for each inference request.
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
</div>
<div className="flex flex-col gap-4">
<FormField
control={form.control}
Expand Down

0 comments on commit 37fd68c

Please sign in to comment.