GroqChatTarget#
This example demonstrates how to use the GroqChatTarget
class in PyRIT to send a prompt
to a Groq model and retrieve a response.
Setup#
Before running this example, you need to set the following environment variables:
export GROQ_API_KEY="your_api_key_here"
export GROQ_MODEL_NAME="llama3-8b-8192"
Alternatively, you can pass these values as arguments when initializing GroqChatTarget
:
groq_target = GroqChatTarget(model_name="llama3-8b-8192", api_key="your_api_key_here")
You can also limit the request rate using max_requests_per_minute
.
Example#
The following code initializes GroqChatTarget
, sends a prompt using PromptSendingOrchestrator
,
and retrieves a response.
from pyrit.common import IN_MEMORY, initialize_pyrit
from pyrit.orchestrator import PromptSendingOrchestrator
from pyrit.prompt_target import GroqChatTarget
initialize_pyrit(memory_db_type=IN_MEMORY)
groq_target = GroqChatTarget()
prompt = "Why is the sky blue ?"
orchestrator = PromptSendingOrchestrator(objective_target=groq_target)
response = await orchestrator.send_prompts_async(prompt_list=[prompt]) # type: ignore
await orchestrator.print_conversations_async() # type: ignore
None of PyTorch, TensorFlow >= 2.0, or Flax have been found. Models won't be available and only tokenizers, configuration and file/data utilities can be used.
Conversation ID: 7ae4ae98-a23b-4330-9c3e-5fd9e8c37854
user: Why is the sky blue ?
assistant: The sky appears blue because of a phenomenon called Rayleigh scattering, which is the scattering of light by small particles or molecules in the atmosphere.
When sunlight enters Earth's atmosphere, it encounters tiny molecules of gases such as nitrogen (N2) and oxygen (O2). These molecules scatter the light in all directions, but they scatter shorter (blue) wavelengths more than longer (red) wavelengths. This is known as Rayleigh scattering.
As a result of this scattering, the blue light is dispersed throughout the atmosphere, reaching our eyes from all directions. This is why the sky appears blue during the daytime, as the blue light is being scattered in all directions and reaching our eyes from all parts of the sky.
In addition to Rayleigh scattering, there are other factors that can affect the color of the sky, such as:
* Mie scattering: This is the scattering of light by larger particles, such as dust, pollen, and water droplets. Mie scattering can give the sky a more orange or pinkish hue during sunrise and sunset.
* Scattering by cloud droplets: Clouds can scatter light in a way that gives the sky a more white or gray appearance.
* Atmospheric conditions: Factors such as pollution, dust, and water vapor can also affect the color of the sky, making it appear more hazy or brownish.
Overall, the combination of Rayleigh scattering and other atmospheric effects is what gives the sky its blue color during the daytime.