Skip to content

Commit 776aac1

Browse files
authored
Merge pull request #140 from GreyDGL/local-llm
Local llm
2 parents 90b4c4f + 85726d1 commit 776aac1

File tree

7 files changed

+45
-34
lines changed

7 files changed

+45
-34
lines changed

pentestgpt/test_connection.py

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,64 +33,62 @@ def main():
3333
chatgpt_config = ChatGPTConfig(api_base=args.baseUrl)
3434
console = Console()
3535

36-
# 1. test the connection for chatgpt cookie
37-
print("#### Test connection for chatgpt cookie")
38-
try:
39-
chatgpt = ChatGPT(chatgpt_config)
40-
conversations = chatgpt.get_conversation_history()
41-
if conversations is not None:
42-
console.print(
43-
"1. You're connected with ChatGPT Plus cookie. \nTo start PentestGPT, please use <pentestgpt --reasoning_model=gpt-4>",
44-
style="bold green",
45-
)
46-
else:
47-
console.print(
48-
"The cookie is not properly configured with ChatGPT Cookie. Please follow README to update cookie through `export CHATGPT_COOKIE=<your cookie>`",
49-
style="bold red",
50-
)
51-
except Exception as e: # use a general exception first. Update later for debug
52-
logger.error(e)
53-
print(
54-
"The cookie is not properly configured. Please follow README to update cookie in config/chatgpt_config.py"
55-
)
56-
57-
# 2. test the connection for chatgpt api with GPT-4
36+
# 1. test the connection for chatgpt api with GPT-4
5837
print("#### Test connection for OpenAI api (GPT-4)")
5938
try:
6039
chatgpt_config.model = "gpt-4"
6140
chatgpt = ChatGPTAPI(chatgpt_config)
6241
openai.api_key = chatgpt_config.openai_key
6342
result, conversation_id = chatgpt.send_new_message("Hi how are you?")
6443
console.print(
65-
"2. You're connected with OpenAI API. You have GPT-4 access. To start PentestGPT, please use <pentestgpt --reasoning_model=gpt-4 --useAPI>",
44+
"1. You're connected with OpenAI API. You have GPT-4 access. To start PentestGPT, please use <pentestgpt --reasoning_model=gpt-4>",
6645
style="bold green",
6746
)
6847
except Exception as e: # use a general exception first. Update later for debug
6948
console.print(
70-
"The OpenAI API key is not properly configured. Please follow README to update OpenAI API key through `export OPENAI_KEY=<>`.",
49+
"1. The OpenAI API key is not properly configured. Please follow README to update OpenAI API key through `export OPENAI_KEY=<>`.",
7150
style="bold red",
7251
)
7352
print("The error is below:", e)
7453

75-
# 3. test the connection for chatgpt api with GPT-3.5
54+
# 2. test the connection for chatgpt api with GPT-3.5
7655
print("#### Test connection for OpenAI api (GPT-3.5)")
7756
try:
78-
chatgpt_config.model = "gpt-3.5-turbo"
57+
chatgpt_config.model = "gpt-3.5-turbo-16k"
7958
chatgpt = ChatGPTAPI(chatgpt_config)
8059
openai.api_key = chatgpt_config.openai_key
8160
result, conversation_id = chatgpt.send_new_message("Hi how are you?")
8261
console.print(
83-
"3. You're connected with OpenAI API. You have GPT-3.5 access. To start PentestGPT, please use <pentestgpt --reasoning_model=gpt-3.5-turbo --useAPI>",
62+
"2. You're connected with OpenAI API. You have GPT-3.5 access. To start PentestGPT, please use <pentestgpt --reasoning_model=gpt-3.5-turbo-16k>",
8463
style="bold green",
8564
)
8665
except Exception as e: # use a general exception first. Update later for debug
8766
logger.error(e)
8867
console.print(
89-
"The OpenAI API key is not properly configured. Please follow README to update OpenAI API key through `export OPENAI_KEY=<>`",
68+
"2. The OpenAI API key is not properly configured. The likely reason is that you do not link a payment method to OpenAI so your key is not active. \nPlease follow README to update OpenAI API key through `export OPENAI_KEY=<>`",
9069
style="bold red",
9170
)
9271
print("The error is below:", e)
9372

