Skip to content

Commit

Permalink
Merge pull request #20 from jekalmin/add-f-17
Browse files Browse the repository at this point in the history
[#17] add base url in config flow
  • Loading branch information
jekalmin authored Nov 9, 2023
2 parents b2861d3 + a09bb64 commit 919dca9
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 5 deletions.
2 changes: 2 additions & 0 deletions custom_components/extended_openai_conversation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
CONF_TOP_P,
CONF_MAX_FUNCTION_CALLS_PER_CONVERSATION,
CONF_FUNCTIONS,
CONF_BASE_URL,
DEFAULT_CHAT_MODEL,
DEFAULT_MAX_TOKENS,
DEFAULT_PROMPT,
Expand Down Expand Up @@ -263,6 +264,7 @@ async def query(
_LOGGER.info("Prompt for %s: %s", model, messages)

response = await openai.ChatCompletion.acreate(
api_base=self.entry.data.get(CONF_BASE_URL),
api_key=self.entry.data[CONF_API_KEY],
model=model,
messages=messages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
CONF_TOP_P,
CONF_MAX_FUNCTION_CALLS_PER_CONVERSATION,
CONF_FUNCTIONS,
CONF_BASE_URL,
DEFAULT_CHAT_MODEL,
DEFAULT_MAX_TOKENS,
DEFAULT_PROMPT,
DEFAULT_TEMPERATURE,
DEFAULT_TOP_P,
DEFAULT_MAX_FUNCTION_CALLS_PER_CONVERSATION,
DEFAULT_CONF_FUNCTIONS,
DEFAULT_CONF_BASE_URL,
DOMAIN,
DEFAULT_NAME,
)
Expand All @@ -48,6 +50,7 @@
{
vol.Optional(CONF_NAME): str,
vol.Required(CONF_API_KEY): str,
vol.Optional(CONF_BASE_URL, default=DEFAULT_CONF_BASE_URL): str,
}
)

Expand All @@ -72,7 +75,10 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> None:
Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
"""
openai.api_key = data[CONF_API_KEY]
await hass.async_add_executor_job(partial(openai.Engine.list, request_timeout=10))
base_url = data.get(CONF_BASE_URL)
await hass.async_add_executor_job(
partial(openai.Engine.list, api_base=base_url, request_timeout=10)
)


class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
Expand Down
4 changes: 3 additions & 1 deletion custom_components/extended_openai_conversation/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"description": "The entity_id retrieved from available devices. It must start with domain, followed by dot character.",
}
},
"required": ["entity_id"]
"required": ["entity_id"],
},
},
"required": ["domain", "service", "service_data"],
Expand All @@ -75,3 +75,5 @@
"function": {"type": "native", "name": "execute_service"},
}
]
CONF_BASE_URL = "base_url"
DEFAULT_CONF_BASE_URL = "https://api.openai.com/v1"
3 changes: 2 additions & 1 deletion custom_components/extended_openai_conversation/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"user": {
"data": {
"name": "[%key:common::config_flow::data::name%]",
"api_key": "[%key:common::config_flow::data::api_key%]"
"api_key": "[%key:common::config_flow::data::api_key%]",
"base_url": "[%key:common::config_flow::data::base_url%]"
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"user": {
"data": {
"name": "Name",
"api_key": "API Key"
"api_key": "API Key",
"base_url": "Base Url"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"user": {
"data": {
"name": "Name",
"api_key": "API Key"
"api_key": "API Key",
"base_url": "Base Url"
}
}
}
Expand Down

0 comments on commit 919dca9

Please sign in to comment.