Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,38 @@ Integration tests default to using ollama, to avoid cost and leaking sensitive i
However, unit test recordings should use the authoritative OpenAI platform unless the test is
about a specific portability corner case.

To refresh a test, delete its cassette file in tests/cassettes and make sure you have the
following environment variables set for OpenAI recordings:
To refresh a test, delete its cassette file in tests/cassettes and make sure you have environment
variables set for recordings, detailed later.

If writing a new test, start with the test logic with no assertions. If extending an existing unit test
rather than writing a new one, remove the corresponding recorded response from [cassettes](./tests/cassettes/)
instead.

Then, run `pytest` as normal. It will execute a request against the LLM and record it. Update the
test with correct assertions until it passes. Following executions of `pytest` will use the recorded
response without querying the LLM.

### OpenAI Environment Variables

* `OPENAI_API_KEY` - from https://platform.openai.com/settings/profile?tab=api-keys
* It should look like `sk-...`

and the following for Azure recordings, deployment url and api key are available for each deployment
in https://oai.azure.com/resource/deployments:
### Azure OpenAI Environment Variables

Azure is different from OpenAI primarily in that a URL has an implicit model. This means it ignores
the model parameter set by the OpenAI SDK. The implication is that one endpoint cannot serve both
chat and embeddings at the same time. Hence, we need separate environment variables for chat and
embeddings. In either case, the `DEPLOYMENT_URL` is the "Endpoint Target URI" and the `API_KEY` is
the `Endpoint Key` for a corresponding deployment in https://oai.azure.com/resource/deployments

* `AZURE_CHAT_COMPLETIONS_DEPLOYMENT_URL`
* It should look like https://endpoint.com/openai/deployments/my-deployment/chat/completions?api-version=2023-05-15
* `AZURE_CHAT_COMPLETIONS_API_KEY`
* It should be in hex like `abc01...` and possibly the same as `AZURE_EMBEDDINGS_API_KEY`
* `AZURE_EMBEDDINGS_DEPLOYMENT_URL`
* It should look like https://endpoint.com/openai/deployments/my-deployment/embeddings?api-version=2023-05-15
* `AZURE_EMBEDDINGS_API_KEY`

If writing a new test, start with the test logic with no assertions. If extending an existing unit test
rather than writing a new one, remove the corresponding recorded response from [cassettes](./tests/cassettes/)
instead.

Then, run `pytest` as normal. It will execute a request against the LLM and record it. Update the
test with correct assertions until it passes. Following executions of `pytest` will use the recorded
response without querying the LLM.
* It should be in hex like `abc01...` and possibly the same as `AZURE_CHAT_COMPLETIONS_API_KEY`

## License

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
interactions:
- request:
body: '{"messages": [{"role": "user", "content": "Answer in up to 3 words: Which
ocean contains the falkland islands?"}], "model": "gpt-4o-mini", "frequency_penalty":
0, "max_tokens": 100, "presence_penalty": 0, "stop": "foo", "temperature": 1,
"top_p": 1}'
body: |-
{
"messages": [
{
"role": "user",
"content": "Answer in up to 3 words: Which ocean contains the falkland islands?"
}
],
"model": "unused",
"frequency_penalty": 0,
"max_tokens": 100,
"presence_penalty": 0,
"stop": "foo",
"temperature": 1,
"top_p": 1
}
headers:
accept:
- application/json
Expand All @@ -16,70 +28,133 @@ interactions:
connection:
- keep-alive
content-length:
- '249'
- '244'
content-type:
- application/json
host:
- test.openai.azure.com
user-agent:
- AzureOpenAI/Python 1.50.0
- AzureOpenAI/Python 1.54.3
x-stainless-arch:
- x64
- arm64
x-stainless-async:
- 'false'
x-stainless-lang:
- python
x-stainless-os:
- Linux
- MacOS
x-stainless-package-version:
- 1.50.0
- 1.54.3
x-stainless-retry-count:
- '0'
x-stainless-runtime:
- CPython
x-stainless-runtime-version:
- 3.10.12
- 3.12.6
method: POST
uri: https://test.openai.azure.com/openai/deployments/test-azure-deployment/chat/completions?api-version=2023-03-15-preview
uri: https://test.openai.azure.com/openai/deployments/test-azure-deployment/chat/completions?api-version=2024-08-01-preview
response:
body:
string: '{"choices":[{"finish_reason":"stop","index":0,"message":{"content":"South
Atlantic Ocean.","role":"assistant"}}],"created":1727962531,"id":"chatcmpl-AEGHLLqYkgJxUgLgX8RCLeL85irQR","model":"gpt-4o-mini","object":"chat.completion","system_fingerprint":"fp_878413d04d","usage":{"completion_tokens":4,"prompt_tokens":24,"total_tokens":28}}

