OpenAI-Specific Parameters in ClientAI¶
This guide covers the OpenAI-specific parameters that can be passed to ClientAI's generate_text
and chat
methods. These parameters are passed as additional keyword arguments to customize OpenAI's behavior.
generate_text Method¶
Basic Structure¶
from clientai import ClientAI
client = ClientAI('openai', api_key="your-openai-api-key")
response = client.generate_text(
prompt="Your prompt here", # Required
model="gpt-3.5-turbo", # Required
frequency_penalty=0.5, # OpenAI-specific
presence_penalty=0.2, # OpenAI-specific
logit_bias={123: 100}, # OpenAI-specific
max_completion_tokens=100, # OpenAI-specific
response_format={"type": "json"}, # OpenAI-specific
seed=12345 # OpenAI-specific
)
OpenAI-Specific Parameters¶
frequency_penalty: Optional[float]
¶
- Range: -2.0 to 2.0
- Penalizes tokens based on their frequency in the text
presence_penalty: Optional[float]
¶
- Range: -2.0 to 2.0
- Penalizes tokens based on their presence in prior text
logit_bias: Optional[Dict[str, int]]
¶
- Maps token IDs to bias values (-100 to 100)
max_completion_tokens: Optional[int]
¶
- Maximum tokens for completion
response_format: ResponseFormat
¶
- Controls output structure
seed: Optional[int]
¶
- For deterministic generation (Beta)
user: str
¶
- Unique identifier for end-user tracking
chat Method¶
Basic Structure¶
response = client.chat(
model="gpt-3.5-turbo", # Required
messages=[...], # Required
tools=[...], # OpenAI-specific
tool_choice="auto", # OpenAI-specific
response_format={"type": "json"}, # OpenAI-specific
logprobs=True, # OpenAI-specific
top_logprobs=5 # OpenAI-specific
)
OpenAI-Specific Parameters¶
tools: Iterable[ChatCompletionToolParam]
¶
- List of available tools (max 128)
tool_choice: ChatCompletionToolChoiceOptionParam
¶
- Controls tool selection behavior
modalities: Optional[List[ChatCompletionModality]]
¶
- Output types for generation
audio: Optional[ChatCompletionAudioParam]
¶
- Audio output parameters
metadata: Optional[Dict[str, str]]
¶
- Custom tags for filtering
Complete Examples¶
Example 1: Structured Output with Tools¶
response = client.chat(
model="gpt-4",
messages=[
{"role": "system", "content": "You are a data assistant"},
{"role": "user", "content": "Get weather for Paris"}
],
response_format={"type": "json_object"},
tools=[{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get weather data",
"parameters": {
"type": "object",
"properties": {
"location": {"type": "string"}
}
}
}
}],
tool_choice="auto"
)
Example 2: Advanced Text Generation¶
response = client.generate_text(
prompt="Write a technical analysis",
model="gpt-4",
max_completion_tokens=500,
frequency_penalty=0.7,
presence_penalty=0.6,
logit_bias={123: 50},
user="analyst_1",
seed=42
)
Example 3: Audio Generation¶
response = client.chat(
model="gpt-4o-audio-preview",
messages=[{"role": "user", "content": "Explain quantum physics"}],
modalities=["text", "audio"],
audio={
"model": "tts-1",
"voice": "nova",
"speed": 1.0
},
metadata={"type": "educational"}
)
Parameter Validation Notes¶
- Both
model
andprompt
/messages
are required response_format
requires compatible models- Tool usage limited to 128 functions
- Audio generation requires specific models
logprobs
must be True when usingtop_logprobs
seed
feature is in Beta and not guaranteed
These parameters allow you to fully customize OpenAI's behavior while working with ClientAI's abstraction layer.