73+
# 3. test the connection for chatgpt cookie (deprecated)
74+
print("#### Test connection for chatgpt cookie")
75+
try:
76+
chatgpt = ChatGPT(chatgpt_config)
77+
conversations = chatgpt.get_conversation_history()
78+
if conversations is not None:
79+
console.print(
80+
"3. You're connected with ChatGPT Plus cookie. \nTo start PentestGPT, please use <pentestgpt --reasoning_model=gpt-4>",
81+
style="bold green",
82+
)
83+
else:
84+
console.print(
85+
"3. The cookie is not properly configured with ChatGPT Cookie. If you're not using cookie bypass for testing, please neglect this message.",
86+
style="bold red",
87+
)
88+
except Exception as e: # use a general exception first. Update later for debug
89+
logger.error(e)
90+
print("The cookie is not properly configured.")
91+
9492

9593
if __name__ == "__main__":
9694
main()

pentestgpt/utils/APIs/chatgpt_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def __eq__(self, other):
4343

4444
class ChatGPTAPI(LLMAPI):
4545
def __init__(self, config_class):
46+
self.name = str(config_class.model)
4647
openai.api_key = os.getenv("OPENAI_KEY", None)
4748
openai.api_base = config_class.api_base
4849
self.model = config_class.model

pentestgpt/utils/APIs/gpt4all_api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def __eq__(self, other):
4545

4646
class GPT4ALLAPI(LLMAPI):
4747
def __init__(self, config_class):
48+
self.name = str(config_class.model)
4849
self.history_length = (
4950
2 # maintain 2 messages in the history due to gpt4all limitation.
5051
)
@@ -71,7 +72,7 @@ def _chat_completion(self, history: List) -> str:
7172

7273
if __name__ == "__main__":
7374
chatgpt_config = ChatGPTConfig()
74-
chatgpt = ChatGPTAPI()
75+
chatgpt = GPT4ALLAPI()
7576

7677
# test is below
7778
# 1. create a new conversation

pentestgpt/utils/APIs/module_import.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,14 @@ def dynamic_import(module_name, log_dir) -> object:
7070
return LLM_class_initialized
7171

7272
else:
73-
print("Module not found: " + module_name)
74-
return None
73+
print(
74+
"Module not found: "
75+
+ module_name
76+
+ ". Falling back to use the default gpt-3.5-turbo-16k"
77+
)
78+
# fall back to gpt-3.5-turbo-16k
79+
LLM_class_initialized = dynamic_import("gpt-3.5-turbo-16k", log_dir)
80+
return LLM_class_initialized
7581

7682

7783
if __name__ == "__main__":

pentestgpt/utils/llm_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def __eq__(self, other):
4545

4646
class LLMAPI:
4747
def __init__(self, config: ChatGPTConfig):
48+
self.name = "LLMAPI_base_class"
4849
self.config = config
4950
openai.api_key = config.openai_key
5051
openai.proxy = config.proxies

pentestgpt/utils/pentest_gpt.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,12 @@ def __init__(
9595
style="bold green",
9696
)
9797
self.console.print("The settings are: ")
98-
self.console.print(f" - parsing model: {parsing_model}", style="bold green")
99-
self.console.print(f" - reasoning model: {reasoning_model}", style="bold green")
98+
self.console.print(
99+
f" - parsing model: {parsing_model_object.name}", style="bold green"
100+
)
101+
self.console.print(
102+
f" - reasoning model: {reasoning_model_object.name}", style="bold green"
103+
)
100104
self.console.print(f" - use API: {useAPI}", style="bold green")
101105
self.console.print(f" - log directory: {log_dir}", style="bold green")
102106

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
setup(
99
name="pentestgpt",
10-
version="0.9.0",
10+
version="0.9.1",
1111
description="PentestGPT, a GPT-empowered penetration testing tool",
1212
long_description="""
1313
PentestGPT is a penetration testing tool empowered by ChatGPT.

0 commit comments

Comments
 (0)