-
Notifications
You must be signed in to change notification settings - Fork 20
feat(init): Replace create_chat_func
with client
#60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0beaf43
feat(querychat_init): Support `client` parameter
gadenbuie c7408cb
chore: Bump version to 0.0.1.9000
gadenbuie b5a5487
chore: Add news item
gadenbuie 73ec852
docs: Update README
gadenbuie fbd3071
docs: fix typo in readme
gadenbuie b060097
fix: Call client function with `system_prompt` value
gadenbuie 2f0f83d
feat(py): Use `init(client=)` instead of `create_chat_callback`
gadenbuie bda2821
chore(py): Add `seaborn` to examples dependencies
gadenbuie 288f711
chore(py): Add changelog item
gadenbuie 6d9fb87
fix(py): typo in docstring
gadenbuie c4f62f4
Apply suggestions from code review
gadenbuie 381dfb2
docs: Document `client` function signature
gadenbuie fbba6ed
chore(pkg-r): Use `null` as default for `system_prompt`
gadenbuie 671a956
tests: fix app test
gadenbuie a72ed02
tests(pkg-r): Use `{withr}`
gadenbuie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [UNRELEASED] | ||
|
||
* `querychat.init()` now accepts a `client` argument, replacing the previous `create_chat_callback` argument. (#60) | ||
|
||
The `client` can be: | ||
|
||
* a `chatlas.Chat` object, | ||
* a function that returns a `chatlas.Chat` object, | ||
* or a provider-model string, e.g. `"openai/gpt-4.1"`, to be passed to `chatlas.ChatAuto()`. | ||
|
||
If `client` is not provided, querychat will use the `QUERYCHAT_CLIENT` environment variable, which should be a provider-model string. If the envvar is not set, querychat uses OpenAI with the default model from `chatlas.ChatOpenAI()`. | ||
|
||
|
||
## [0.1.0] - 2025-05-24 | ||
|
||
This first release of the `querychat` package. | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
from contextlib import contextmanager | ||
from typing import Optional | ||
|
||
|
||
@contextmanager | ||
def temp_env_vars(env_vars: dict[str, Optional[str]]): | ||
""" | ||
Temporarily set environment variables and restore them when exiting. | ||
|
||
Parameters | ||
---------- | ||
env_vars : Dict[str, str] | ||
Dictionary of environment variable names to values to set temporarily | ||
|
||
Example | ||
------- | ||
with temp_env_vars({"FOO": "bar", "BAZ": "qux"}): | ||
# FOO and BAZ are set to "bar" and "qux" | ||
do_something() | ||
# FOO and BAZ are restored to their original values (or unset if they weren't set) | ||
|
||
""" | ||
original_values: dict[str, Optional[str]] = {} | ||
for key in env_vars: | ||
original_values[key] = os.environ.get(key) | ||
|
||
for key, value in env_vars.items(): | ||
if value is None: | ||
# If value is None, remove the variable | ||
os.environ.pop(key, None) | ||
else: | ||
# Otherwise set the variable to the specified value | ||
os.environ[key] = value | ||
|
||
try: | ||
yield | ||
finally: | ||
# Restore original values | ||
for key, original_value in original_values.items(): | ||
if original_value is None: | ||
# Variable wasn't set originally, so remove it | ||
os.environ.pop(key, None) | ||
else: | ||
# Restore original value | ||
os.environ[key] = original_value |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#' @keywords internal | ||
"_PACKAGE" | ||
|
||
## usethis namespace: start | ||
#' @importFrom lifecycle deprecated | ||
## usethis namespace: end | ||
NULL |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.