Skip to content

Commit

Permalink
Merge pull request #12 from datastax/streaming-function-calling
Browse files Browse the repository at this point in the history
Streaming Function calling support
  • Loading branch information
phact authored Mar 18, 2024
2 parents 22d200a + 4365b37 commit 47d3e35
Show file tree
Hide file tree
Showing 9 changed files with 420 additions and 43 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -380,3 +380,37 @@ jobs:
- name: run tests
run: |
poetry run pytest -s --disable-warnings tests/streaming-assistants/test_streaming_run.py
run-streaming-assistants-tests-streaming-run-function-calling:
runs-on: ubuntu-latest
name: run streaming-assistants streaming run 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 }}

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/streaming-assistants/test_streaming_run_function_calling.py
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.1.2
v0.1.3
17 changes: 3 additions & 14 deletions examples/python/streaming_runs/basic.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import time
from openai import OpenAI
from dotenv import load_dotenv
from openai.types.beta.assistant_stream_event import ThreadMessageDelta
from streaming_assistants import patch
from openai.lib.streaming import AssistantEventHandler
from typing_extensions import override


load_dotenv("./.env")
Expand Down Expand Up @@ -36,21 +32,14 @@ def run_with_assistant(assistant, client):
)
print(f"> {user_message}")

class EventHandler(AssistantEventHandler):
@override
def on_text_delta(self, delta, snapshot):
# Increment the counter each time the method is called
print(delta.value, end="", flush=True)

print(f"creating run")
with client.beta.threads.runs.create_and_stream(
thread_id=thread.id,
assistant_id=assistant.id,
event_handler=EventHandler(),
) as stream:
for part in stream:
if not isinstance(part, ThreadMessageDelta):
print(f'received event: {part}\n')
for text in stream.text_deltas:
print(text, end="", flush=True)
print()

print("\n")

Expand Down
2 changes: 1 addition & 1 deletion impl/astra_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ def get_run(self, id, thread_id):
required_action_object = RunObjectRequiredAction.parse_raw(required_action)
run = RunObject(
id=json_rows["id"],
object="run",
object="thread.run",
created_at=created_at,
thread_id=json_rows["thread_id"],
assistant_id=json_rows["assistant_id"],
Expand Down
5 changes: 5 additions & 0 deletions impl/model/submit_tool_outputs_run_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from typing import Optional
from openapi_server.models.submit_tool_outputs_run_request import SubmitToolOutputsRunRequest as SubmitToolOutputsRunRequestGenerated

class SubmitToolOutputsRunRequest(SubmitToolOutputsRunRequestGenerated):
stream: Optional[bool] = None
Loading

0 comments on commit 47d3e35

Please sign in to comment.