Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 61 additions & 8 deletions .github/scripts/run_single_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,50 @@ patch_dependencies() {
mv "$tmp_file" "$file"
}

is_server_example() {
grep -q "^[^#]*RagbitsAPI" "$1"
}

run_server_example() {
local file="$1"
local port=8000
local max_wait=60
local pid

echo "Starting server example: $file"
uv run "$file" &
pid=$!
trap 'kill "$pid" 2>/dev/null; wait "$pid" 2>/dev/null' EXIT

echo "Waiting for server to start (PID: $pid, port: $port)..."
local elapsed=0
while [[ $elapsed -lt $max_wait ]]; do
if ! kill -0 "$pid" 2>/dev/null; then
echo "Server process exited unexpectedly"
wait "$pid"
trap - EXIT
return $?
fi

if curl -sf "http://127.0.0.1:$port/api/config" > /dev/null 2>&1; then
echo "Server started successfully after ${elapsed}s"
kill "$pid" 2>/dev/null
wait "$pid" 2>/dev/null || true
trap - EXIT
return 0
fi

sleep 2
elapsed=$((elapsed + 2))
done

echo "Server failed to start within ${max_wait}s"
kill "$pid" 2>/dev/null
wait "$pid" 2>/dev/null || true
trap - EXIT
return 1
}

if ! has_script_section "$EXAMPLE_FILE"; then
echo "Skipping $EXAMPLE_FILE (no script section found)"
exit 0
Expand All @@ -71,15 +115,24 @@ fi
echo "Running the script: $EXAMPLE_FILE"
patch_dependencies "$EXAMPLE_FILE" "$PR_BRANCH"

set +e
timeout 120s uv run "$EXAMPLE_FILE"
exit_code=$?
set -e
if is_server_example "$EXAMPLE_FILE"; then
set +e
run_server_example "$EXAMPLE_FILE"
exit_code=$?
set -e
else
set +e
timeout 120s uv run "$EXAMPLE_FILE"
exit_code=$?
set -e

if [[ $exit_code -eq 124 ]]; then
echo "Script timed out after 120 seconds"
exit 1
fi
fi

if [[ $exit_code -eq 124 ]]; then
echo "Script timed out after 120 seconds"
exit 1
elif [[ $exit_code -ne 0 ]]; then
if [[ $exit_code -ne 0 ]]; then
echo "Script failed"
exit $exit_code
else
Expand Down
48 changes: 0 additions & 48 deletions .github/workflows/main-checks.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/pull-request-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

- name: Verify changelog updates
run: |
./.github/scripts/check_changelog_update.sh
./.github/scripts/check_changelog_update.sh ${{ github.event.pull_request.base.ref }}

check-pr-title:
name: Check pull request title
Expand Down
6 changes: 6 additions & 0 deletions examples/chat/authenticated_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,3 +373,9 @@ def get_multi_auth_backend() -> MultiAuthenticationBackend:
get_discord_auth_backend(), # Discord OAuth2 authentication
]
)


if __name__ == "__main__":
from ragbits.chat.api import RagbitsAPI

RagbitsAPI(MyAuthenticatedChat, auth_backend=get_auth_backend()).run()
7 changes: 6 additions & 1 deletion examples/chat/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# "ragbits-chat",
# ]
# ///
#

