-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for API key configuration in LiteLLM #2178
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,4 +1,5 @@ | ||||||||||||||
import json | ||||||||||||||
import os | ||||||||||||||
from typing import Dict, List, Optional | ||||||||||||||
|
||||||||||||||
try: | ||||||||||||||
|
@@ -16,7 +17,8 @@ def __init__(self, config: Optional[BaseLlmConfig] = None): | |||||||||||||
|
||||||||||||||
if not self.config.model: | ||||||||||||||
self.config.model = "gpt-4o-mini" | ||||||||||||||
|
||||||||||||||
if not self.config.api_key: | ||||||||||||||
self.config.api_key = os.environ["OPENAI_API_KEY"] | ||||||||||||||
Comment on lines
+20
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing error handling when 📝 Committable Code Suggestion
Suggested change
|
||||||||||||||
def _parse_response(self, response, tools): | ||||||||||||||
""" | ||||||||||||||
Process the response based on whether tools are used or not. | ||||||||||||||
|
@@ -75,6 +77,7 @@ def generate_response( | |||||||||||||
"temperature": self.config.temperature, | ||||||||||||||
"max_tokens": self.config.max_tokens, | ||||||||||||||
"top_p": self.config.top_p, | ||||||||||||||
"api_key": self.config.api_key, | ||||||||||||||
} | ||||||||||||||
if response_format: | ||||||||||||||
params["response_format"] = response_format | ||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing error handling when
OPENAI_API_KEY
environment variable is not set. This will cause an uncaughtKeyError
exception when the API key is not configured.📝 Committable Code Suggestion