-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from weaviate/agentic-architectures
Setup for agentic architecture refactor
- Loading branch information
Showing
6 changed files
with
243 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
name: Python Tests | ||
|
||
on: | ||
push: | ||
branches: [ "gorilla" ] | ||
pull_request: | ||
branches: [ "gorilla" ] | ||
|
||
jobs: | ||
build-and-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: '3.9' | ||
|
||
- name: Install dependencies | ||
run: pip install -r requirements.txt | ||
|
||
# Step 4: Run tests | ||
- name: Run pytest | ||
run: pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"🔭 OpenTelemetry Tracing Details 🔭\n", | ||
"| Phoenix Project: default\n", | ||
"| Span Processor: SimpleSpanProcessor\n", | ||
"| Collector Endpoint: https://app.phoenix.arize.com/v1/traces\n", | ||
"| Transport: HTTP\n", | ||
"| Transport Headers: {'api_key': '****'}\n", | ||
"| \n", | ||
"| Using a default SpanProcessor. `add_span_processor` will overwrite this default.\n", | ||
"| \n", | ||
"| `register` has set this TracerProvider as the global OpenTelemetry default.\n", | ||
"| To disable this behavior, call `register` with `set_global_tracer_provider=False`.\n", | ||
"\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import os\n", | ||
"from phoenix.otel import register\n", | ||
"\n", | ||
"# Add Phoenix API Key for tracing\n", | ||
"PHOENIX_API_KEY = os.getenv(\"PHOENIX_API_KEY\")\n", | ||
"os.environ[\"PHOENIX_CLIENT_HEADERS\"] = f\"api_key={PHOENIX_API_KEY}\"\n", | ||
"\n", | ||
"# configure the Phoenix tracer\n", | ||
"tracer_provider = register(\n", | ||
" endpoint=\"https://app.phoenix.arize.com/v1/traces\",\n", | ||
") " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from openinference.instrumentation.openai import OpenAIInstrumentor\n", | ||
"\n", | ||
"OpenAIInstrumentor().instrument(tracer_provider=tracer_provider)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"Failed to export batch code: 204, reason: \n" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"There are 5,280 feet in a mile.\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"from pydantic_ai import Agent\n", | ||
"\n", | ||
"agent = Agent( \n", | ||
" 'openai:gpt-4o',\n", | ||
" system_prompt='Be concise, reply with one sentence.', \n", | ||
")\n", | ||
"\n", | ||
"result = await agent.run('How many feet are in a mile?') \n", | ||
"print(result.data)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"Failed to export batch code: 204, reason: \n" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"greeting=\"Hello, Alice! It's great to see you!\"\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import nest_asyncio\n", | ||
"nest_asyncio.apply()\n", | ||
"\n", | ||
"import asyncio\n", | ||
"from dataclasses import dataclass\n", | ||
"\n", | ||
"from pydantic import BaseModel, Field\n", | ||
"from pydantic_ai import Agent, RunContext\n", | ||
"\n", | ||
"\n", | ||
"@dataclass\n", | ||
"class NameContext:\n", | ||
" \"\"\"Dependencies (context) for the conversation.\"\"\"\n", | ||
" user_name: str\n", | ||
"\n", | ||
"\n", | ||
"class GreetingResult(BaseModel):\n", | ||
" \"\"\"Structured output from the AI.\"\"\"\n", | ||
" greeting: str = Field(description=\"A short greeting to the user\")\n", | ||
"\n", | ||
"\n", | ||
"greeting_agent = Agent(\n", | ||
" model=\"openai:gpt-4o\",\n", | ||
" deps_type=NameContext,\n", | ||
" result_type=GreetingResult,\n", | ||
" system_prompt=(\n", | ||
" \"You are a personalized greeter AI. \"\n", | ||
" \"Return a short greeting for the user.\"\n", | ||
" ),\n", | ||
")\n", | ||
"\n", | ||
"\n", | ||
"@greeting_agent.system_prompt\n", | ||
"async def add_user_name(ctx: RunContext[NameContext]) -> str:\n", | ||
" return f\"The user's name is {ctx.deps.user_name!r}.\"\n", | ||
"\n", | ||
"\n", | ||
"async def main():\n", | ||
" deps = NameContext(user_name=\"Alice\")\n", | ||
"\n", | ||
" result = await greeting_agent.run(\n", | ||
" \"Hi, can you greet me?\",\n", | ||
" deps=deps\n", | ||
" )\n", | ||
"\n", | ||
" print(result.data)\n", | ||
"\n", | ||
"await main()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"```\n", | ||
"{\"messages\": [{\"role\": \"system\", \"content\": \"You are a personalized greeter AI. Return a short greeting for the user.\"}, {\"role\": \"system\", \"content\": \"The user's name is 'Alice'.\"}, {\"role\": \"user\", \"content\": \"Hi, can you greet me?\"}], \"model\": \"gpt-4o\", \"n\": 1, \"parallel_tool_calls\": true, \"stream\": false, \"tool_choice\": \"required\", \"tools\": [{\"type\": \"function\", \"function\": {\"name\": \"final_result\", \"description\": \"Structured output from the AI.\", \"parameters\": {\"properties\": {\"greeting\": {\"description\": \"A short greeting to the user\", \"title\": \"Greeting\", \"type\": \"string\"}}, \"required\": [\"greeting\"], \"title\": \"GreetingResult\", \"type\": \"object\"}}}]}\n", | ||
"```" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.10" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pytest==8.3.4 |
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# tests/test_tests.py | ||
|
||
import sys | ||
|
||
def test_basic_math(): | ||
""" | ||
A trivial test to verify pytest is running. | ||
""" | ||
assert 1 + 1 == 2, "Basic math failed, so something is off!" | ||
|
||
def test_python_version(): | ||
""" | ||
This test checks if the Python version is at least 3.8. | ||
Adjust the version requirement as needed. | ||
""" | ||
major, minor = sys.version_info[:2] | ||
assert (major == 3 and minor >= 8), ( | ||
f"Expected Python 3.8+ but found Python {major}.{minor}." | ||
) | ||
|
||
def test_pytest_is_installed(): | ||
""" | ||
A quick sanity check to ensure 'pytest' is recognized. | ||
The fact that we're running this test at all typically | ||
confirms pytest is installed, but let's be explicit. | ||
""" | ||
try: | ||
import pytest # noqa: F401 # just to check import | ||
except ImportError as e: | ||
assert False, f"pytest not installed or not found: {e}" |