import asyncio
import uuid
Expand Down Expand Up @@ -224,3 +223,9 @@ async def chat(
yield self.create_usage_response(streaming_result.usage)

yield self.create_followup_messages(["Example Response 1", "Example Response 2", "Example Response 3"])


if __name__ == "__main__":
from ragbits.chat.api import RagbitsAPI

RagbitsAPI(MyChat).run()
6 changes: 6 additions & 0 deletions examples/chat/code_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,9 @@ async def chat(
description=self.planning_state.plan.last_completed_task.result,
)
yield self.create_plan_item_response(self.planning_state.plan.last_completed_task)


if __name__ == "__main__":
from ragbits.chat.api import RagbitsAPI

RagbitsAPI(CodePlannerChat).run()
6 changes: 6 additions & 0 deletions examples/chat/file_explorer_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,3 +629,9 @@ async def chat( # noqa: PLR0912
case Usage():
# Usage information
yield self.create_usage_response(response)


if __name__ == "__main__":
from ragbits.chat.api import RagbitsAPI

RagbitsAPI(FileExplorerChat).run()
6 changes: 6 additions & 0 deletions examples/chat/no_summary_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ async def chat(
streaming_result = self.llm.generate_streaming([*history, {"role": "user", "content": message}])
async for chunk in streaming_result:
yield self.create_text_response(chunk)


if __name__ == "__main__":
from ragbits.chat.api import RagbitsAPI

RagbitsAPI(MyChat).run()
6 changes: 6 additions & 0 deletions examples/chat/offline_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,9 @@ async def upload_handler(self, file: UploadFile) -> None: # noqa: PLR6301
# If you want to notify the user in the chat, the user would usually send a message
# mentioning they uploaded a file, or you could potentially trigger something else.
# Currently the flow is: UI uploads -> Backend handles -> UI gets 200 OK.


if __name__ == "__main__":
from ragbits.chat.api import RagbitsAPI

RagbitsAPI(MyChat).run()
5 changes: 3 additions & 2 deletions examples/chat/stream_events_from_tools_to_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
To run the API, use the following command:

```bash
uvicorn examples.chat.stream_events_from_tools_to_chat:app
ragbits api run examples.chat.stream_events_from_tools_to_chat:RevenueChatInterface
```
"""

Expand Down Expand Up @@ -110,4 +110,5 @@ async def chat(
yield chunk


app = RagbitsAPI(RevenueChatInterface).app
if __name__ == "__main__":
RagbitsAPI(RevenueChatInterface).run()
6 changes: 6 additions & 0 deletions examples/chat/themed_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ async def chat(self, message: str, history: list[dict], context: ChatContext) ->
response = await self.llm.generate(prompt)

yield ChatInterface.create_text_response(str(response))


if __name__ == "__main__":
from ragbits.chat.api import RagbitsAPI

RagbitsAPI(MyChat).run()
10 changes: 8 additions & 2 deletions examples/chat/tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
# "ragbits-agents"
# ]
# ///
#

import base64
from collections.abc import AsyncGenerator
Expand All @@ -43,6 +42,7 @@
from ragbits.agents import Agent, ToolCallResult
from ragbits.agents.tools.openai import get_image_generation_tool, get_web_search_tool
from ragbits.chat.auth import ListAuthenticationBackend
from ragbits.chat.auth.session_store import InMemorySessionStore
from ragbits.chat.interface import ChatInterface
from ragbits.chat.interface.forms import FeedbackConfig, UserSettings
from ragbits.chat.interface.types import ChatContext, ChatResponse, LiveUpdateType
Expand Down Expand Up @@ -259,4 +259,10 @@ def get_auth_backend() -> ListAuthenticationBackend:
},
]

return ListAuthenticationBackend(users)
return ListAuthenticationBackend(users, session_store=InMemorySessionStore())


if __name__ == "__main__":
from ragbits.chat.api import RagbitsAPI

RagbitsAPI(MyChat, auth_backend=get_auth_backend()).run()
6 changes: 6 additions & 0 deletions examples/chat/upload_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ async def upload_handler(self, file: UploadFile) -> None: # noqa: PLR6301
# If you want to notify the user in the chat, the user would usually send a message
# mentioning they uploaded a file, or you could potentially trigger something else.
# Currently the flow is: UI uploads -> Backend handles -> UI gets 200 OK.


if __name__ == "__main__":
from ragbits.chat.api import RagbitsAPI

RagbitsAPI(UploadChat).run()
Loading