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
@@ -0,0 +1,56 @@
interactions:
- request:
body: '{"messages": [{"role": "user", "content": "Answer in up to 3 words: Which
ocean contains the falkland islands?"}], "model": "qwen2.5:0.5b"}'
headers:
accept:
- application/json
accept-encoding:
- gzip, deflate
authorization:
- Bearer test_openai_api_key
connection:
- keep-alive
content-length:
- '139'
content-type:
- application/json
host:
- localhost:11434
user-agent:
- OpenAI/Python 1.34.0
x-stainless-arch:
- x64
x-stainless-async:
- 'false'
x-stainless-lang:
- python
x-stainless-os:
- Linux
x-stainless-package-version:
- 1.34.0
x-stainless-runtime:
- CPython
x-stainless-runtime-version:
- 3.10.12
method: POST
uri: http://localhost:11434/v1/chat/completions
response:
body:
string: '{"id":"chatcmpl-833","object":"chat.completion","created":1729263413,"model":"qwen2.5:0.5b","system_fingerprint":"fp_ollama","choices":[{"index":0,"message":{"role":"assistant","content":"The
Falklands Islands are located in which ocean?"},"finish_reason":"stop"}],"usage":{"prompt_tokens":46,"completion_tokens":11,"total_tokens":57}}

'
headers:
Content-Length:
- '336'
Content-Type:
- application/json
Date:
- Fri, 18 Oct 2024 14:56:53 GMT
Set-Cookie: test_set_cookie
openai-organization: test_openai_org_key
status:
code: 200
message: OK
version: 1
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ def vcr_cassette_name(request):
# TODO: we can probably rebuild the name from the request
# request.node.name format: test_basic[ollama_provider_chat_completions-Atlantic Ocean.-24-4-5]
test_name = re.match(r"(\w+\[\w+)", request.node.name)
return f"{test_name.group()}]"
if test_name:
return f"{test_name.group()}]"
# if we don't use parametrization return the default one
return request.node.name


class AzureProvider:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3312,3 +3312,32 @@ def test_with_model_not_found(
assert_error_operation_duration_metric(
provider, operation_duration_metric, attributes=attributes, data_point=duration
)


@pytest.mark.vcr()
def test_exported_schema_version(
ollama_provider_chat_completions,
trace_exporter,
metrics_reader,
):
client = ollama_provider_chat_completions.get_client()

messages = [
{
"role": "user",
"content": "Answer in up to 3 words: Which ocean contains the falkland islands?",
}
]

client.chat.completions.create(model="qwen2.5:0.5b", messages=messages)

spans = trace_exporter.get_finished_spans()
(span,) = spans
assert span.instrumentation_scope.schema_url == "https://opentelemetry.io/schemas/1.27.0"

metrics_data = metrics_reader.get_metrics_data()
resource_metrics = metrics_data.resource_metrics

for metrics in resource_metrics:
for scope_metrics in metrics.scope_metrics:
assert scope_metrics.schema_url == "https://opentelemetry.io/schemas/1.27.0"
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from unittest import mock

import opentelemetry.instrumentation.openai
from opentelemetry.instrumentation.openai import OpenAIInstrumentor


Expand All @@ -31,25 +28,3 @@ def test_can_override_capture_content_programmatically(instrument):
instrumentor.instrument(capture_content=True)
assert instrumentor.capture_content
instrumentor.uninstrument()


def test_get_tracer_is_called_with_a_string_schema(instrument):
instrument.uninstrument()
instrumentor = OpenAIInstrumentor()
with mock.patch.object(opentelemetry.instrumentation.openai, "get_tracer") as get_tracer_mock:
instrumentor.instrument()
instrumentor.uninstrument()
get_tracer_mock.assert_called_once_with(
"opentelemetry.instrumentation.openai", mock.ANY, None, schema_url="https://opentelemetry.io/schemas/1.27.0"
)


def test_get_meter_is_called_with_a_string_schema(instrument):
instrument.uninstrument()
instrumentor = OpenAIInstrumentor()
with mock.patch.object(opentelemetry.instrumentation.openai, "get_meter") as get_meter_mock:
instrumentor.instrument()
instrumentor.uninstrument()
get_meter_mock.assert_called_once_with(
"opentelemetry.instrumentation.openai", mock.ANY, None, schema_url="https://opentelemetry.io/schemas/1.27.0"
)