mirror of
https://github.com/microsoft/autogen.git
synced 2025-08-01 21:32:38 +00:00

* --skip-openai * All tests pass * Update build.yml * Update Contribute.md * Fix for failing Ubuntu tests * More tests skipped, fixing 3.10 build * Apply suggestions from code review Co-authored-by: Qingyun Wu <qingyun0327@gmail.com> * Added more comments * fixed test__wrap_function_* --------- Co-authored-by: Qingyun Wu <qingyun0327@gmail.com> Co-authored-by: Davor Runje <davor@airt.ai>
89 lines
2.9 KiB
Python
89 lines
2.9 KiB
Python
import pytest
|
|
from autogen import OpenAIWrapper, config_list_from_json, config_list_openai_aoai
|
|
from conftest import skip_openai
|
|
|
|
try:
|
|
from openai import OpenAI
|
|
except ImportError:
|
|
skip = True
|
|
else:
|
|
skip = False or skip_openai
|
|
|
|
KEY_LOC = "notebook"
|
|
OAI_CONFIG_LIST = "OAI_CONFIG_LIST"
|
|
|
|
|
|
@pytest.mark.skipif(skip, reason="openai>=1 not installed")
|
|
def test_aoai_chat_completion_stream():
|
|
config_list = config_list_from_json(
|
|
env_or_file=OAI_CONFIG_LIST,
|
|
file_location=KEY_LOC,
|
|
filter_dict={"api_type": ["azure"], "model": ["gpt-3.5-turbo", "gpt-35-turbo"]},
|
|
)
|
|
client = OpenAIWrapper(config_list=config_list)
|
|
response = client.create(messages=[{"role": "user", "content": "2+2="}], stream=True)
|
|
print(response)
|
|
print(client.extract_text_or_completion_object(response))
|
|
|
|
|
|
@pytest.mark.skipif(skip, reason="openai>=1 not installed")
|
|
def test_chat_completion_stream():
|
|
config_list = config_list_from_json(
|
|
env_or_file=OAI_CONFIG_LIST,
|
|
file_location=KEY_LOC,
|
|
filter_dict={"model": ["gpt-3.5-turbo", "gpt-35-turbo"]},
|
|
)
|
|
client = OpenAIWrapper(config_list=config_list)
|
|
response = client.create(messages=[{"role": "user", "content": "1+1="}], stream=True)
|
|
print(response)
|
|
print(client.extract_text_or_completion_object(response))
|
|
|
|
|
|
@pytest.mark.skipif(skip, reason="openai>=1 not installed")
|
|
def test_chat_functions_stream():
|
|
config_list = config_list_from_json(
|
|
env_or_file=OAI_CONFIG_LIST,
|
|
file_location=KEY_LOC,
|
|
filter_dict={"model": ["gpt-3.5-turbo", "gpt-35-turbo"]},
|
|
)
|
|
functions = [
|
|
{
|
|
"name": "get_current_weather",
|
|
"description": "Get the current weather",
|
|
"parameters": {
|
|
"type": "object",
|
|
"properties": {
|
|
"location": {
|
|
"type": "string",
|
|
"description": "The city and state, e.g. San Francisco, CA",
|
|
},
|
|
},
|
|
"required": ["location"],
|
|
},
|
|
},
|
|
]
|
|
client = OpenAIWrapper(config_list=config_list)
|
|
response = client.create(
|
|
messages=[{"role": "user", "content": "What's the weather like today in San Francisco?"}],
|
|
functions=functions,
|
|
stream=True,
|
|
)
|
|
print(response)
|
|
print(client.extract_text_or_completion_object(response))
|
|
|
|
|
|
@pytest.mark.skipif(skip, reason="openai>=1 not installed")
|
|
def test_completion_stream():
|
|
config_list = config_list_openai_aoai(KEY_LOC)
|
|
client = OpenAIWrapper(config_list=config_list)
|
|
response = client.create(prompt="1+1=", model="gpt-3.5-turbo-instruct", stream=True)
|
|
print(response)
|
|
print(client.extract_text_or_completion_object(response))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
test_aoai_chat_completion_stream()
|
|
test_chat_completion_stream()
|
|
test_chat_functions_stream()
|
|
test_completion_stream()
|