Skip to content

Commit d40ad95

Browse files
committed
add function calling test cases
1 parent 57d4b20 commit d40ad95

3 files changed

Lines changed: 43 additions & 41 deletions

File tree

poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@ classifiers = [
1919

2020
[tool.poetry.dependencies]
2121
python = "^3.8"
22+
pydantic = "1.10.13"
2223
networkx = "^3.1"
23-
openai = {version="^1.0rc", allow-prereleases=true}
24-
pydantic = "^1.10.7"
24+
openai = "^1.0rc"
2525
rich_click = "^1.6.1"
2626
tiktoken = "^0.4.0"
2727
tinydb = "^4.7.1"
2828
urllib3 = "<2.0"
2929
importlib-metadata = "^6.8.0"
3030
gitpython = "^3.1.32"
3131
oyaml = "^1.0"
32+
colorama = "^0.4.6"
3233

3334
[tool.poetry.scripts]
3435
devchat = "devchat._cli.main:main"
@@ -40,4 +41,4 @@ gitpython = "^3.1.32"
4041

4142
[build-system]
4243
requires = ["poetry-core>=1.0.0"]
43-
build-backend = "poetry.core.masonry.api"
44+
build-backend = "poetry.core.masonry.api"

tests/test_cli_prompt.py

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import json
23
import pytest
34
from click.testing import CliRunner
45
from devchat.config import ConfigManager, OpenAIModelConfig
@@ -110,43 +111,43 @@ def test_prompt_with_instruct_and_context(git_repo, temp_files): # pylint: disa
110111
assert get_content(result.output).find("hot summer\n") >= 0
111112

112113

113-
# def test_prompt_with_functions(git_repo, functions_file): # pylint: disable=W0613
114-
# # call with -f option
115-
# result = runner.invoke(main, ['prompt', '-m', 'gpt-3.5-turbo', '-f', functions_file,
116-
# "What is the weather like in Boston?"])
117-
# if result.exit_code:
118-
# print(result.output)
119-
# assert result.exit_code == 0
120-
# content = get_content(result.output)
121-
# assert 'finish_reason: function_call' in content
122-
# assert '```command' in content
123-
# assert '"name": "get_current_weather"' in content
124-
125-
# # compare with no -f options
126-
# result = runner.invoke(main, ['prompt', '-m', 'gpt-3.5-turbo',
127-
# 'What is the weather like in Boston?'])
128-
129-
# content = get_content(result.output)
130-
# assert result.exit_code == 0
131-
# assert 'finish_reason: stop' not in content
132-
# assert 'command' not in content
133-
134-
135-
# def test_prompt_log_with_functions(git_repo, functions_file): # pylint: disable=W0613
136-
# # call with -f option
137-
# result = runner.invoke(main, ['prompt', '-m', 'gpt-3.5-turbo', '-f', functions_file,
138-
# 'What is the weather like in Boston?'])
139-
# if result.exit_code:
140-
# print(result.output)
141-
# assert result.exit_code == 0
142-
# prompt_hash = get_prompt_hash(result.output)
143-
# result = runner.invoke(main, ['log', '-t', prompt_hash])
144-
145-
# result_json = json.loads(result.output)
146-
# assert result.exit_code == 0
147-
# assert result_json[0]['request'] == 'What is the weather like in Boston?'
148-
# assert '```command' in result_json[0]['responses'][0]
149-
# assert 'get_current_weather' in result_json[0]['responses'][0]
114+
def test_prompt_with_functions(git_repo, functions_file): # pylint: disable=W0613
115+
# call with -f option
116+
result = runner.invoke(main, ['prompt', '-m', 'gpt-3.5-turbo', '-f', functions_file,
117+
"What is the weather like in Boston?"])
118+
if result.exit_code:
119+
print(result.output)
120+
assert result.exit_code == 0
121+
content = get_content(result.output)
122+
assert 'finish_reason: function_call' in content
123+
assert '```command' in content
124+
assert '"name": "get_current_weather"' in content
125+
126+
# compare with no -f options
127+
result = runner.invoke(main, ['prompt', '-m', 'gpt-3.5-turbo',
128+
'What is the weather like in Boston?'])
129+
130+
content = get_content(result.output)
131+
assert result.exit_code == 0
132+
assert 'finish_reason: stop' not in content
133+
assert 'command' not in content
134+
135+
136+
def test_prompt_log_with_functions(git_repo, functions_file): # pylint: disable=W0613
137+
# call with -f option
138+
result = runner.invoke(main, ['prompt', '-m', 'gpt-3.5-turbo', '-f', functions_file,
139+
'What is the weather like in Boston?'])
140+
if result.exit_code:
141+
print(result.output)
142+
assert result.exit_code == 0
143+
prompt_hash = get_prompt_hash(result.output)
144+
result = runner.invoke(main, ['log', '-t', prompt_hash])
145+
146+
result_json = json.loads(result.output)
147+
assert result.exit_code == 0
148+
assert result_json[0]['request'] == 'What is the weather like in Boston?'
149+
assert '```command' in result_json[0]['responses'][0]
150+
assert 'get_current_weather' in result_json[0]['responses'][0]
150151

151152

152153
def test_prompt_log_compatibility():

0 commit comments

Comments
 (0)