Skip to content
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

Add temperature setting #17

Merged
merged 5 commits into from
Feb 8, 2024
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
8 changes: 7 additions & 1 deletion src/rawdog/llm_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
get_llm_base_url,
get_llm_custom_provider,
get_llm_model,
get_llm_temperature,
rawdog_dir,
set_base_url,
set_llm_custom_provider,
set_llm_model,
set_llm_temperature,
)


Expand Down Expand Up @@ -58,6 +60,9 @@ def __init__(self):
set_llm_model(self.model)
self.custom_provider = get_llm_custom_provider() or None
set_llm_custom_provider(self.custom_provider)
cfg_temperature = get_llm_temperature()
self.temperature = cfg_temperature if cfg_temperature is not None else 1.0
set_llm_temperature(self.temperature)

# In general it's hard to know if the user needs an API key or which environment variables to set
# If they're using the defaults they'll need to set the OPENAI_API_KEY environment variable
Expand All @@ -66,6 +71,7 @@ def __init__(self):
if not env_api_key:
print("Please set the OPENAI_API_KEY environment variable.")
quit()

self.conversation = [
{"role": "system", "content": script_prompt},
{"role": "system", "content": script_examples},
Expand All @@ -87,7 +93,7 @@ def get_response(
base_url=self.base_url,
model=self.model,
messages=messages,
temperature=1.0,
temperature=self.temperature,
custom_llm_provider=self.custom_provider,
)
text = (response.choices[0].message.content) or ""
Expand Down
11 changes: 11 additions & 0 deletions src/rawdog/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ def get_llm_custom_provider():
return config.get("llm_custom_provider")


def get_llm_temperature():
config = load_config()
return config.get("llm_temperature")


def set_llm_model(model_name: str):
config = load_config()
config["llm_model"] = model_name
Expand All @@ -90,3 +95,9 @@ def set_llm_custom_provider(custom_provider: str):
config = load_config()
config["llm_custom_provider"] = custom_provider
save_config(config)


def set_llm_temperature(temperature: float):
config = load_config()
config["llm_temperature"] = temperature
save_config(config)