Skip to content

test chat completions api in e2e case #868

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

delavet
Copy link
Contributor

@delavet delavet commented May 23, 2025

Adds /chat/completions API e2e test case.

Fixes: #814

Copy link

netlify bot commented May 23, 2025

Deploy Preview for gateway-api-inference-extension ready!

Name Link
🔨 Latest commit f88626f
🔍 Latest deploy log https://app.netlify.com/projects/gateway-api-inference-extension/deploys/683ad511985e8c000886176d
😎 Deploy Preview https://deploy-preview-868--gateway-api-inference-extension.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label May 23, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: delavet
Once this PR has been reviewed and has the lgtm label, please assign arangogutierrez for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot requested review from liu-cong and robscott May 23, 2025 02:34
@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label May 23, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @delavet. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 23, 2025
@nirrozenbaum
Copy link
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 23, 2025
Copy link
Contributor

@nirrozenbaum nirrozenbaum left a comment

Choose a reason for hiding this comment

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

@delavet does it make sense to separate different tests into different ginkgo.It statements?
I'd expect moving some parts to the BeforeEach section, e.g., this part:

ginkgo.By("Creating an InferenceModel resource")
infModel := newInferenceModel(nsName)	
gomega.Expect(cli.Create(ctx, infModel)).To(gomega.Succeed())	

ginkgo.By("Ensuring the InferenceModel resource exists in the namespace")
gomega.Eventually(func() error {
	return cli.Get(ctx, types.NamespacedName{Namespace: infModel.Namespace, Name: infModel.Name}, infModel)	}, 
existsTimeout, interval).Should(gomega.Succeed())

I'd also expect creating some helper functions to extract the common code.
I think the e2e tests should include (each in a different ginkgo.It statement):

  • completions with prompt
  • chat completions with a single [role, message].
  • chat completions with multiple [role, message] entries.

@delavet
Copy link
Contributor Author

delavet commented May 28, 2025

@delavet does it make sense to separate different tests into different ginkgo.It statements? I'd expect moving some parts to the BeforeEach section, e.g., this part:

ginkgo.By("Creating an InferenceModel resource")
infModel := newInferenceModel(nsName)	
gomega.Expect(cli.Create(ctx, infModel)).To(gomega.Succeed())	

ginkgo.By("Ensuring the InferenceModel resource exists in the namespace")
gomega.Eventually(func() error {
	return cli.Get(ctx, types.NamespacedName{Namespace: infModel.Namespace, Name: infModel.Name}, infModel)	}, 
existsTimeout, interval).Should(gomega.Succeed())

I'd also expect creating some helper functions to extract the common code. I think the e2e tests should include (each in a different ginkgo.It statement):

  • completions with prompt
  • chat completions with a single [role, message].
  • chat completions with multiple [role, message] entries.

This does make more sense! I will try refactoring this ASAP.

@@ -55,38 +55,40 @@ var _ = ginkgo.Describe("InferencePool", func() {
}, existsTimeout, interval).Should(gomega.Succeed())

ginkgo.By("Verifying connectivity through the inference extension")
curlCmd := getCurlCommand(envoyName, nsName, envoyPort, modelName, curlTimeout)
for _, testApi := range []string{"/completions", "/chat/completions"} {
Copy link
Contributor

@danehans danehans May 30, 2025

Choose a reason for hiding this comment

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

@delavet does it make sense to separate different tests into different ginkgo.It statements?

Another option is to move the ginkgo.By() statement within the range and include the name of the API endpoint so a user can see that each endpoint is being tested?

case "/chat/completions":
command = append(command,
"-d",
fmt.Sprintf(`{"model": "%s", "messages": [{"role": "user", "content": "Hello! Please introduce yourself"}], "max_tokens": 100, "temperature": 0}`, model))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you have both cases use the same "Write as if you were a critic: San Francisco" prompt?

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 31, 2025
@delavet
Copy link
Contributor Author

delavet commented May 31, 2025

@nirrozenbaum @danehans I have refined this PR, and now the e2e tests include coverage for both /completion and /chat/completions. The tests for /chat/completions encompass two scenarios: single-turn chat and multi-turn chat. For the single-turn chat, the same prompt used in /completion, "Write as if you were a critic: San Francisco," is applied. Regarding the organization of the tests, I finally decided to use a single It block that contains multiple By blocks through a loop. This approach appears more semantically coherent.

@delavet delavet requested review from nirrozenbaum and danehans May 31, 2025 10:16
@danehans
Copy link
Contributor

danehans commented Jun 2, 2025

@delavet CI is failing due to #901. Please rebase to include #902.

@nirrozenbaum
Copy link
Contributor

/retest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

e2e: Add /chat/completions Test Case
4 participants