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

Adding parameter support for Local LLMs and GROQ #808

Open
wants to merge 18 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,5 @@ workspace
pilot-env/

# Other
brija.py
brija.py
/pilot/.vs
5 changes: 4 additions & 1 deletion pilot/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# OPENAI or AZURE or OPENROUTER (ignored for Anthropic)
# OPENAI or AZURE or OPENROUTER (ignored for Anthropic) or GROQ
ENDPOINT=OPENAI

# OPENAI_ENDPOINT=https://api.openai.com/v1/chat/completions
Expand All @@ -8,6 +8,9 @@ OPENAI_API_KEY=
AZURE_API_KEY=
AZURE_ENDPOINT=

GROQ_API_KEY=
GROQ_ENDPOINT=

OPENROUTER_API_KEY=

# Set this to use Anthropic API directly
Expand Down
41 changes: 41 additions & 0 deletions pilot/.env.groq.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

ENDPOINT=GROQ
GROQ_API_KEY=sk-your-api-key-here

# In case of Azure/OpenRouter endpoint, change this to your deployed model name
MODEL_NAME=groq/mixtral-8x7b-32768
# In case of Anthropic, use "anthropic/" + the model name, example for Claude 3 Opus
# MODEL_NAME=anthropic/claude-3-opus-20240229
MAX_TOKENS=8192

# Parameters for fine tuning GROQ
#N=2
TEMPERATURE=0.8

#TOP_P=0.95
#FREQUENCY_PENALTY=0
#PRESENCE_PENALTY=0

API_CONNECT_TIMEOUT=30
API_READ_TIMEOUT=3000

# Folders which shouldn't be tracked in workspace (useful to ignore folders created by compiler)
# IGNORE_PATHS=folder1,folder2

# Database
# DATABASE_TYPE=postgres

DB_NAME=gpt-pilot
DB_HOST=
DB_PORT=
DB_USER=
DB_PASSWORD=

OPENAI_API_KEY=sk_needs_dummy_here
# USE_GPTPILOT_FOLDER=true

# Load database imported from another location/system - EXPERIMENTAL
# AUTOFIX_FILE_PATHS=false

# Set extra buffer to wait on top of detected retry time when rate limmit is hit. defaults to 6
# RATE_LIMIT_EXTRA_BUFFER=
45 changes: 45 additions & 0 deletions pilot/.env.local_llm.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# OPENAI or AZURE or OPENROUTER (ignored for Anthropic)
ENDPOINT=OPENAI

# OPENAI_ENDPOINT=https://api.openai.com/v1/chat/completions
OPENAI_ENDPOINT=http://127.0.0.1:8090/v1/chat/completions
OPENAI_API_KEY=sk-blabla-blabla

# In case of Azure/OpenRouter endpoint, change this to your deployed model name
MODEL_NAME=gpt-4-turbo-preview
# In case of Anthropic, use "anthropic/" + the model name, example for Claude 3 Opus
# MODEL_NAME=anthropic/claude-3-opus-20240229
MAX_TOKENS=8192

# Parameters for fin tuning local LLMs
TEMPERATURE=0.8
TOP_P=0.95
TOP_K=40
REPETITION_PENALTY=1.1
PRESENCE_PENALTY=0
FREQUENCY_PENALTY=0
# FOR GPTQ and ExLlama models
GUIDANCE_SCALE=1.8

API_CONNECT_TIMEOUT=30
API_READ_TIMEOUT=3000

# Folders which shouldn't be tracked in workspace (useful to ignore folders created by compiler)
# IGNORE_PATHS=folder1,folder2

# Database
# DATABASE_TYPE=postgres

DB_NAME=gpt-pilot
DB_HOST=
DB_PORT=
DB_USER=
DB_PASSWORD=

# USE_GPTPILOT_FOLDER=true

# Load database imported from another location/system - EXPERIMENTAL
# AUTOFIX_FILE_PATHS=false

# Set extra buffer to wait on top of detected retry time when rate limmit is hit. defaults to 6
# RATE_LIMIT_EXTRA_BUFFER=
4 changes: 2 additions & 2 deletions pilot/const/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
MIN_TOKENS_FOR_GPT_RESPONSE = 600
MAX_QUESTIONS = 5
END_RESPONSE = "EVERYTHING_CLEAR"
API_CONNECT_TIMEOUT = 30 # timeout for connecting to the API and sending the request (seconds)
API_READ_TIMEOUT = 300 # timeout for receiving the response (seconds)
API_CONNECT_TIMEOUT = int(os.getenv('API_CONNECT_TIMEOUT', 30)) # timeout for connecting to the API and sending the request (seconds)
API_READ_TIMEOUT = int(os.getenv('API_READ_TIMEOUT', 300)) # timeout for receiving the response (seconds)
8 changes: 6 additions & 2 deletions pilot/helpers/AgentConvo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
import subprocess
import uuid
import os
from os.path import sep

from utils.style import color_yellow, color_yellow_bold, color_red_bold
Expand All @@ -25,14 +26,17 @@ class AgentConvo:
agent: An instance of the agent participating in the conversation.
"""

def __init__(self, agent, temperature: float = 0.7):
def __init__(self, agent, temperature: float = -1):
# [{'role': 'system'|'user'|'assistant', 'content': ''}, ...]
self.messages: list[dict] = []
self.branches = {}
self.log_to_user = True
self.agent = agent
self.high_level_step = self.agent.project.current_step
self.temperature = temperature
if (temperature < 0.0):
self.temperature = float(os.getenv('TEMPERATURE', 0.7))
else:
self.temperature = temperature

# add system message
system_message = get_sys_message(self.agent.role, self.agent.project.args)
Expand Down
9 changes: 5 additions & 4 deletions pilot/helpers/agents/CodeMonkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,11 @@ def remove_backticks(content: str) -> str:
:param content: content to remove backticks from
:return: content without backticks
"""
start_pattern = re.compile(r"^\s*```([a-z0-9]+)?\n")
end_pattern = re.compile(r"\n```\s*$")
content = start_pattern.sub("", content)
content = end_pattern.sub("", content)
pattern = r"^.*```([a-z0-9]+)?\n(.*)?```.*$"
match = re.search(pattern, content, re.DOTALL)
if match:
code = match.group(2)
return code.strip()
return content

def identify_file_to_change(self, code_changes_description: str, files: list[dict]) -> str:
Expand Down
2 changes: 1 addition & 1 deletion pilot/prompts/development/parse_task.prompt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Examples:
"type": "command",
"command": {
"command": "mv ./index.js ./public/index.js"",
"timeout": "5000",
"timeout": 5000,
"success_message": "",
"command_id": "move_index_file"
}
Expand Down
14 changes: 12 additions & 2 deletions pilot/utils/function_calling.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ def add_function_calls_to_request(gpt_data, function_calls: Union[FunctionCallSe
'content': prompter.prompt('', function_calls['definitions'], function_call)
}
gpt_data['messages'].append(function_call_message)


gpt_data['response_format'] = {"type": "json_object"}

return function_call_message


Expand All @@ -71,7 +73,15 @@ def parse_agent_response(response, function_calls: Union[FunctionCallSet, None])
"""
if function_calls:
text = response['text']
return json.loads(text)
try:
return json.loads(text)
except:
pattern = r'```(.*)\n(.*?)```'
match = re.search(pattern, text, re.DOTALL)

if match:
code = match.group(1)
return json.loads(code.strip())

return response['text']

Expand Down