Introduce a custom system role #130
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR focuses on addressing two open issues by introducing a custom system role:
Initially, there are no apparent issues with either
litellmor Groq. However, this flexible approach will address both concerns.snippet.pyThe code was initially intended to function with a hardcoded system role. However, some LLMs require customization. This PR introduces a new
custom_roleparameter to address the above issues. Then, usingcustom_role=usershould solve these issues.Below are some notes and snippets to help refresh my memory whenever I revisit this code. They also provide newcomers with an overview of the underlying processes:
additional notes and snippets
The
py-zeroxlibrary is designed to interact with LLMs via API, using thelitellmlibrary to ensure everything runs smoothly. Before jumping into action,py-zeroxperforms a couple of important checks usinglitellmmethods:model validation
The
validate_model(self)method useslitellm.supports_vision(model=self.model)to confirm that the model is indeed a vision model. Essentially,litellmchecks a comprehensive JSON map with detailed information on various LLM options to ensure compatibility.snippets
({ # https://docs.python.org/3/library/logging.html#logging-levels # https://github.com/BerriAI/litellm/blob/ea8f0913c2aac4a7b4ec53585cfe9ea04a3282de/litellm/_logging.py#L11 export LITELLM_LOG=CRITICAL output=$(python3 <<EOF import litellm # # https://github.com/BerriAI/litellm/blob/11932d0576a073d83f38a418cbdf6b2d8d4ff46f/litellm/litellm_core_utils/get_llm_provider_logic.py#L322 litellm.suppress_debug_info = True # https://docs.litellm.ai/docs/debugging/local_debugging#set-verbose litellm.set_verbose=False model = "bedrock/amazon.nova-pro-v1:0" model = "bedrock/anthropic.claude-3-haiku-20240307-v1:0" model = "bedrock/amazon.nova-lite-v1:0" model = "groq/llama-3.2-11b-vision-preview" isVisionModel = litellm.supports_vision(model) print("Does %s supports visual? %s" % (model, isVisionModel)) EOF ) echo $output })access validation
The
validate_access(self)method useslitellm.check_valid_key(model=self.model, api_key=None)to verify access to the model. This check ensures that environment variables are correctly set with proper values.In short,
litellmperforms a simple API request to the given LLM. If any issues arise, it simply returnsFalse. Otherwise, it returns aTruefor a successful outcome.snippets
({ # https://docs.python.org/3/library/logging.html#logging-levels # https://github.com/BerriAI/litellm/blob/ea8f0913c2aac4a7b4ec53585cfe9ea04a3282de/litellm/_logging.py#L11 export LITELLM_LOG=DEBUG export GROQ_API_KEY="xxxxxxxxxxxxxxxx" output=$(python3 <<EOF import litellm # # https://github.com/BerriAI/litellm/blob/11932d0576a073d83f38a418cbdf6b2d8d4ff46f/litellm/litellm_core_utils/get_llm_provider_logic.py#L322 litellm.suppress_debug_info = False # https://docs.litellm.ai/docs/debugging/local_debugging#set-verbose litellm.set_verbose=True model = "bedrock/amazon.nova-pro-v1:0" model = "bedrock/anthropic.claude-3-haiku-20240307-v1:0" model = "bedrock/amazon.nova-lite-v1:0" model = "groq/llama-3.2-11b-vision-preview" isAllSet = litellm.check_valid_key(model,api_key=None) print("Does %s have everything set? %s" % (model, isAllSet)) EOF ) echo $output })Once these checks are completed,
py-zeroxbegins using thelitellmto convert PDFs into markdown format.Thanks!