|
1 | 1 | import os |
| 2 | +import json |
2 | 3 | import pytest |
3 | 4 | from click.testing import CliRunner |
4 | 5 | from devchat.config import ConfigManager, OpenAIModelConfig |
@@ -110,43 +111,43 @@ def test_prompt_with_instruct_and_context(git_repo, temp_files): # pylint: disa |
110 | 111 | assert get_content(result.output).find("hot summer\n") >= 0 |
111 | 112 |
|
112 | 113 |
|
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] |
150 | 151 |
|
151 | 152 |
|
152 | 153 | def test_prompt_log_compatibility(): |
|
0 commit comments