Skip to content

Commit 285f26c

Browse files
committed
fix bugs around using openai client for ollama or openrouter etc
1 parent 8b2bd62 commit 285f26c

File tree

3 files changed

+32
-32
lines changed

3 files changed

+32
-32
lines changed

py-src/data_formulator/agent_routes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ def test_model():
158158
"message": ""
159159
}
160160
except Exception as e:
161+
print(f"Error: {e}")
161162
logger.info(f"Error: {e}")
162163
result = {
163164
"model": content['model'],

py-src/data_formulator/agents/client_utils.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def __init__(self, endpoint, model, api_key=None, api_base=None, api_version=No
5454
self.model = model
5555
else:
5656
self.model = f"ollama/{model}"
57+
5758

5859
def get_completion(self, messages):
5960
"""
@@ -63,12 +64,28 @@ def get_completion(self, messages):
6364
# Configure LiteLLM
6465

6566
if self.endpoint == "openai":
67+
68+
print("--------------------------------")
69+
print(f"self.params: {self.params}")
70+
print(f"self.model: {self.model}")
71+
print(f"self.endpoint: {self.endpoint}")
72+
print(f"self.params['api_key']: {self.params.get('api_key', 'None')}")
73+
print(f"self.params['api_base']: {self.params.get('api_base', 'None')}")
74+
print(f"self.params['api_version']: {self.params.get('api_version', 'None')}")
75+
print("--------------------------------")
76+
77+
6678
client = openai.OpenAI(
67-
api_key=self.params["api_key"],
68-
base_url=self.params["api_base"] if "api_base" in self.params else None,
79+
base_url=self.params.get("api_base", 'placeholder'),
80+
api_key=self.params.get("api_key", 'placeholder'),
6981
timeout=120
7082
)
7183

84+
85+
print("--------------------------------")
86+
print(f"client: {client}")
87+
print("--------------------------------")
88+
7289
completion_params = {
7390
"model": self.model,
7491
"messages": messages,

src/views/ModelSelectionDialog.tsx

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
100100

101101
const [newEndpoint, setNewEndpoint] = useState<string>(""); // openai, azure, ollama etc
102102
const [newModel, setNewModel] = useState<string>("");
103-
const [newApiKey, setNewApiKey] = useState<string | undefined>(undefined);
104-
const [newApiBase, setNewApiBase] = useState<string | undefined>(undefined);
105-
const [newApiVersion, setNewApiVersion] = useState<string | undefined>(undefined);
103+
const [newApiKey, setNewApiKey] = useState<string>("");
104+
const [newApiBase, setNewApiBase] = useState<string>("");
105+
const [newApiVersion, setNewApiVersion] = useState<string>("");
106106

107107
// Fetch available models from the API
108108
useEffect(() => {
@@ -145,23 +145,6 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
145145
fetchModelOptions();
146146
}, []);
147147

148-
useEffect(() => {
149-
if (newEndpoint == 'ollama') {
150-
if (!newApiBase) {
151-
setNewApiBase('http://localhost:11434');
152-
}
153-
}
154-
if (newEndpoint == "openai") {
155-
if (!newModel && providerModelOptions.openai.length > 0) {
156-
setNewModel(providerModelOptions.openai[0]);
157-
}
158-
}
159-
if (newEndpoint == "anthropic") {
160-
if (!newModel && providerModelOptions.anthropic.length > 0) {
161-
setNewModel(providerModelOptions.anthropic[0]);
162-
}
163-
}
164-
}, [newEndpoint, providerModelOptions]);
165148

166149
let modelExists = models.some(m =>
167150
m.endpoint == newEndpoint && m.model == newModel && m.api_base == newApiBase
@@ -247,8 +230,8 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
247230
<TextField fullWidth size="small" type={showKeys ? "text" : "password"}
248231
InputProps={{ style: { fontSize: "0.875rem" } }}
249232
placeholder='leave blank if using keyless access'
250-
error={!(newEndpoint == "azure" || newEndpoint == "ollama" || newEndpoint == "") && !newApiKey}
251-
value={newApiKey} onChange={(event: any) => { setNewApiKey(event.target.value); }}
233+
value={newApiKey}
234+
onChange={(event: any) => { setNewApiKey(event.target.value); }}
252235
autoComplete='off'
253236
/>
254237
</TableCell>
@@ -304,7 +287,6 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
304287
<TableCell align="right">
305288
<TextField size="small" type="text" fullWidth
306289
placeholder="api_base"
307-
error={newEndpoint === "azure" && !newApiBase}
308290
InputProps={{ style: { fontSize: "0.875rem" } }}
309291
value={newApiBase}
310292
onChange={(event: any) => { setNewApiBase(event.target.value); }}
@@ -343,9 +325,9 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
343325

344326
setNewEndpoint("");
345327
setNewModel("");
346-
setNewApiKey(undefined);
347-
setNewApiBase(undefined);
348-
setNewApiVersion(undefined);
328+
setNewApiKey("");
329+
setNewApiBase("");
330+
setNewApiVersion("");
349331
}}>
350332
<AddCircleIcon />
351333
</IconButton>
@@ -358,9 +340,9 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
358340
event.stopPropagation()
359341
setNewEndpoint("");
360342
setNewModel("");
361-
setNewApiKey(undefined);
362-
setNewApiBase(undefined);
363-
setNewApiVersion(undefined);
343+
setNewApiKey("");
344+
setNewApiBase("");
345+
setNewApiVersion("");
364346
}}>
365347
<ClearIcon />
366348
</IconButton>
@@ -527,7 +509,7 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
527509
{modelTable}
528510
</DialogContent>
529511
<DialogActions>
530-
{appConfig.DISABLE_DISPLAY_KEYS && (
512+
{!appConfig.DISABLE_DISPLAY_KEYS && (
531513
<Button sx={{marginRight: 'auto'}} endIcon={showKeys ? <VisibilityOffIcon /> : <VisibilityIcon />} onClick={()=>{
532514
setShowKeys(!showKeys);}}>
533515
{showKeys ? 'hide' : 'show'} keys

0 commit comments

Comments
 (0)