Skip to content

Commit

Permalink
(g4f/Provider/Blackbox.py) Removed prefixes that were not used
Browse files Browse the repository at this point in the history
  • Loading branch information
kqlio67 committed Dec 27, 2024
1 parent eebd075 commit de54f0c
Showing 1 changed file with 4 additions and 34 deletions.
38 changes: 4 additions & 34 deletions g4f/Provider/Blackbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,6 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
'builder Agent': {'mode': True, 'id': "builder Agent"},
}

additional_prefixes = {
'gpt-4o': '@GPT-4o',
'gemini-pro': '@Gemini-PRO',
'claude-sonnet-3.5': '@Claude-Sonnet-3.5'
}

model_prefixes = {
**{
mode: f"@{value['id']}" for mode, value in trendingAgentMode.items()
if mode not in ["gemini-1.5-flash", "llama-3.1-8b", "llama-3.1-70b", "llama-3.1-405b", "repomap"]
},
**additional_prefixes
}

models = list(dict.fromkeys([default_model, *userSelectedModel, *list(agentMode.keys()), *list(trendingAgentMode.keys())]))

model_aliases = {
Expand Down Expand Up @@ -141,7 +127,7 @@ def _load_cached_value(cls) -> str | None:
data = json.load(f)
return data.get('validated_value')
except Exception as e:
print(f"Error reading cache file: {e}")
debug.log(f"Error reading cache file: {e}")
return None

@classmethod
Expand All @@ -151,7 +137,7 @@ def _save_cached_value(cls, value: str):
with open(cache_file, 'w') as f:
json.dump({'validated_value': value}, f)
except Exception as e:
print(f"Error writing to cache file: {e}")
debug.log(f"Error writing to cache file: {e}")

@classmethod
async def fetch_validated(cls):
Expand Down Expand Up @@ -200,7 +186,7 @@ def is_valid_context(text_around):
continue

except Exception as e:
print(f"Error trying {base_url}: {e}")
debug.log(f"Error trying {base_url}: {e}")
continue

# If we failed to get a new validated_value, we return the cached one
Expand All @@ -214,21 +200,6 @@ def generate_id(length=7):
characters = string.ascii_letters + string.digits
return ''.join(random.choice(characters) for _ in range(length))

@classmethod
def add_prefix_to_messages(cls, messages: Messages, model: str) -> Messages:
prefix = cls.model_prefixes.get(model, "")
if not prefix:
return messages

new_messages = []
for message in messages:
new_message = message.copy()
if message['role'] == 'user':
new_message['content'] = (prefix + " " + message['content']).strip()
new_messages.append(new_message)

return new_messages

@classmethod
async def create_async_generator(
cls,
Expand Down Expand Up @@ -261,13 +232,12 @@ def run_search():
web_search = False

async def process_request():
messages_with_prefix = cls.add_prefix_to_messages(messages, model)
validated_value = await cls.fetch_validated()

if not validated_value:
raise RuntimeError("Failed to get validated value")

formatted_message = format_prompt(messages_with_prefix)
formatted_message = format_prompt(messages)
current_model = cls.get_model(model)

first_message = next((msg for msg in messages if msg['role'] == 'user'), None)
Expand Down

0 comments on commit de54f0c

Please sign in to comment.