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

Commit

Permalink
Merge pull request #137 from pinecone-io/allow-additional-param-chat-…
Browse files Browse the repository at this point in the history
…completion

Ignore additional params in chat completion
  • Loading branch information
acatav authored Nov 5, 2023
2 parents 2d460d0 + 4969144 commit b90769d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
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

0 comments on commit b90769d

Please sign in to comment.