AI Generators
generators
¶
Assembly: Mappy
Filename: generators.py
Author: Terry D. Eppler
Created: 05-31-2022
Last Modified By: Terry D. Eppler
Last Modified On: 05-01-2025
generators.py
Copyright © 2022 Terry Eppler
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
You can contact me at: terryeppler@gmail.com or eppler.terry@epa.gov
Classes¶
Generator
¶
Base interface for provider-specific generation wrappers.
Purpose
Define the shared interface and common state used by provider-specific text-generation wrappers.
Attributes:
| Name | Type | Description |
|---|---|---|
timeout |
Optional[int]
|
Request timeout or generation timeout setting retained by subclasses. |
headers |
Optional[Dict[str, Any]]
|
HTTP headers or provider headers used by subclasses. |
response |
Optional[Response]
|
Raw response object returned by a provider request. |
url |
Optional[str]
|
Provider endpoint URL or request URL used by a fetch operation. |
result |
Optional[Result]
|
Normalized result container produced by a fetch operation. |
query |
Optional[str]
|
Prompt or query text used by the latest operation. |
Initialize the Generator wrapper.
Purpose
Initialize common base-generator state used by provider-specific subclasses.
Source code in generators.py
Methods:¶
fetch
¶
fetch(
query: str, url: str, time: int = 10
) -> Result | None
Fetch.
Purpose
Define the base fetch contract implemented by provider-specific generator classes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
User query or prompt text. |
required |
url
|
str
|
Request URL or image URL used by the operation. |
required |
time
|
int
|
Optional timeout or time value used by the provider call. |
10
|
Returns:
| Type | Description |
|---|---|
Result | None
|
Result | None: Provider output text or generated content when available. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Raised by the base interface until a subclass implements the method. |
Source code in generators.py
Grok
¶
Bases: Generator
xAI Grok text and web-search generation wrapper.
Purpose
Generate text and web-grounded responses through the xAI Responses API.
Attributes:
| Name | Type | Description |
|---|---|---|
api_key |
Optional[str]
|
xAI API key loaded from configuration. |
client |
Optional[Client]
|
xAI client used for Responses API calls. |
model |
Optional[str]
|
Model identifier selected for the latest request. |
query |
Optional[str]
|
User prompt submitted to the latest request. |
response |
Optional[Any]
|
Raw xAI response object. |
content |
Extracted response text returned to callers. |
|
tools |
Optional[List[Dict[str, Any]]]
|
Tool definitions sent to the Responses API. |
instructions |
Optional[List[Dict[str, Any]]]
|
System instructions sent to the Responses API. |
domains |
Optional[List[Dict[str, Any]]]
|
Optional web-search domain filters. |
Initialize the Grok wrapper.
Purpose
Initialize xAI client state, request defaults, model option lists, and runtime response fields.
Source code in generators.py
Methods:¶
normalize_domains
¶
Normalize domains.
Purpose
Normalize domain-filter input into a clean list of non-empty domain strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domains
|
Any
|
Domain-filter input supplied as a string, list, tuple, or set. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: Normalized value suitable for provider request construction. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
supports_reasoning_effort
¶
Supports reasoning effort.
Purpose
Determine whether the selected Grok model supports a reasoning-effort parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Provider model identifier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Provider capability flag or predicate result. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
supports_reasoning_object
¶
Supports reasoning object.
Purpose
Determine whether the selected Grok model accepts a reasoning object in the request payload.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Provider model identifier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Provider capability flag or predicate result. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
is_reasoning_model
¶
Is reasoning model.
Purpose
Determine whether the selected Grok model should be treated as a reasoning-capable model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Provider model identifier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Provider capability flag or predicate result. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
build_instructions
¶
Build instructions.
Purpose
Combine optional system text and response-format guidance into a provider instruction string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
str
|
Optional system instructions. |
None
|
response_format
|
str
|
Requested response format, such as text or JSON. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: Provider-specific request configuration or payload fragment. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
build_tools
¶
Build tools.
Purpose
Build xAI Responses API tool definitions for optional web search with optional domain filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
web_search
|
bool
|
Whether provider web search should be enabled. |
False
|
search_domains
|
Any
|
Optional domains used to constrain provider web search. |
None
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: Provider-specific request configuration or payload fragment. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
build_response_format
¶
Build response format.
Purpose
Build the xAI response-format payload for JSON or plain-text output requests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response_format
|
str
|
Requested response format, such as text or JSON. |
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any] | None
|
Dict[str, Any] | None: Provider-specific request configuration or payload fragment. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
extract_output_text
¶
Extract output text.
Purpose
Extract generated text from an xAI Responses API response using supported response shapes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
Any
|
Raw provider response object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Extracted generated text when available. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 | |
create_response
¶
Create response.
Purpose
Submit a fully prepared payload to the xAI Responses API and return extracted text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
payload
|
Dict[str, Any]
|
Prepared provider request payload. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Result produced by the operation. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
fetch
¶
fetch(
query: str,
model: str = "grok-4-fast-reasoning",
temperature: float = 0.7,
max_tokens: int = 2048,
top_p: float = 1.0,
seed: int | None = None,
system: str = None,
response_format: str = None,
reasoning_effort: str = None,
web_search: bool = False,
search_domains: Any = None,
stop: List[str] = None,
stream: bool = False,
store: bool = True,
parallel_tool_calls: bool = True,
tool_choice: str = "auto",
) -> str | None
Fetch.
Purpose
Build and submit an xAI Responses API request for text generation, optional reasoning, optional JSON output, and optional web search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
User query or prompt text. |
required |
model
|
str
|
Provider model identifier. |
'grok-4-fast-reasoning'
|
temperature
|
float
|
Sampling temperature. |
0.7
|
max_tokens
|
int
|
Maximum output-token count. |
2048
|
top_p
|
float
|
Nucleus sampling value. |
1.0
|
seed
|
int | None
|
Optional deterministic seed. |
None
|
system
|
str
|
Optional system instructions. |
None
|
response_format
|
str
|
Requested response format, such as text or JSON. |
None
|
reasoning_effort
|
str
|
Requested reasoning-effort level. |
None
|
web_search
|
bool
|
Whether provider web search should be enabled. |
False
|
search_domains
|
Any
|
Optional domains used to constrain provider web search. |
None
|
stop
|
List[str]
|
Optional stop sequences. |
None
|
stream
|
bool
|
Whether streaming output should be requested. |
False
|
store
|
bool
|
Whether the provider should store the response server-side. |
True
|
parallel_tool_calls
|
bool
|
Whether parallel tool calls are allowed. |
True
|
tool_choice
|
str
|
Tool-choice behavior sent to the provider. |
'auto'
|
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: Provider output text or generated content when available. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 | |
generate_text
¶
generate_text(
query: str,
model: str = "grok-4-fast-reasoning",
temperature: float = 0.7,
max_tokens: int = 2048,
top_p: float = 1.0,
seed: int | None = None,
system: str = None,
response_format: str = None,
reasoning_effort: str = None,
web_search: bool = False,
search_domains: Any = None,
stop: List[str] = None,
stream: bool = False,
store: bool = True,
parallel_tool_calls: bool = True,
tool_choice: str = "auto",
) -> str | None
Generate text.
Purpose
Generate text with Grok by delegating to the full fetch workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
User query or prompt text. |
required |
model
|
str
|
Provider model identifier. |
'grok-4-fast-reasoning'
|
temperature
|
float
|
Sampling temperature. |
0.7
|
max_tokens
|
int
|
Maximum output-token count. |
2048
|
top_p
|
float
|
Nucleus sampling value. |
1.0
|
seed
|
int | None
|
Optional deterministic seed. |
None
|
system
|
str
|
Optional system instructions. |
None
|
response_format
|
str
|
Requested response format, such as text or JSON. |
None
|
reasoning_effort
|
str
|
Requested reasoning-effort level. |
None
|
web_search
|
bool
|
Whether provider web search should be enabled. |
False
|
search_domains
|
Any
|
Optional domains used to constrain provider web search. |
None
|
stop
|
List[str]
|
Optional stop sequences. |
None
|
stream
|
bool
|
Whether streaming output should be requested. |
False
|
store
|
bool
|
Whether the provider should store the response server-side. |
True
|
parallel_tool_calls
|
bool
|
Whether parallel tool calls are allowed. |
True
|
tool_choice
|
str
|
Tool-choice behavior sent to the provider. |
'auto'
|
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: Provider output text or generated content when available. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
search_web
¶
search_web(
query: str,
model: str = "grok-4-fast-reasoning",
temperature: float = 0.7,
max_tokens: int = 2048,
top_p: float = 1.0,
seed: int | None = None,
system: str = None,
response_format: str = None,
reasoning_effort: str = None,
search_domains: Any = None,
stream: bool = False,
store: bool = True,
parallel_tool_calls: bool = True,
tool_choice: str = "auto",
) -> str | None
Search web.
Purpose
Generate a web-grounded Grok answer by enabling the xAI web-search tool path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
User query or prompt text. |
required |
model
|
str
|
Provider model identifier. |
'grok-4-fast-reasoning'
|
temperature
|
float
|
Sampling temperature. |
0.7
|
max_tokens
|
int
|
Maximum output-token count. |
2048
|
top_p
|
float
|
Nucleus sampling value. |
1.0
|
seed
|
int | None
|
Optional deterministic seed. |
None
|
system
|
str
|
Optional system instructions. |
None
|
response_format
|
str
|
Requested response format, such as text or JSON. |
None
|
reasoning_effort
|
str
|
Requested reasoning-effort level. |
None
|
search_domains
|
Any
|
Optional domains used to constrain provider web search. |
None
|
stream
|
bool
|
Whether streaming output should be requested. |
False
|
store
|
bool
|
Whether the provider should store the response server-side. |
True
|
parallel_tool_calls
|
bool
|
Whether parallel tool calls are allowed. |
True
|
tool_choice
|
str
|
Tool-choice behavior sent to the provider. |
'auto'
|
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: Provider output text or generated content when available. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
Gemini
¶
Bases: Generator
Google Gemini text, grounding, and structured-output wrapper.
Purpose
Generate text, grounded answers, and structured outputs through the Google Gemini API.
Attributes:
| Name | Type | Description |
|---|---|---|
api_key |
Optional[str]
|
Google Gemini API key loaded from configuration. |
client |
Optional[Any]
|
Gemini client used for model calls. |
model |
Optional[str]
|
Model identifier selected for the latest request. |
prompt |
Optional[str]
|
Prompt submitted to the latest request. |
response |
Optional[Any]
|
Raw Gemini response object. |
content |
Optional[Any]
|
Extracted response text returned to callers. |
config |
Optional[Any]
|
Generation configuration sent to Gemini. |
tools |
Optional[List[Any]]
|
Optional grounding tools sent to Gemini. |
domains |
Optional[List[Any]]
|
Optional search-domain filters used in grounded requests. |
Initialize the Gemini wrapper.
Purpose
Initialize Gemini client state, option lists, request defaults, and runtime response fields.
Source code in generators.py
Methods:¶
normalize_domains
¶
Normalize domains.
Purpose
Normalize search-domain filters into a clean list of non-empty domain strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domains
|
Any
|
Domain-filter input supplied as a string, list, tuple, or set. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: Normalized value suitable for provider request construction. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
normalize_stop_sequences
¶
Normalize stop sequences.
Purpose
Normalize stop-sequence input into a clean list suitable for Gemini generation configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
stop_sequences
|
Any
|
Optional stop sequences. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: Normalized value suitable for provider request construction. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
supports_thinking_level
¶
Supports thinking level.
Purpose
Determine whether the selected Gemini model supports named thinking-level controls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Provider model identifier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Provider capability flag or predicate result. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
supports_thinking_budget
¶
Supports thinking budget.
Purpose
Determine whether the selected Gemini model supports explicit thinking-budget controls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Provider model identifier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Provider capability flag or predicate result. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
build_system_instruction
¶
build_system_instruction(
system: str = None,
response_format: str = None,
grounding: bool = False,
search_domains: Any = None,
) -> str | None
Build system instruction.
Purpose
Build Gemini system instructions from optional system text, response-format guidance, grounding guidance, and domain filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
str
|
Optional system instructions. |
None
|
response_format
|
str
|
Requested response format, such as text or JSON. |
None
|
grounding
|
bool
|
Whether Gemini grounding should be enabled. |
False
|
search_domains
|
Any
|
Optional domains used to constrain provider web search. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: Provider-specific request configuration or payload fragment. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
build_thinking_config
¶
build_thinking_config(
model: str,
reasoning: bool = False,
thinking_level: str = None,
thinking_budget: int | None = None,
include_thoughts: bool = False,
) -> Any
Build thinking config.
Purpose
Build Gemini thinking configuration for supported reasoning models and requested thinking controls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Provider model identifier. |
required |
reasoning
|
bool
|
Whether reasoning or thinking controls should be enabled. |
False
|
thinking_level
|
str
|
Requested Gemini thinking-level label. |
None
|
thinking_budget
|
int | None
|
Optional token budget for thinking-capable models. |
None
|
include_thoughts
|
bool
|
Whether Gemini should include thought summaries when supported. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Provider-specific request configuration or payload fragment. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 | |
build_tools
¶
Build tools.
Purpose
Build Gemini tool configuration for grounded search when grounding is enabled.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grounding
|
bool
|
Whether Gemini grounding should be enabled. |
False
|
Returns:
| Type | Description |
|---|---|
List[Any]
|
List[Any]: Provider-specific request configuration or payload fragment. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
build_config
¶
build_config(
model: str,
temperature: float = 0.7,
max_tokens: int = 2048,
top_p: float = 1.0,
top_k: int | None = None,
candidate_count: int = 1,
seed: int | None = None,
system: str = None,
response_format: str = None,
stop_sequences: Any = None,
grounding: bool = False,
search_domains: Any = None,
reasoning: bool = False,
thinking_level: str = None,
thinking_budget: int | None = None,
include_thoughts: bool = False,
response_json_schema: Dict[str, Any] = None,
) -> Any
Build config.
Purpose
Build the Gemini generation configuration from sampling, response-format, grounding, and thinking options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Provider model identifier. |
required |
temperature
|
float
|
Sampling temperature. |
0.7
|
max_tokens
|
int
|
Maximum output-token count. |
2048
|
top_p
|
float
|
Nucleus sampling value. |
1.0
|
top_k
|
int | None
|
Top-k sampling value. |
None
|
candidate_count
|
int
|
Number of Gemini candidates to request. |
1
|
seed
|
int | None
|
Optional deterministic seed. |
None
|
system
|
str
|
Optional system instructions. |
None
|
response_format
|
str
|
Requested response format, such as text or JSON. |
None
|
stop_sequences
|
Any
|
Optional stop sequences. |
None
|
grounding
|
bool
|
Whether Gemini grounding should be enabled. |
False
|
search_domains
|
Any
|
Optional domains used to constrain provider web search. |
None
|
reasoning
|
bool
|
Whether reasoning or thinking controls should be enabled. |
False
|
thinking_level
|
str
|
Requested Gemini thinking-level label. |
None
|
thinking_budget
|
int | None
|
Optional token budget for thinking-capable models. |
None
|
include_thoughts
|
bool
|
Whether Gemini should include thought summaries when supported. |
False
|
response_json_schema
|
Dict[str, Any]
|
Optional JSON schema for structured responses. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Provider-specific request configuration or payload fragment. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 | |
extract_text
¶
Extract text.
Purpose
Extract generated text from Gemini response objects across supported response shapes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
Any
|
Raw provider response object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Extracted generated text when available. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
fetch
¶
fetch(
prompt: str,
model: str = "gemini-2.5-flash",
temperature: float = 0.7,
max_tokens: int = 2048,
top_p: float = 1.0,
top_k: int | None = None,
candidate_count: int = 1,
seed: int | None = None,
system: str = None,
response_format: str = None,
stop_sequences: Any = None,
grounding: bool = False,
search_domains: Any = None,
reasoning: bool = False,
thinking_level: str = None,
thinking_budget: int | None = None,
include_thoughts: bool = False,
response_json_schema: Dict[str, Any] = None,
) -> str | None
Fetch.
Purpose
Build and submit a Gemini generation request with optional grounding, structured output, stop sequences, and thinking controls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
User prompt text. |
required |
model
|
str
|
Provider model identifier. |
'gemini-2.5-flash'
|
temperature
|
float
|
Sampling temperature. |
0.7
|
max_tokens
|
int
|
Maximum output-token count. |
2048
|
top_p
|
float
|
Nucleus sampling value. |
1.0
|
top_k
|
int | None
|
Top-k sampling value. |
None
|
candidate_count
|
int
|
Number of Gemini candidates to request. |
1
|
seed
|
int | None
|
Optional deterministic seed. |
None
|
system
|
str
|
Optional system instructions. |
None
|
response_format
|
str
|
Requested response format, such as text or JSON. |
None
|
stop_sequences
|
Any
|
Optional stop sequences. |
None
|
grounding
|
bool
|
Whether Gemini grounding should be enabled. |
False
|
search_domains
|
Any
|
Optional domains used to constrain provider web search. |
None
|
reasoning
|
bool
|
Whether reasoning or thinking controls should be enabled. |
False
|
thinking_level
|
str
|
Requested Gemini thinking-level label. |
None
|
thinking_budget
|
int | None
|
Optional token budget for thinking-capable models. |
None
|
include_thoughts
|
bool
|
Whether Gemini should include thought summaries when supported. |
False
|
response_json_schema
|
Dict[str, Any]
|
Optional JSON schema for structured responses. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: Provider output text or generated content when available. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 | |
generate_text
¶
generate_text(
prompt: str,
model: str = "gemini-2.5-flash",
temperature: float = 0.7,
max_tokens: int = 2048,
top_p: float = 1.0,
top_k: int | None = None,
candidate_count: int = 1,
seed: int | None = None,
system: str = None,
response_format: str = None,
stop_sequences: Any = None,
grounding: bool = False,
search_domains: Any = None,
reasoning: bool = False,
thinking_level: str = None,
thinking_budget: int | None = None,
include_thoughts: bool = False,
response_json_schema: Dict[str, Any] = None,
) -> str | None
Generate text.
Purpose
Generate text with Gemini by delegating to the full fetch workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
User prompt text. |
required |
model
|
str
|
Provider model identifier. |
'gemini-2.5-flash'
|
temperature
|
float
|
Sampling temperature. |
0.7
|
max_tokens
|
int
|
Maximum output-token count. |
2048
|
top_p
|
float
|
Nucleus sampling value. |
1.0
|
top_k
|
int | None
|
Top-k sampling value. |
None
|
candidate_count
|
int
|
Number of Gemini candidates to request. |
1
|
seed
|
int | None
|
Optional deterministic seed. |
None
|
system
|
str
|
Optional system instructions. |
None
|
response_format
|
str
|
Requested response format, such as text or JSON. |
None
|
stop_sequences
|
Any
|
Optional stop sequences. |
None
|
grounding
|
bool
|
Whether Gemini grounding should be enabled. |
False
|
search_domains
|
Any
|
Optional domains used to constrain provider web search. |
None
|
reasoning
|
bool
|
Whether reasoning or thinking controls should be enabled. |
False
|
thinking_level
|
str
|
Requested Gemini thinking-level label. |
None
|
thinking_budget
|
int | None
|
Optional token budget for thinking-capable models. |
None
|
include_thoughts
|
bool
|
Whether Gemini should include thought summaries when supported. |
False
|
response_json_schema
|
Dict[str, Any]
|
Optional JSON schema for structured responses. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: Provider output text or generated content when available. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
search_web
¶
search_web(
prompt: str,
model: str = "gemini-2.5-flash",
temperature: float = 0.7,
max_tokens: int = 2048,
top_p: float = 1.0,
top_k: int | None = None,
candidate_count: int = 1,
seed: int | None = None,
system: str = None,
response_format: str = None,
stop_sequences: Any = None,
search_domains: Any = None,
reasoning: bool = False,
thinking_level: str = None,
thinking_budget: int | None = None,
include_thoughts: bool = False,
response_json_schema: Dict[str, Any] = None,
) -> str | None
Search web.
Purpose
Generate a Gemini answer with grounding enabled and optional domain-filter guidance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
User prompt text. |
required |
model
|
str
|
Provider model identifier. |
'gemini-2.5-flash'
|
temperature
|
float
|
Sampling temperature. |
0.7
|
max_tokens
|
int
|
Maximum output-token count. |
2048
|
top_p
|
float
|
Nucleus sampling value. |
1.0
|
top_k
|
int | None
|
Top-k sampling value. |
None
|
candidate_count
|
int
|
Number of Gemini candidates to request. |
1
|
seed
|
int | None
|
Optional deterministic seed. |
None
|
system
|
str
|
Optional system instructions. |
None
|
response_format
|
str
|
Requested response format, such as text or JSON. |
None
|
stop_sequences
|
Any
|
Optional stop sequences. |
None
|
search_domains
|
Any
|
Optional domains used to constrain provider web search. |
None
|
reasoning
|
bool
|
Whether reasoning or thinking controls should be enabled. |
False
|
thinking_level
|
str
|
Requested Gemini thinking-level label. |
None
|
thinking_budget
|
int | None
|
Optional token budget for thinking-capable models. |
None
|
include_thoughts
|
bool
|
Whether Gemini should include thought summaries when supported. |
False
|
response_json_schema
|
Dict[str, Any]
|
Optional JSON schema for structured responses. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: Provider output text or generated content when available. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
Claude
¶
Bases: Generator
Anthropic Claude text and web-search generation wrapper.
Purpose
Generate text and web-search-enabled responses through the Anthropic Claude Messages API.
Attributes:
| Name | Type | Description |
|---|---|---|
api_key |
Optional[str]
|
Anthropic API key loaded from configuration. |
client |
Optional[Anthropic]
|
Anthropic client used for Messages API calls. |
model |
Optional[str]
|
Model identifier selected for the latest request. |
query |
Optional[str]
|
User prompt submitted to the latest request. |
response |
Optional[Any]
|
Raw Claude response object. |
content |
Extracted response text returned to callers. |
|
tools |
Tool definitions used for web search when enabled. |
|
domains |
Optional allowed or blocked web-search domains. |
Initialize the Claude wrapper.
Purpose
Initialize Anthropic client state, model options, request defaults, and runtime response fields.
Source code in generators.py
Methods:¶
fetch
¶
fetch(
query: str,
model: str = "claude-sonnet-4-6",
temperature: float = 0.7,
max_tokens: int = 2048,
top_p: float = 1.0,
top_k: int | None = None,
system: str = None,
stop_sequences: List[str] = None,
thinking: bool = False,
thinking_budget: int | None = None,
web_search: bool = False,
search_domains: Any = None,
blocked_domains: Any = None,
) -> str | None
Fetch.
Purpose
Build and submit a Claude Messages API request with optional thinking, stop sequences, and web-search tools.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
User query or prompt text. |
required |
model
|
str
|
Provider model identifier. |
'claude-sonnet-4-6'
|
temperature
|
float
|
Sampling temperature. |
0.7
|
max_tokens
|
int
|
Maximum output-token count. |
2048
|
top_p
|
float
|
Nucleus sampling value. |
1.0
|
top_k
|
int | None
|
Top-k sampling value. |
None
|
system
|
str
|
Optional system instructions. |
None
|
stop_sequences
|
List[str]
|
Optional stop sequences. |
None
|
thinking
|
bool
|
Whether Claude thinking controls should be enabled. |
False
|
thinking_budget
|
int | None
|
Optional token budget for thinking-capable models. |
None
|
web_search
|
bool
|
Whether provider web search should be enabled. |
False
|
search_domains
|
Any
|
Optional domains used to constrain provider web search. |
None
|
blocked_domains
|
Any
|
Optional domains excluded from provider web search. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: Provider output text or generated content when available. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 | |
generate_text
¶
generate_text(
query: str,
model: str = "claude-sonnet-4-6",
temperature: float = 0.7,
max_tokens: int = 2048,
top_p: float = 1.0,
top_k: int | None = None,
system: str = None,
stop_sequences: List[str] = None,
thinking: bool = False,
thinking_budget: int | None = None,
web_search: bool = False,
search_domains: Any = None,
blocked_domains: Any = None,
) -> str | None
Generate text.
Purpose
Generate text with Claude by delegating to the full fetch workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
User query or prompt text. |
required |
model
|
str
|
Provider model identifier. |
'claude-sonnet-4-6'
|
temperature
|
float
|
Sampling temperature. |
0.7
|
max_tokens
|
int
|
Maximum output-token count. |
2048
|
top_p
|
float
|
Nucleus sampling value. |
1.0
|
top_k
|
int | None
|
Top-k sampling value. |
None
|
system
|
str
|
Optional system instructions. |
None
|
stop_sequences
|
List[str]
|
Optional stop sequences. |
None
|
thinking
|
bool
|
Whether Claude thinking controls should be enabled. |
False
|
thinking_budget
|
int | None
|
Optional token budget for thinking-capable models. |
None
|
web_search
|
bool
|
Whether provider web search should be enabled. |
False
|
search_domains
|
Any
|
Optional domains used to constrain provider web search. |
None
|
blocked_domains
|
Any
|
Optional domains excluded from provider web search. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: Provider output text or generated content when available. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
search_web
¶
search_web(
query: str,
model: str = "claude-sonnet-4-6",
temperature: float = 0.7,
max_tokens: int = 2048,
top_p: float = 1.0,
top_k: int | None = None,
system: str = None,
stop_sequences: List[str] = None,
thinking: bool = False,
thinking_budget: int | None = None,
search_domains: Any = None,
blocked_domains: Any = None,
) -> str | None
Search web.
Purpose
Generate a Claude answer with Anthropic web search enabled and optional domain controls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
User query or prompt text. |
required |
model
|
str
|
Provider model identifier. |
'claude-sonnet-4-6'
|
temperature
|
float
|
Sampling temperature. |
0.7
|
max_tokens
|
int
|
Maximum output-token count. |
2048
|
top_p
|
float
|
Nucleus sampling value. |
1.0
|
top_k
|
int | None
|
Top-k sampling value. |
None
|
system
|
str
|
Optional system instructions. |
None
|
stop_sequences
|
List[str]
|
Optional stop sequences. |
None
|
thinking
|
bool
|
Whether Claude thinking controls should be enabled. |
False
|
thinking_budget
|
int | None
|
Optional token budget for thinking-capable models. |
None
|
search_domains
|
Any
|
Optional domains used to constrain provider web search. |
None
|
blocked_domains
|
Any
|
Optional domains excluded from provider web search. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: Provider output text or generated content when available. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
Mistral
¶
Bases: Generator
Mistral text-generation and schema-building wrapper.
Purpose
Generate text and tool-schema payloads through the Mistral chat completion API.
Attributes:
| Name | Type | Description |
|---|---|---|
api_key |
Optional[str]
|
Mistral API key loaded from configuration. |
client |
Optional[Mistral]
|
Mistral client used for chat completion requests. |
model |
Optional[str]
|
Model identifier selected for the latest request. |
query |
Optional[str]
|
User prompt submitted to the latest request. |
response |
Optional[Any]
|
Raw Mistral response object. |
content |
Extracted response text returned to callers. |
|
schema |
Last generated tool schema payload. |
Initialize the Mistral wrapper.
Purpose
Initialize Mistral client state, model options, request defaults, and runtime response fields.
Source code in generators.py
Methods:¶
fetch
¶
fetch(
query: str,
model: str = "mistral-large-latest",
temperature: float = 0.7,
max_tokens: int = 1024,
top_p: float = 1.0,
seed: int | None = None,
safe_mode: bool = False,
system: str = None,
) -> str | None
Fetch.
Purpose
Build and submit a Mistral chat-completion request using sampling, seed, safe-mode, and system options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
User query or prompt text. |
required |
model
|
str
|
Provider model identifier. |
'mistral-large-latest'
|
temperature
|
float
|
Sampling temperature. |
0.7
|
max_tokens
|
int
|
Maximum output-token count. |
1024
|
top_p
|
float
|
Nucleus sampling value. |
1.0
|
seed
|
int | None
|
Optional deterministic seed. |
None
|
safe_mode
|
bool
|
Whether Mistral safe-mode behavior should be enabled. |
False
|
system
|
str
|
Optional system instructions. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: Provider output text or generated content when available. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 | |
create_schema
¶
create_schema(
function: str,
tool: str,
description: str,
parameters: dict,
required: list[str],
) -> Dict[str, str] | None
Create schema.
Purpose
Build a JSON-compatible tool schema dictionary from a function name, tool label, description, parameters, and required fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
function
|
str
|
Function name exposed in the generated tool schema. |
required |
tool
|
str
|
Tool or service label associated with the generated schema. |
required |
description
|
str
|
Human-readable description for the generated schema. |
required |
parameters
|
dict
|
JSON-schema parameter definitions. |
required |
required
|
list[str]
|
Optional list of required parameter names. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, str] | None
|
Dict[str, str] | None: JSON-compatible tool schema dictionary. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
Chat
¶
Chat(
num: int = 1,
temp: float = 0.8,
top: float = 0.9,
freq: float = 0.0,
pres: float = 0.0,
iters: int = 10000,
store: bool = True,
stream: bool = True,
)
Bases: Generator
OpenAI Responses API generation wrapper.
Purpose
Generate OpenAI Responses API text, image-analysis, document-summary, search, and utility outputs.
Attributes:
| Name | Type | Description |
|---|---|---|
api_key |
Optional[str]
|
OpenAI API key loaded from configuration. |
client |
Optional[OpenAI]
|
OpenAI client used for Responses API calls. |
prompt |
Optional[OpenAI]
|
Prompt submitted to the latest request. |
model |
Optional[str]
|
Model identifier selected for the latest request. |
response |
Optional[Any]
|
Raw OpenAI response object. |
content |
Optional[Any]
|
Extracted response text returned to callers. |
tools |
Optional[List[Dict[str, Any]]]
|
Tool definitions sent to the Responses API. |
instructions |
Optional[List[Dict[str, Any]]]
|
System instructions sent to the Responses API. |
format |
Optional[List[Dict[str, Any]]]
|
Text or structured-output format used by the latest request. |
Initialize the Chat wrapper.
Purpose
Initialize OpenAI Responses API defaults, option lists, request state, and runtime output fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
int
|
Default response count retained for compatibility. |
1
|
temp
|
float
|
Default sampling temperature. |
0.8
|
top
|
float
|
Default top-p value. |
0.9
|
freq
|
float
|
Default frequency-penalty value. |
0.0
|
pres
|
float
|
Default presence-penalty value. |
0.0
|
iters
|
int
|
Default maximum output-token count. |
10000
|
store
|
bool
|
Whether the provider should store the response server-side. |
True
|
stream
|
bool
|
Whether streaming output should be requested. |
True
|
Source code in generators.py
Methods:¶
normalize_domains
¶
Normalize domains.
Purpose
Normalize web-search domain filters into a clean list of non-empty domain strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domains
|
Any
|
Domain-filter input supplied as a string, list, tuple, or set. |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: Normalized value suitable for provider request construction. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 | |
supports_reasoning
¶
Supports reasoning.
Purpose
Determine whether the selected OpenAI model supports reasoning-effort controls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Provider model identifier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
Provider capability flag or predicate result. |
Source code in generators.py
build_instructions
¶
build_instructions(
system: str = None,
response_format: str = None,
web_search: bool = False,
search_domains: Any = None,
) -> str | None
Build instructions.
Purpose
Build OpenAI Responses API instructions from system text, response-format guidance, and web-search guidance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
str
|
Optional system instructions. |
None
|
response_format
|
str
|
Requested response format, such as text or JSON. |
None
|
web_search
|
bool
|
Whether provider web search should be enabled. |
False
|
search_domains
|
Any
|
Optional domains used to constrain provider web search. |
None
|
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: Provider-specific request configuration or payload fragment. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
build_text_format
¶
build_text_format(
response_format: str | Dict[str, Any] = None,
json_schema: Dict[str, Any] = None,
schema_name: str = "structured_response",
schema_description: str = "Structured JSON response.",
) -> Dict[str, Any] | None
Build text format.
Purpose
Build OpenAI Responses API text-format configuration for plain text, JSON object, or JSON schema outputs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response_format
|
str | Dict[str, Any]
|
Requested response format, such as text or JSON. |
None
|
json_schema
|
Dict[str, Any]
|
Optional JSON schema definition for structured output. |
None
|
schema_name
|
str
|
Name assigned to the JSON schema response format. |
'structured_response'
|
schema_description
|
str
|
Description assigned to the JSON schema response format. |
'Structured JSON response.'
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any] | None
|
Dict[str, Any] | None: Provider-specific request configuration or payload fragment. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
build_tools
¶
build_tools(
web_search: bool = False,
search_domains: Any = None,
file_search: bool = False,
vector_store_ids: List[str] = None,
max_file_results: int = 20,
) -> List[Dict[str, Any]]
Build tools.
Purpose
Build OpenAI Responses API tool definitions for web search and file search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
web_search
|
bool
|
Whether provider web search should be enabled. |
False
|
search_domains
|
Any
|
Optional domains used to constrain provider web search. |
None
|
file_search
|
bool
|
Whether OpenAI file search should be enabled. |
False
|
vector_store_ids
|
List[str]
|
Vector store identifiers used by OpenAI file search. |
None
|
max_file_results
|
int
|
Maximum number of file-search results to return. |
20
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: Provider-specific request configuration or payload fragment. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
extract_output_text
¶
Extract output text.
Purpose
Extract generated text from OpenAI Responses API objects across supported response shapes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
response
|
Any
|
Raw provider response object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Extracted generated text when available. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 | |
fetch
¶
fetch(
prompt: str,
model: str = "gpt-5-mini",
temperature: float = 0.7,
max_tokens: int = 1024,
top_p: float = 1.0,
seed: int | None = None,
system: str = None,
response_format: str | Dict[str, Any] = None,
reasoning_effort: str = None,
web_search: bool = False,
search_domains: Any = None,
store: bool = True,
stream: bool = False,
parallel_tool_calls: bool = True,
tool_choice: str = "auto",
json_schema: Dict[str, Any] = None,
schema_name: str = "structured_response",
schema_description: str = "Structured JSON response.",
) -> str
Fetch.
Purpose
Build and submit an OpenAI Responses API request with optional reasoning, structured output, web search, and tool settings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
User prompt text. |
required |
model
|
str
|
Provider model identifier. |
'gpt-5-mini'
|
temperature
|
float
|
Sampling temperature. |
0.7
|
max_tokens
|
int
|
Maximum output-token count. |
1024
|
top_p
|
float
|
Nucleus sampling value. |
1.0
|
seed
|
int | None
|
Optional deterministic seed. |
None
|
system
|
str
|
Optional system instructions. |
None
|
response_format
|
str | Dict[str, Any]
|
Requested response format, such as text or JSON. |
None
|
reasoning_effort
|
str
|
Requested reasoning-effort level. |
None
|
web_search
|
bool
|
Whether provider web search should be enabled. |
False
|
search_domains
|
Any
|
Optional domains used to constrain provider web search. |
None
|
store
|
bool
|
Whether the provider should store the response server-side. |
True
|
stream
|
bool
|
Whether streaming output should be requested. |
False
|
parallel_tool_calls
|
bool
|
Whether parallel tool calls are allowed. |
True
|
tool_choice
|
str
|
Tool-choice behavior sent to the provider. |
'auto'
|
json_schema
|
Dict[str, Any]
|
Optional JSON schema definition for structured output. |
None
|
schema_name
|
str
|
Name assigned to the JSON schema response format. |
'structured_response'
|
schema_description
|
str
|
Description assigned to the JSON schema response format. |
'Structured JSON response.'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Provider output text or generated content when available. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 | |
generate_text
¶
generate_text(
prompt: str,
model: str = "gpt-5-mini",
temperature: float = 0.7,
max_tokens: int = 1024,
top_p: float = 1.0,
seed: int | None = None,
system: str = None,
response_format: str | Dict[str, Any] = None,
reasoning_effort: str = None,
web_search: bool = False,
search_domains: Any = None,
store: bool = True,
stream: bool = False,
parallel_tool_calls: bool = True,
tool_choice: str = "auto",
json_schema: Dict[str, Any] = None,
) -> str
Generate text.
Purpose
Generate text with OpenAI by delegating to the full fetch workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
User prompt text. |
required |
model
|
str
|
Provider model identifier. |
'gpt-5-mini'
|
temperature
|
float
|
Sampling temperature. |
0.7
|
max_tokens
|
int
|
Maximum output-token count. |
1024
|
top_p
|
float
|
Nucleus sampling value. |
1.0
|
seed
|
int | None
|
Optional deterministic seed. |
None
|
system
|
str
|
Optional system instructions. |
None
|
response_format
|
str | Dict[str, Any]
|
Requested response format, such as text or JSON. |
None
|
reasoning_effort
|
str
|
Requested reasoning-effort level. |
None
|
web_search
|
bool
|
Whether provider web search should be enabled. |
False
|
search_domains
|
Any
|
Optional domains used to constrain provider web search. |
None
|
store
|
bool
|
Whether the provider should store the response server-side. |
True
|
stream
|
bool
|
Whether streaming output should be requested. |
False
|
parallel_tool_calls
|
bool
|
Whether parallel tool calls are allowed. |
True
|
tool_choice
|
str
|
Tool-choice behavior sent to the provider. |
'auto'
|
json_schema
|
Dict[str, Any]
|
Optional JSON schema definition for structured output. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Provider output text or generated content when available. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
generate_image
¶
Generate image.
Purpose
Generate an image from a prompt using the configured OpenAI image workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
User prompt text. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Provider output text or generated content when available. |
Source code in generators.py
analyze_image
¶
Analyze image.
Purpose
Analyze an image URL with a multimodal OpenAI request and return the generated description or answer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
User prompt text. |
required |
url
|
str
|
Request URL or image URL used by the operation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Provider output text or generated content when available. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
summarize_document
¶
Summarize document.
Purpose
Read a document from disk and summarize it with the OpenAI text-generation workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
User prompt text. |
required |
path
|
str
|
Filesystem path used by the operation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Provider output text or generated content when available. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
search_web
¶
search_web(
prompt: str,
model: str = "gpt-5-mini",
temperature: float = 0.7,
max_tokens: int = 1024,
top_p: float = 1.0,
seed: int | None = None,
system: str = None,
response_format: str | Dict[str, Any] = None,
reasoning_effort: str = None,
search_domains: Any = None,
store: bool = True,
stream: bool = False,
parallel_tool_calls: bool = True,
tool_choice: str = "auto",
) -> str
Search web.
Purpose
Generate an OpenAI answer with web search enabled and optional domain filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
User prompt text. |
required |
model
|
str
|
Provider model identifier. |
'gpt-5-mini'
|
temperature
|
float
|
Sampling temperature. |
0.7
|
max_tokens
|
int
|
Maximum output-token count. |
1024
|
top_p
|
float
|
Nucleus sampling value. |
1.0
|
seed
|
int | None
|
Optional deterministic seed. |
None
|
system
|
str
|
Optional system instructions. |
None
|
response_format
|
str | Dict[str, Any]
|
Requested response format, such as text or JSON. |
None
|
reasoning_effort
|
str
|
Requested reasoning-effort level. |
None
|
search_domains
|
Any
|
Optional domains used to constrain provider web search. |
None
|
store
|
bool
|
Whether the provider should store the response server-side. |
True
|
stream
|
bool
|
Whether streaming output should be requested. |
False
|
parallel_tool_calls
|
bool
|
Whether parallel tool calls are allowed. |
True
|
tool_choice
|
str
|
Tool-choice behavior sent to the provider. |
'auto'
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Provider output text or generated content when available. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
search_files
¶
Search files.
Purpose
Run a file-search-oriented OpenAI prompt using the configured file-search workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
User prompt text. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Provider output text or generated content when available. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
translate
¶
Translate.
Purpose
Translate text by delegating to the OpenAI generation workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text value processed by the utility method. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Provider output text or generated content when available. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
transcribe
¶
Transcribe.
Purpose
Transcribe text-like input by delegating to the OpenAI generation workflow retained by the application.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Text value processed by the utility method. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Provider output text or generated content when available. |
Source code in generators.py
get_format_options
¶
Get format options.
Purpose
Return supported response-format option labels for UI controls and callers.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: Option list or state dictionary requested by the caller. |
Source code in generators.py
get_model_options
¶
Get model options.
Purpose
Return supported OpenAI model option labels for UI controls and callers.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: Option list or state dictionary requested by the caller. |
Source code in generators.py
get_effort_options
¶
Get effort options.
Purpose
Return supported reasoning-effort option labels for UI controls and callers.
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: Option list or state dictionary requested by the caller. |
Source code in generators.py
get_data
¶
Get data.
Purpose
Return the latest request and response state as a serializable dictionary.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: Option list or state dictionary requested by the caller. |
Raises:
| Type | Description |
|---|---|
Error
|
Raised after wrapping and logging provider, validation, or response-processing failures. |
Source code in generators.py
dump
¶
Dump.
Purpose
Return a compact diagnostic snapshot of the current Chat generator state.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Diagnostic state snapshot. |
Source code in generators.py
Functions:¶
throw_if
¶
Validate a required runtime value.
Purpose
Validate that a required generator value is present before provider logic uses it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the value being validated. |
required |
value
|
Any
|
Runtime value to validate. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
Raised when the supplied value is missing. |
Source code in generators.py
encode_image
¶
Encode an image file as base64 text.
Purpose
Read an image file and return its base64-encoded string representation for multimodal request payloads.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Filesystem path used by the operation. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Base64-encoded image content. |