Skip to content
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
1 change: 1 addition & 0 deletions py-src/data_formulator/agent_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def test_model():
"message": ""
}
except Exception as e:
print(f"Error: {e}")
logger.info(f"Error: {e}")
result = {
"model": content['model'],
Expand Down
21 changes: 19 additions & 2 deletions py-src/data_formulator/agents/client_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def __init__(self, endpoint, model, api_key=None, api_base=None, api_version=No
self.model = model
else:
self.model = f"ollama/{model}"


def get_completion(self, messages):
"""
Expand All @@ -63,12 +64,28 @@ def get_completion(self, messages):
# Configure LiteLLM

if self.endpoint == "openai":

print("--------------------------------")
print(f"self.params: {self.params}")
print(f"self.model: {self.model}")
print(f"self.endpoint: {self.endpoint}")
print(f"self.params['api_key']: {self.params.get('api_key', 'None')}")
print(f"self.params['api_base']: {self.params.get('api_base', 'None')}")
print(f"self.params['api_version']: {self.params.get('api_version', 'None')}")
print("--------------------------------")


client = openai.OpenAI(
api_key=self.params["api_key"],
base_url=self.params["api_base"] if "api_base" in self.params else None,
base_url=self.params.get("api_base", 'placeholder'),
api_key=self.params.get("api_key", 'placeholder'),
timeout=120
)


print("--------------------------------")
print(f"client: {client}")
print("--------------------------------")

completion_params = {
"model": self.model,
"messages": messages,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "data_formulator"
version = "0.2"
version = "0.2.1"

requires-python = ">=3.9"
authors = [
Expand Down
42 changes: 12 additions & 30 deletions src/views/ModelSelectionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {

const [newEndpoint, setNewEndpoint] = useState<string>(""); // openai, azure, ollama etc
const [newModel, setNewModel] = useState<string>("");
const [newApiKey, setNewApiKey] = useState<string | undefined>(undefined);
const [newApiBase, setNewApiBase] = useState<string | undefined>(undefined);
const [newApiVersion, setNewApiVersion] = useState<string | undefined>(undefined);
const [newApiKey, setNewApiKey] = useState<string>("");
const [newApiBase, setNewApiBase] = useState<string>("");
const [newApiVersion, setNewApiVersion] = useState<string>("");

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

useEffect(() => {
if (newEndpoint == 'ollama') {
if (!newApiBase) {
setNewApiBase('http://localhost:11434');
}
}
if (newEndpoint == "openai") {
if (!newModel && providerModelOptions.openai.length > 0) {
setNewModel(providerModelOptions.openai[0]);
}
}
if (newEndpoint == "anthropic") {
if (!newModel && providerModelOptions.anthropic.length > 0) {
setNewModel(providerModelOptions.anthropic[0]);
}
}
}, [newEndpoint, providerModelOptions]);

let modelExists = models.some(m =>
m.endpoint == newEndpoint && m.model == newModel && m.api_base == newApiBase
Expand Down Expand Up @@ -247,8 +230,8 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
<TextField fullWidth size="small" type={showKeys ? "text" : "password"}
InputProps={{ style: { fontSize: "0.875rem" } }}
placeholder='leave blank if using keyless access'
error={!(newEndpoint == "azure" || newEndpoint == "ollama" || newEndpoint == "") && !newApiKey}
value={newApiKey} onChange={(event: any) => { setNewApiKey(event.target.value); }}
value={newApiKey}
onChange={(event: any) => { setNewApiKey(event.target.value); }}
Copy link

Copilot AI Apr 24, 2025

Choose a reason for hiding this comment

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

Removing the error prop from the API key field may lead to users not receiving feedback when an API key is required. Consider reinstating validation for newApiKey based on the endpoint conditions.

Suggested change
onChange={(event: any) => { setNewApiKey(event.target.value); }}
onChange={(event: any) => { setNewApiKey(event.target.value); }}
error={newEndpoint !== "" && !newApiKey}
helperText={newEndpoint !== "" && !newApiKey ? "API key is required for this endpoint." : ""}

Copilot uses AI. Check for mistakes.
autoComplete='off'
/>
</TableCell>
Expand Down Expand Up @@ -304,7 +287,6 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
<TableCell align="right">
<TextField size="small" type="text" fullWidth
placeholder="api_base"
error={newEndpoint === "azure" && !newApiBase}
InputProps={{ style: { fontSize: "0.875rem" } }}
value={newApiBase}
onChange={(event: any) => { setNewApiBase(event.target.value); }}
Expand Down Expand Up @@ -343,9 +325,9 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {

setNewEndpoint("");
setNewModel("");
setNewApiKey(undefined);
setNewApiBase(undefined);
setNewApiVersion(undefined);
setNewApiKey("");
setNewApiBase("");
setNewApiVersion("");
}}>
<AddCircleIcon />
</IconButton>
Expand All @@ -358,9 +340,9 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
event.stopPropagation()
setNewEndpoint("");
setNewModel("");
setNewApiKey(undefined);
setNewApiBase(undefined);
setNewApiVersion(undefined);
setNewApiKey("");
setNewApiBase("");
setNewApiVersion("");
}}>
<ClearIcon />
</IconButton>
Expand Down Expand Up @@ -527,7 +509,7 @@ export const ModelSelectionButton: React.FC<{}> = ({ }) => {
{modelTable}
</DialogContent>
<DialogActions>
{appConfig.DISABLE_DISPLAY_KEYS && (
{!appConfig.DISABLE_DISPLAY_KEYS && (
<Button sx={{marginRight: 'auto'}} endIcon={showKeys ? <VisibilityOffIcon /> : <VisibilityIcon />} onClick={()=>{
setShowKeys(!showKeys);}}>
{showKeys ? 'hide' : 'show'} keys
Expand Down