This demo project integrates URL fetching capabilities into a chat application using Semantic Kernel.
In this demo, we use Semantic Kernel to integrate a custom Python plugin. This plugin extracts web content from URLs specified within the chat prompt.
static/
- Contains webclient HTML.env
- Environment variable configurations.env.example
- Example environment configuration fileDockerfile
- Docker configurationapi-key.txt
- Placeholder for API key storageapp.py
- Main application scriptdocker-compose.yml
- Docker Compose configurationfetchurl.py
- Script for fetching URLsrequirements.txt
- Python dependencies
- Azure account (step-by-step guide)
- GPT4o deployed in Microsoft AI Studio (step-by-step guide steps:#1 to #3)
- Basic Python knowledge
git clone https://github.com/KostaMalsev/fetchurl-chat-semantic-kernel-demo
cd fetchurl-chat-semantic-kernel-demo
- Update your
AZURE_OPENAI_ENDPOINT
indocker-compose.yml
- Update the
api-key.txt
with yourAZURE_OPENAI_API_KEY
You can run the application using Docker or directly with Python.
- Install Docker Compose (step-by-step guide)
- Run the following command:
docker-compose up
- Test the demo in your browser at http://localhost:8000/static/webclient.html
Note: You can find the Docker image of the service on DockerHub: chatserver
python app.py
- Uses
semantic_kernel
for model invocation with FetchPlugin - Implements FastAPI endpoint at
localhost:8000/demoprompt
for handling chat prompts - Uses
fetchurl
for web content retrieval
class FetchPlugin:
@kernel_function(name="get_content_from_url", description="Get the content from url")
def get_content_from_url(self, url: str) -> str:
return fetch_text_content_from_url(url)
- On startup: Sets up kernel with AI service and FetchPlugin
- On request: Invokes model via kernel with the FetchPlugin
- Returns model response to web client
- This demo uses a single plugin, but Semantic Kernel supports multiple custom plugins
- The fetch method is limited and may not work on all websites
- Be aware of AI API usage costs. Use Azure Cost Management for budgeting and monitoring