openai_gpt
langroid/language_models/openai_gpt.py
AnthropicModel
¶
Bases: str
, Enum
Enum for Anthropic models
OpenAIChatModel
¶
Bases: str
, Enum
Enum for OpenAI Chat models
GeminiModel
¶
Bases: str
, Enum
Enum for Gemini models
OpenAICompletionModel
¶
Bases: str
, Enum
Enum for OpenAI Completion models
OpenAICallParams
¶
Bases: BaseModel
Various params that can be sent to an OpenAI API chat-completion call. When specified, any param here overrides the one with same name in the OpenAIGPTConfig. See OpenAI API Reference for details on the params: https://platform.openai.com/docs/api-reference/chat
OpenAIGPTConfig(**kwargs)
¶
Bases: LLMConfig
Class for any LLM with an OpenAI-like API: besides the OpenAI models this includes: (a) locally-served models behind an OpenAI-compatible API (b) non-local models, using a proxy adaptor lib like litellm that provides an OpenAI-compatible API. We could rename this class to OpenAILikeConfig.
Source code in langroid/language_models/openai_gpt.py
create(prefix)
classmethod
¶
Create a config class whose params can be set via a desired prefix from the .env file or env vars. E.g., using
you can have a group of params prefixed by "OLLAMA_", to be used with models served viaollama
.
This way, you can maintain several setting-groups in your .env file,
one per model type.
Source code in langroid/language_models/openai_gpt.py
OpenAIResponse
¶
Bases: BaseModel
OpenAI response model, either completion or chat.
OpenAIGPT(config=OpenAIGPTConfig())
¶
Bases: LanguageModel
Class for OpenAI LLMs
Source code in langroid/language_models/openai_gpt.py
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 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 651 652 653 654 655 656 657 658 659 660 |
|
requires_first_user_message()
¶
Does the chat_model require a non-empty first user message? TODO: Add other models here; we know gemini requires a non-empty user message, after the system message.
Source code in langroid/language_models/openai_gpt.py
unsupported_params()
¶
List of params that are not supported by the current model
Source code in langroid/language_models/openai_gpt.py
rename_params()
¶
Map of param name -> new name for specific models. Currently main troublemaker is o1* series.
Source code in langroid/language_models/openai_gpt.py
chat_context_length()
¶
Context-length for chat-completion models/endpoints Get it from the dict, otherwise fail-over to general method
Source code in langroid/language_models/openai_gpt.py
completion_context_length()
¶
Context-length for completion models/endpoints Get it from the dict, otherwise fail-over to general method
Source code in langroid/language_models/openai_gpt.py
chat_cost()
¶
(Prompt, Generation) cost per 1000 tokens, for chat-completion models/endpoints. Get it from the dict, otherwise fail-over to general method
Source code in langroid/language_models/openai_gpt.py
set_stream(stream)
¶
Enable or disable streaming output from API. Args: stream: enable streaming output from API Returns: previous value of stream
Source code in langroid/language_models/openai_gpt.py
get_stream()
¶
Get streaming status. Note we disable streaming in quiet mode.
Source code in langroid/language_models/openai_gpt.py
tool_deltas_to_tools(tools)
staticmethod
¶
Convert accumulated tool-call deltas to OpenAIToolCall objects. Adapted from this excellent code: https://community.openai.com/t/help-for-function-calls-with-streaming/627170/2
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tools |
List[Dict[str, Any]]
|
list of tool deltas received from streaming API |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
plain text corresponding to tool calls that failed to parse |
List[OpenAIToolCall]
|
List[OpenAIToolCall]: list of OpenAIToolCall objects |
|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: list of tool dicts (to reconstruct OpenAI API response, so it can be cached) |
Source code in langroid/language_models/openai_gpt.py
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 |
|
noop()
¶
litellm_logging_fn(model_call_dict)
¶
Logging function for litellm