-
Notifications
You must be signed in to change notification settings - Fork 0
SGP Inference #71
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
base: main
Are you sure you want to change the base?
SGP Inference #71
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 |
|---|---|---|
|
|
@@ -39,10 +39,16 @@ async def handle_message_send( | |
| if params.content.author != "user": | ||
| raise ValueError(f"Expected user message, got {params.content.author}") | ||
|
|
||
| if not os.environ.get("OPENAI_API_KEY"): | ||
| if not os.environ.get("SGP_API_KEY"): | ||
| return TextContent( | ||
| author="agent", | ||
| content="Hey, sorry I'm unable to respond to your message because you're running this example without an OpenAI API key. Please set the OPENAI_API_KEY environment variable to run this example. Do this by either by adding a .env file to the project/ directory or by setting the environment variable in your terminal.", | ||
| content="Hey, sorry I'm unable to respond to your message because you're running this example without an SGP API key. Please set the SGP_API_KEY environment variable to run this example. Do this by either by adding a .env file to the project/ directory or by setting the environment variable in your terminal.", | ||
| ) | ||
|
|
||
| if not os.environ.get("SGP_ACCOUNT_ID"): | ||
| return TextContent( | ||
| author="agent", | ||
| content="Hey, sorry I'm unable to respond to your message because you're running this example without an SGP Account ID. Please set the SGP_ACCOUNT_ID environment variable to run this example. Do this by either by adding a .env file to the project/ directory or by setting the environment variable in your terminal.", | ||
| ) | ||
|
|
||
| ######################################################### | ||
|
|
@@ -54,7 +60,7 @@ async def handle_message_send( | |
|
|
||
| if not task_state: | ||
| # If the state doesn't exist, create it. | ||
| state = StateModel(system_prompt="You are a helpful assistant that can answer questions.", model="gpt-4o-mini") | ||
| state = StateModel(system_prompt="You are a helpful assistant that can answer questions.", model="openai/gpt-4o-mini") | ||
| task_state = await adk.state.create(task_id=params.task.id, agent_id=params.agent.id, state=state) | ||
| else: | ||
| state = StateModel.model_validate(task_state.state) | ||
|
|
@@ -96,7 +102,7 @@ async def handle_message_send( | |
| ######################################################### | ||
|
|
||
| # Call an LLM to respond to the user's message | ||
| chat_completion = await adk.providers.litellm.chat_completion( | ||
|
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. Nit for the future: Is the goal for each of these providers to be drop in replacements for each other? If so, for the future, would you want to consider some type of "LLMProviderInterface" spec that these providers adhere to? And then have a |
||
| chat_completion = await adk.providers.sgp.chat_completion( | ||
| llm_config=LLMConfig(model=state.model, messages=llm_messages), | ||
| trace_id=params.task.id, | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,10 +11,14 @@ | |
|
|
||
|
|
||
| class SGPLLMGateway(LLMGateway): | ||
| def __init__(self, sgp_api_key: str | None = None): | ||
| self.sync_client = SGPClient(api_key=os.environ.get("SGP_API_KEY", sgp_api_key)) | ||
| def __init__(self, sgp_api_key: str | None = None, sgp_account_id: str | None = None): | ||
| self.sync_client = SGPClient( | ||
|
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.
|
||
| api_key=os.environ.get("SGP_API_KEY", sgp_api_key), | ||
| account_id=os.environ.get("SGP_ACCOUNT_ID", sgp_account_id) | ||
| ) | ||
| self.async_client = AsyncSGPClient( | ||
| api_key=os.environ.get("SGP_API_KEY", sgp_api_key) | ||
| api_key=os.environ.get("SGP_API_KEY", sgp_api_key), | ||
| account_id=os.environ.get("SGP_ACCOUNT_ID", sgp_account_id) | ||
| ) | ||
|
|
||
| def completion(self, *args, **kwargs) -> Completion: | ||
|
|
||
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.
Do we need these checks here or will the SGPClient already raise SGPClientError exceptions when these keys are missing? Just wondering b/c it adds a lot of boilerplate to each project. Are you trying to protect against error message propagation issues?