Skip to content

Conversation

@OhYee
Copy link
Contributor

@OhYee OhYee commented Dec 2, 2025

Change-Id: Idf3ecad27a33902fc017c9392e314b252944c7ab

Thank you for creating a pull request to contribute to Serverless Devs agentrun-sdk-python code! Before you open the request please answer the following questions to help it be more easily integrated. Please check the boxes "[ ]" with "[x]" when done too.
Please select one of the PR types below to complete


Fix bugs

Bug detail

模型服务在配置凭证情况下,未正确获取 api key

Pull request tasks

  • Add test cases for the changes
  • Passed the CI test

Update docs

Reason for update

Why do you need to update your documentation?

Pull request tasks

  • Update Chinese documentation
  • Update English documentation

Add contributor

Contributed content

  • Code
  • Document

Content detail

if content_type == 'code' || content_type == 'document':
    please tell us `PR url`,like: https://github.com/Serverless-Devs/agentrun-sdk-python/pull/1
else:
    please describe your contribution in detail

Others

Reason for update

Why do you need to update your documentation?

Copilot AI review requested due to automatic review settings December 2, 2025 02:47
Copilot finished reviewing on behalf of OhYee December 2, 2025 02:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where model services were not correctly retrieving API keys when credentials were configured. The fix adds logic to fetch the API key from the associated credential when it's not directly provided in the provider settings.

  • Added credential-based API key retrieval in model_info() method
  • Added comprehensive test coverage for model services using credentials (both sync and async)
  • Removed unused ClientError import from test files

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
agentrun/model/model_service.py Added logic to retrieve API key from credential when not set in provider settings
agentrun/model/__model_service_async_template.py Added same credential-based API key retrieval logic for async template
tests/e2e/test_model.py Added sync and async test cases for model services with credentials; removed unused import
tests/e2e/__test_model_async_template.py Added async test case for model services with credentials; removed unused import

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 276 to 285
cr = Credential.create(
CredentialCreateInput(
credential_name=f"{model_service_name}-credential",
enabled=True,
credential_config=CredentialConfig.outbound_llm_api_key(
api_key=api_key,
provider="openai",
),
)
)
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In an async test method, Credential.create() should be replaced with await Credential.create_async() to maintain consistency with the async pattern used elsewhere in the test (e.g., await ModelService.create_async(), await ms.delete_async(), await cr.delete_async()). Using synchronous calls in async methods can lead to blocking behavior and defeats the purpose of async testing.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot open a new pull request to apply changes based on this feedback

@OhYee OhYee force-pushed the fix-model-service-with-credential branch 3 times, most recently from 2e9e2cb to 765650b Compare December 2, 2025 03:15
Copy link
Contributor

Copilot AI commented Dec 2, 2025

@OhYee I've opened a new pull request, #6, to work on those changes. Once the pull request is ready, I'll request review from you.

Change-Id: Ib6831f5a3978b3a47843c3c9f22c1b63c2255c32
Signed-off-by: OhYee <oyohyee@oyohyee.com>
@OhYee OhYee force-pushed the fix-model-service-with-credential branch from be7573c to 4f3b53d Compare December 2, 2025 03:21
@OhYee OhYee requested a review from Copilot December 2, 2025 03:23
Copilot finished reviewing on behalf of OhYee December 2, 2025 03:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Sodawyx Sodawyx merged commit 53e3b69 into main Dec 2, 2025
7 checks passed
@OhYee OhYee deleted the fix-model-service-with-credential branch December 5, 2025 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants