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

Added ability to configure temperature. #140

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ANTHROPIC_API_KEY="YOUR API KEY"
TAVILY_API_KEY="YOUR API KEY"
#TEMPERATURE=Value between 0.0 and 1.0
24 changes: 20 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ def setup_virtual_environment() -> Tuple[str, str]:
anthropic_api_key = os.getenv("ANTHROPIC_API_KEY")
if not anthropic_api_key:
raise ValueError("ANTHROPIC_API_KEY not found in environment variables")

# Read TEMPERATURE from environment variables
temperature = os.getenv("TEMPERATURE")
if temperature is not None:
try:
temperature = float(temperature)
except ValueError:
print("Invalid TEMPERATURE value in .env file. Using API default.")
temperature = None

client = Anthropic(api_key=anthropic_api_key)

# Initialize the Tavily client
Expand Down Expand Up @@ -362,7 +372,8 @@ async def generate_edit_instructions(file_path, file_content, instructions, proj
extra_headers={"anthropic-beta": "max-tokens-3-5-sonnet-2024-07-15"},
messages=[
{"role": "user", "content": "Generate SEARCH/REPLACE blocks for the necessary changes."}
]
],
**({'temperature': temperature} if temperature is not None else {})
)
# Update token usage for code editor
code_editor_tokens['input'] += response.usage.input_tokens
Expand Down Expand Up @@ -861,7 +872,8 @@ async def send_to_ai_for_executing(code, execution_result):
system=system_prompt,
messages=[
{"role": "user", "content": f"Analyze this code execution from the 'code_execution_env' virtual environment:\n\nCode:\n{code}\n\nExecution Result:\n{execution_result}"}
]
],
**({'temperature': temperature} if temperature is not None else {})
)

# Update token usage for code execution
Expand Down Expand Up @@ -977,7 +989,8 @@ async def chat_with_claude(user_input, image_path=None, current_iteration=None,
extra_headers={"anthropic-beta": "max-tokens-3-5-sonnet-2024-07-15"},
messages=messages,
tools=tools,
tool_choice={"type": "auto"}
tool_choice={"type": "auto"},
**({'temperature': temperature} if temperature is not None else {})
)
# Update token usage for MAINMODEL
main_model_tokens['input'] += response.usage.input_tokens
Expand Down Expand Up @@ -1074,7 +1087,8 @@ async def chat_with_claude(user_input, image_path=None, current_iteration=None,
extra_headers={"anthropic-beta": "max-tokens-3-5-sonnet-2024-07-15"},
messages=messages,
tools=tools,
tool_choice={"type": "auto"}
tool_choice={"type": "auto"},
**({'temperature': temperature} if temperature is not None else {})
)
# Update token usage for tool checker
tool_checker_tokens['input'] += tool_response.usage.input_tokens
Expand Down Expand Up @@ -1202,6 +1216,8 @@ async def main():
console.print("Type 'reset' to clear the conversation history.")
console.print("Type 'save chat' to save the conversation to a Markdown file.")
console.print("While in automode, press Ctrl+C at any time to exit the automode to return to regular chat.")
if temperature is not None:
console.print(f"Model temperature set to: {temperature}")

while True:
user_input = await get_user_input()
Expand Down