From 098d67cd8ce6631993bd9e51404961ebba13b3a1 Mon Sep 17 00:00:00 2001 From: Gianluigi Conti <13535297+glconti@users.noreply.github.com> Date: Tue, 9 Sep 2025 10:14:34 +0200 Subject: [PATCH 1/2] feat(openai): add Azure OpenAI support with configuration options --- apps/client/src/constants/llm.ts | 1 + .../dashboard/settings/_sections/openai.tsx | 107 ++++++++++++++++-- apps/client/src/services/openai/client.ts | 33 +++++- apps/client/src/stores/openai.ts | 14 ++- 4 files changed, 143 insertions(+), 12 deletions(-) diff --git a/apps/client/src/constants/llm.ts b/apps/client/src/constants/llm.ts index b713400a..e33b3948 100644 --- a/apps/client/src/constants/llm.ts +++ b/apps/client/src/constants/llm.ts @@ -1,2 +1,3 @@ export const DEFAULT_MODEL = "gpt-3.5-turbo"; export const DEFAULT_MAX_TOKENS = 1024; +export const DEFAULT_AZURE_API_VERSION = "2025-01-01-preview"; diff --git a/apps/client/src/pages/dashboard/settings/_sections/openai.tsx b/apps/client/src/pages/dashboard/settings/_sections/openai.tsx index 1a37f316..cb866871 100644 --- a/apps/client/src/pages/dashboard/settings/_sections/openai.tsx +++ b/apps/client/src/pages/dashboard/settings/_sections/openai.tsx @@ -11,11 +11,12 @@ import { FormLabel, FormMessage, Input, + Checkbox, } from "@reactive-resume/ui"; import { useForm } from "react-hook-form"; import { z } from "zod"; -import { DEFAULT_MAX_TOKENS, DEFAULT_MODEL } from "@/client/constants/llm"; +import { DEFAULT_MAX_TOKENS, DEFAULT_MODEL, DEFAULT_AZURE_API_VERSION } from "@/client/constants/llm"; import { useOpenAiStore } from "@/client/stores/openai"; const formSchema = z.object({ @@ -32,13 +33,21 @@ const formSchema = z.object({ .default(""), model: z.string().default(DEFAULT_MODEL), maxTokens: z.number().default(DEFAULT_MAX_TOKENS), + isAzure: z.boolean().default(false), + azureApiVersion: z.string().default(DEFAULT_AZURE_API_VERSION), }); type FormValues = z.infer; export const OpenAISettings = () => { - const { apiKey, setApiKey, baseURL, setBaseURL, model, setModel, maxTokens, setMaxTokens } = - useOpenAiStore(); + const { + apiKey, setApiKey, + baseURL, setBaseURL, + model, setModel, + maxTokens, setMaxTokens, + isAzure, setIsAzure, + azureApiVersion, setAzureApiVersion + } = useOpenAiStore(); const isEnabled = !!apiKey; @@ -49,11 +58,14 @@ export const OpenAISettings = () => { baseURL: baseURL ?? "", model: model ?? DEFAULT_MODEL, maxTokens: maxTokens ?? DEFAULT_MAX_TOKENS, + isAzure: isAzure ?? false, + azureApiVersion: azureApiVersion ?? DEFAULT_AZURE_API_VERSION, }, }); - const onSubmit = ({ apiKey, baseURL, model, maxTokens }: FormValues) => { + const onSubmit = ({ apiKey, baseURL, model, maxTokens, isAzure, azureApiVersion }: FormValues) => { setApiKey(apiKey); + setIsAzure(isAzure); if (baseURL) { setBaseURL(baseURL); } @@ -63,6 +75,9 @@ export const OpenAISettings = () => { if (maxTokens) { setMaxTokens(maxTokens); } + if (azureApiVersion) { + setAzureApiVersion(azureApiVersion); + } }; const onRemove = () => { @@ -70,15 +85,24 @@ export const OpenAISettings = () => { setBaseURL(null); setModel(DEFAULT_MODEL); setMaxTokens(DEFAULT_MAX_TOKENS); - form.reset({ apiKey: "", baseURL: "", model: DEFAULT_MODEL, maxTokens: DEFAULT_MAX_TOKENS }); + setIsAzure(false); + setAzureApiVersion(DEFAULT_AZURE_API_VERSION); + form.reset({ + apiKey: "", + baseURL: "", + model: DEFAULT_MODEL, + maxTokens: DEFAULT_MAX_TOKENS, + isAzure: false, + azureApiVersion: DEFAULT_AZURE_API_VERSION + }); }; return (
-

{t`OpenAI/Ollama Integration`}

+

{t`OpenAI/Azure OpenAI/Ollama Integration`}

- {t`You can make use of the OpenAI API to help you generate content, or improve your writing while composing your resume.`} + {t`You can make use of the OpenAI API, Azure OpenAI, or Ollama to help you generate content, or improve your writing while composing your resume.`}

@@ -99,6 +123,15 @@ export const OpenAISettings = () => {

+

+ + You can also integrate with Azure OpenAI by enabling the "Use Azure OpenAI" checkbox + and setting the Resource URL to your Azure OpenAI resource (e.g., + `https://your-resource.openai.azure.com`). Set the deployment name in the Model field + and specify the appropriate API version for your Azure deployment. + +

+

You can also integrate with Ollama simply by setting the API key to @@ -129,9 +162,22 @@ export const OpenAISettings = () => { control={form.control} render={({ field }) => ( - {t`Base URL`} + + {form.watch("isAzure") + ? t`Azure OpenAI Resource URL` + : t`Base URL` + } + - + @@ -142,7 +188,12 @@ export const OpenAISettings = () => { control={form.control} render={({ field }) => ( - {t`Model`} + + {form.watch("isAzure") + ? t`Deployment Name` + : t`Model` + } + @@ -170,6 +221,42 @@ export const OpenAISettings = () => { )} /> + ( + + + + +

+ {t`Use Azure OpenAI`} +
+ + + )} + /> + ( + + {t`Azure API Version`} + + + + + + )} + />