Skip to content

Commit

Permalink
add tools
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Cole <[email protected]>
  • Loading branch information
codefromthecrypt committed Sep 25, 2024
1 parent a708ba2 commit 42e5d99
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 3 deletions.
74 changes: 74 additions & 0 deletions tests/providers/cassettes/test_azure_tools.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
interactions:
- request:
body: '{"messages": [{"role": "system", "content": "You are a helpful assistant.
Expect to need to read a file using read_file."}, {"role": "user", "content":
"What are the contents of this file? test.txt"}], "model": "gpt-4o-mini", "tools":
[{"type": "function", "function": {"name": "read_file", "description": "Read
the contents of the file.", "parameters": {"type": "object", "properties": {"filename":
{"type": "string", "description": "The path to the file, which can be relative
or\nabsolute. If it is a plain filename, it is assumed to be in the\ncurrent
working directory."}}, "required": ["filename"]}}}]}'
headers:
accept:
- '*/*'
accept-encoding:
- gzip, deflate
api-key:
- test_azure_api_key
connection:
- keep-alive
content-length:
- '608'
content-type:
- application/json
host:
- test.openai.azure.com
user-agent:
- python-httpx/0.27.2
method: POST
uri: https://test.openai.azure.com/openai/deployments/test-azure-deployment/chat/completions?api-version=2024-05-01-preview
response:
body:
string: '{"choices":[{"content_filter_results":{},"finish_reason":"tool_calls","index":0,"logprobs":null,"message":{"content":null,"role":"assistant","tool_calls":[{"function":{"arguments":"{\n \"filename\":
\"test.txt\"\n}","name":"read_file"},"id":"call_a47abadDxlGKIWjvYYvGVAHa","type":"function"}]}}],"created":1727256650,"id":"chatcmpl-ABIeABbq5WVCq0e0AriGFaYDSih3P","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":16,"prompt_tokens":109,"total_tokens":125}}
'
headers:
Cache-Control:
- no-cache, must-revalidate
Content-Length:
- '769'
Content-Type:
- application/json
Date:
- Wed, 25 Sep 2024 09:30:50 GMT
Set-Cookie: test_set_cookie
Strict-Transport-Security:
- max-age=31536000; includeSubDomains; preload
access-control-allow-origin:
- '*'
apim-request-id:
- 8c0e3372-8ffd-4ff5-a5d1-0b962c4ea339
azureml-model-session:
- d145-20240919052126
openai-organization: test_openai_org_key
x-accel-buffering:
- 'no'
x-content-type-options:
- nosniff
x-ms-client-request-id:
- 8c0e3372-8ffd-4ff5-a5d1-0b962c4ea339
x-ms-rai-invoked:
- 'true'
x-ms-region:
- Switzerland North
x-ratelimit-remaining-requests:
- '79'
x-ratelimit-remaining-tokens:
- '79824'
x-request-id:
- 401bd803-b790-47b7-b098-98708d44f060
status:
code: 200
message: OK
version: 1
27 changes: 25 additions & 2 deletions tests/providers/test_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import pytest

from exchange import Text
from exchange import Text, ToolUse
from exchange.providers.azure import AzureProvider
from .conftest import complete
from .conftest import complete, tools

AZURE_MODEL = os.getenv("AZURE_MODEL", "gpt-4o-mini")

Expand All @@ -23,3 +23,26 @@ def test_azure_complete_integration():

assert reply[0].content is not None
print("Completion content from Azure:", reply[0].content)


@pytest.mark.vcr()
def test_azure_tools(default_azure_env):
reply_message, reply_usage = tools(AzureProvider, AZURE_MODEL)

tool_use = reply_message.content[0]
assert isinstance(tool_use, ToolUse)
assert tool_use.id == "call_a47abadDxlGKIWjvYYvGVAHa"
assert tool_use.name == "read_file"
assert tool_use.parameters == {"filename": "test.txt"}
assert reply_usage.total_tokens == 125


@pytest.mark.integration
def test_azure_tools_integration():
reply = tools(AzureProvider, AZURE_MODEL)

tool_use = reply[0].content[0]
assert isinstance(tool_use, ToolUse)
assert tool_use.id is not None
assert tool_use.name == "read_file"
assert tool_use.parameters == {"filename": "test.txt"}
2 changes: 1 addition & 1 deletion tests/providers/test_ollama.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def test_ollama_complete_integration():


@pytest.mark.vcr()
def test_ollama_tools(default_openai_env):
def test_ollama_tools():
reply_message, reply_usage = tools(OllamaProvider, OLLAMA_MODEL)

tool_use = reply_message.content[0]
Expand Down

0 comments on commit 42e5d99

Please sign in to comment.