'
string: |-
{
"choices": [
{
"content_filter_results": {
"hate": {
"filtered": false,
"severity": "safe"
},
"self_harm": {
"filtered": false,
"severity": "safe"
},
"sexual": {
"filtered": false,
"severity": "safe"
},
"violence": {
"filtered": false,
"severity": "safe"
}
},
"finish_reason": "stop",
"index": 0,
"logprobs": null,
"message": {
"content": "Atlantic Ocean",
"role": "assistant"
}
}
],
"created": 1731466203,
"id": "chatcmpl-ASxkBZGOa53uXX1Ciygl77IrF8PbB",
"model": "gpt-4-32k",
"object": "chat.completion",
"prompt_filter_results": [
{
"prompt_index": 0,
"content_filter_results": {
"hate": {
"filtered": false,
"severity": "safe"
},
"self_harm": {
"filtered": false,
"severity": "safe"
},
"sexual": {
"filtered": false,
"severity": "safe"
},
"violence": {
"filtered": false,
"severity": "safe"
}
}
}
],
"system_fingerprint": null,
"usage": {
"completion_tokens": 2,
"prompt_tokens": 24,
"total_tokens": 26
}
}
headers:
Cache-Control:
- no-cache, must-revalidate
Content-Length:
- '336'
- '805'
Content-Type:
- application/json
Date:
- Thu, 03 Oct 2024 13:35:31 GMT
- Wed, 13 Nov 2024 02:50:02 GMT
Set-Cookie: test_set_cookie
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
access-control-allow-origin:
- '*'
apim-request-id:
- c017b850-54f6-40dd-9505-d1a9ee9a45b5
- f0e5ae5b-b609-4908-bedb-533ec71e9bfa
azureml-model-session:
- d009-20240925074800
openai-organization: test_openai_org_key
- d156-20241010120317
openai-organization: test_openai_org_id
x-accel-buffering:
- 'no'
x-content-type-options:
- nosniff
x-envoy-upstream-service-time:
- '249'
x-ms-client-request-id:
- c017b850-54f6-40dd-9505-d1a9ee9a45b5
- f0e5ae5b-b609-4908-bedb-533ec71e9bfa
x-ms-rai-invoked:
- 'true'
x-ms-region:
- East US
- Switzerland North
x-ratelimit-remaining-requests:
- '909'
- '78'
x-ratelimit-remaining-tokens:
- '90883'
- '79884'
x-request-id:
- fba991b8-1a4f-4c6e-8a53-8b826a61a78a
- 3a1ee803-cce9-472f-ad04-2d0757009288
status:
code: 200
message: OK
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
interactions:
- request:
body: '{"messages": [{"role": "user", "content": "Answer in up to 3 words: Which
ocean contains the falkland islands?"}], "model": "qwen2.5:0.5b", "frequency_penalty":
0, "max_completion_tokens": 100, "presence_penalty": 0, "stop": "foo", "temperature":
1, "top_p": 1}'
body: |-
{
"messages": [
{
"role": "user",
"content": "Answer in up to 3 words: Which ocean contains the falkland islands?"
}
],
"model": "qwen2.5:0.5b",
"frequency_penalty": 0,
"max_tokens": 100,
"presence_penalty": 0,
"stop": "foo",
"temperature": 1,
"top_p": 1
}
headers:
accept:
- application/json
Expand All @@ -14,44 +26,63 @@ interactions:
connection:
- keep-alive
content-length:
- '261'
- '250'
content-type:
- application/json
host:
- localhost:11434
user-agent:
- OpenAI/Python 1.50.0
- OpenAI/Python 1.50.2
x-stainless-arch:
- x64
- arm64
x-stainless-async:
- 'false'
x-stainless-lang:
- python
x-stainless-os:
- Linux
- MacOS
x-stainless-package-version:
- 1.50.0
- 1.50.2
x-stainless-retry-count:
- '0'
x-stainless-runtime:
- CPython
x-stainless-runtime-version:
- 3.10.12
- 3.12.6
method: POST
uri: http://localhost:11434/v1/chat/completions
response:
body:
string: '{"id":"chatcmpl-398","object":"chat.completion","created":1727962341,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"message":{"role":"assistant","content":"The
Great British Oceanic Peninsula."},"finish_reason":"stop"}],"usage":{"prompt_tokens":46,"completion_tokens":8,"total_tokens":54}}

'
string: |-
{
"id": "chatcmpl-46",
"object": "chat.completion",
"created": 1731311779,
"model": "qwen2.5:0.5b",
"system_fingerprint": "fp_ollama",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "The Falklands Islands are located in Atlantic Oceans."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 46,
"completion_tokens": 12,
"total_tokens": 58
}
}
headers:
Content-Length:
- '322'
- '339'
Content-Type:
- application/json
Date:
- Thu, 03 Oct 2024 13:32:21 GMT
- Mon, 11 Nov 2024 07:56:19 GMT
Set-Cookie: test_set_cookie
openai-organization: test_openai_org_key
status:
Expand Down
Loading