Skip to content
This repository has been archived by the owner on Nov 13, 2024. It is now read-only.

Ignore additional params in chat completion #137

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/canopy_server/api_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ class ChatRequest(BaseModel):
stream: bool = False
user: Optional[str] = None

class Config:
extra = "ignore"


class ContextQueryRequest(BaseModel):
queries: List[Query]
Expand Down
29 changes: 28 additions & 1 deletion tests/e2e/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -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]
Expand Down