From 669ce6c9ce4d286472e2fc39b0cd6d41e00de42e Mon Sep 17 00:00:00 2001 From: phact Date: Wed, 29 May 2024 12:46:52 -0400 Subject: [PATCH] add streaming tests rm old messages test --- .github/workflows/run-tests.yml | 105 +++++++++++++++++++ tests/test_modify_and_delete_messages.py | 11 -- tests/test_patch_function_calling.py | 126 ----------------------- 3 files changed, 105 insertions(+), 137 deletions(-) delete mode 100644 tests/test_modify_and_delete_messages.py delete mode 100644 tests/test_patch_function_calling.py diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 4e67e1f..a3abb6a 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -216,3 +216,108 @@ jobs: - name: run tests run: | poetry run pytest -s --disable-warnings tests/test_run_retreival.py + run-streaming-assistants-tests-create-and-stream-run: + runs-on: ubuntu-latest + name: run streaming-assistants create and stream run tests + env: + ASTRA_DB_APPLICATION_TOKEN: ${{ secrets.ASTRA_DB_APPLICATION_TOKEN }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_REGION_NAME: ${{ secrets.AWS_REGION_NAME }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + base_url: ${{ secrets.BASE_URL }} + COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }} + GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + PERPLEXITYAI_API_KEY: ${{ secrets.PERPLEXITYAI_API_KEY }} + GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }} + + steps: + - name: Git checkout + uses: actions/checkout@v3 + - name: Set up Python 3.10.12 + uses: actions/setup-python@v2 + with: + python-version: '3.10.12' + - name: Install Poetry + run: | + curl -sSL https://install.python-poetry.org | python3 - + - name: Check Poetry Version + run: poetry --version + - name: Configure Poetry to Use Python 3.10.12 + run: poetry env use python3.10 + - name: get dependencies + run: | + poetry install + - name: run tests + run: | + poetry run pytest -s --disable-warnings tests/test_create_and_stream_run.py + run-streaming-assistants-tests-streaming-function-calling: + runs-on: ubuntu-latest + name: run streaming-assistants streaming function calling tests + env: + ASTRA_DB_APPLICATION_TOKEN: ${{ secrets.ASTRA_DB_APPLICATION_TOKEN }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_REGION_NAME: ${{ secrets.AWS_REGION_NAME }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + base_url: ${{ secrets.BASE_URL }} + COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }} + GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + PERPLEXITYAI_API_KEY: ${{ secrets.PERPLEXITYAI_API_KEY }} + GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }} + + steps: + - name: Git checkout + uses: actions/checkout@v3 + - name: Set up Python 3.10.12 + uses: actions/setup-python@v2 + with: + python-version: '3.10.12' + - name: Install Poetry + run: | + curl -sSL https://install.python-poetry.org | python3 - + - name: Check Poetry Version + run: poetry --version + - name: Configure Poetry to Use Python 3.10.12 + run: poetry env use python3.10 + - name: get dependencies + run: | + poetry install + - name: run tests + run: | + poetry run pytest -s --disable-warnings tests/test_streaming_function_calling.py + run-streaming-assistants-tests-streaming-calling-run: + runs-on: ubuntu-latest + name: run streaming-assistants streaming run tests + env: + ASTRA_DB_APPLICATION_TOKEN: ${{ secrets.ASTRA_DB_APPLICATION_TOKEN }} + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_REGION_NAME: ${{ secrets.AWS_REGION_NAME }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + base_url: ${{ secrets.BASE_URL }} + COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }} + GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + PERPLEXITYAI_API_KEY: ${{ secrets.PERPLEXITYAI_API_KEY }} + GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }} + + steps: + - name: Git checkout + uses: actions/checkout@v3 + - name: Set up Python 3.10.12 + uses: actions/setup-python@v2 + with: + python-version: '3.10.12' + - name: Install Poetry + run: | + curl -sSL https://install.python-poetry.org | python3 - + - name: Check Poetry Version + run: poetry --version + - name: Configure Poetry to Use Python 3.10.12 + run: poetry env use python3.10 + - name: get dependencies + run: | + poetry install + - name: run tests + run: | + poetry run pytest -s --disable-warnings tests/test_streaming_run.py diff --git a/tests/test_modify_and_delete_messages.py b/tests/test_modify_and_delete_messages.py deleted file mode 100644 index 554baf9..0000000 --- a/tests/test_modify_and_delete_messages.py +++ /dev/null @@ -1,11 +0,0 @@ -user_message = "puppies" -def test_threads(openai_client): - client = openai_client - - thread = client.beta.threads.create() - - message = client.beta.threads.messages.create( - thread_id=thread.id, role="user", content=user_message - ) - client.beta.threads.messages.update(thread_id=thread.id, message_id=message.id, content="kittens") - client.beta.threads.messages.delete(thread_id=thread.id, message_id=message.id) diff --git a/tests/test_patch_function_calling.py b/tests/test_patch_function_calling.py deleted file mode 100644 index 721f146..0000000 --- a/tests/test_patch_function_calling.py +++ /dev/null @@ -1,126 +0,0 @@ -import time - -import pytest - - -def test_function_calling_gpt_4(openai_client): - model="gpt-4-1106-preview" - function_calling(model, openai_client) - -def test_function_calling_gpt_3_5(openai_client): - model="gpt-3.5-turbo" - function_calling(model, openai_client) - - -def test_function_calling_groq(openai_client): - model="groq/llama3-8b-8192" - function_calling(model, openai_client) - -@pytest.mark.skip(reason="claude does not consistently work with function calling, skip") -def test_function_calling_cohere(openai_client): - model="cohere/command" - function_calling(model, openai_client) - -def test_function_calling_pplx_mix(openai_client): - model="perplexity/mixtral-8x7b-instruct" - function_calling(model, openai_client) - -@pytest.mark.skip(reason="pplx_online just looks up the weather and doesn't do the function call") -def test_function_calling_pplx_online(openai_client): - model="perplexity/pplx-70b-online" - function_calling(model, openai_client) - -@pytest.mark.skip(reason="claude does not consistently work with function calling, skip") -def test_function_calling_claude(openai_client): - model="anthropic.claude-v2" - function_calling(model, openai_client) - -def test_function_calling_gemini(openai_client): - model="gemini/gemini-pro" - function_calling(model, openai_client) - -@pytest.mark.skip(reason="llama does not consistently work with function calling, skip") -def test_function_calling_llama(openai_client): - model = "meta.llama2-13b-chat-v1" - function_calling(model, openai_client) - - -def function_calling(model, client): - print("make assistant") - assistant = client.beta.assistants.create( - name=f"Weather Bot {model}", - instructions="You are a weather bot. Use the provided functions to answer questions.", - model=model, - tools=[{ - "type": "function", - "function": { - "name": "getCurrentWeather", - "description": "Get the weather in location", - "parameters": { - "type": "object", - "properties": { - "location": {"type": "string", "description": "The city and state e.g. San Francisco, CA"}, - "unit": {"type": "string", "enum": ["c", "f"]} - }, - "required": ["location"] - } - } - }, { - "type": "function", - "function": { - "name": "getNickname", - "description": "Get the nickname of a city", - "parameters": { - "type": "object", - "properties": { - "location": {"type": "string", "description": "The city and state e.g. San Francisco, CA"}, - }, - "required": ["location"] - } - } - }] - ) - print(assistant) - - print("generating thread") - user_message="What's the weather like in Miami today?" - thread = client.beta.threads.create() - - client.beta.threads.messages.create( - thread_id=thread.id, role="user", content=user_message - ) - run = client.beta.threads.runs.create( - thread_id=thread.id, - assistant_id=assistant.id, - ) - print(thread) - print(run) - - def wait_on_run(run, thread): - while run.status == "queued" or run.status == "in_progress" or run.status == "generating": - run = client.beta.threads.runs.retrieve( - thread_id=thread.id, - run_id=run.id, - ) - time.sleep(0.5) - print(f"run {run}") - return run - - - run = wait_on_run(run, thread) - if run.required_action is not None: - print(run.required_action) - tool_outputs = [] - for tool_call in run.required_action.submit_tool_outputs.tool_calls: - tool_outputs.append({"tool_call_id": tool_call.id, "output": "75 and sunny"}) - - run = client.beta.threads.runs.submit_tool_outputs( - thread_id=thread.id, - run_id=run.id, - tool_outputs=tool_outputs - ) - run = wait_on_run(run, thread) - - messages = client.beta.threads.messages.list(thread_id=thread.id) - print(f"{model}-->") - print(messages.data[0].content[0].text.value) \ No newline at end of file