From 49691447c267175892b1d57b08f5bd8dcfcf7e6a Mon Sep 17 00:00:00 2001 From: Amnon Catav Date: Thu, 2 Nov 2023 12:22:50 +0200 Subject: [PATCH] ignore additioanl params in chat completion --- src/canopy_server/api_models.py | 3 +++ tests/e2e/test_app.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/canopy_server/api_models.py b/src/canopy_server/api_models.py index dae422f5..b0d61673 100644 --- a/src/canopy_server/api_models.py +++ b/src/canopy_server/api_models.py @@ -11,6 +11,9 @@ class ChatRequest(BaseModel): stream: bool = False user: Optional[str] = None + class Config: + extra = "ignore" + class ContextQueryRequest(BaseModel): queries: List[Query] diff --git a/tests/e2e/test_app.py b/tests/e2e/test_app.py index 6d067695..41357f4a 100644 --- a/tests/e2e/test_app.py +++ b/tests/e2e/test_app.py @@ -128,7 +128,7 @@ def test_query(client): upsert_payload.dict()["documents"][0]["source"]) -def test_chat(client): +def test_chat_required_params(client): # test response is as expected on /chat chat_payload = { "messages": [ @@ -149,6 +149,33 @@ def test_chat(client): assert all([kw in chat_response_content for kw in ["red", "bananas"]]) +def test_chat_openai_additional_params(client): + chat_payload = { + "messages": [ + { + "role": "user", + "content": "what is the topic of the test document? be concise", + } + ], + "user": "test-user", + "model": "gpt-4", + "temperature": 0.5, + "max_tokens": 10, + "logit_bias": {12: 10, 13: 11}, + "n": 2, + "stop": "stop string", + "top_p": 0.5, + } + chat_response = client.post("/context/chat/completions", json=chat_payload) + assert chat_response.is_success + chat_response_as_json = chat_response.json() + assert chat_response_as_json["choices"][0]["message"]["role"] == "assistant" + chat_response_content = chat_response_as_json["choices"][0]["message"][ + "content" + ] + assert all([kw in chat_response_content for kw in ["red", "bananas"]]) + + def test_delete(client, knowledge_base): doc_ids = ["api_tests-1"] vector_ids = [f"{d_id}_{0}" for d_id in doc_ids]