python-openai-demos  by pamelafox

Python scripts for OpenAI API demos

created 1 year ago
374 stars

Top 76.9% on sourcepulse

GitHubView on GitHub
Project Summary

This repository provides a comprehensive collection of Python scripts demonstrating the use of the OpenAI API for various natural language processing tasks, including chat completions, streaming responses, conversational history, and Retrieval-Augmented Generation (RAG). It targets developers and researchers looking to integrate OpenAI's capabilities into their applications, offering practical examples with popular LLM libraries like Langchain and LlamaIndex.

How It Works

The scripts leverage the official OpenAI Python SDK, showcasing direct API interactions and integration with higher-level frameworks. Key features include handling chat history for context-aware conversations, implementing streaming for real-time responses, and demonstrating RAG patterns for knowledge-grounded generation. Advanced examples cover asynchronous operations, content safety filtering, and structured output generation using Pydantic models for function calling and data extraction.

Quick Start & Requirements

  • Install dependencies: python -m pip install -r requirements.txt (or requirements-rag.txt for RAG examples).
  • Configure environment variables in .env for API host (Azure OpenAI, OpenAI.com, Ollama, GitHub), API keys, and model names.
  • Dev Container/GitHub Codespaces provide an automated setup.
  • Official Docs: https://github.com/pamelafox/python-openai-demos

Highlighted Details

  • Demonstrates RAG with CSV, multi-turn chat, query rewriting, PDF ingestion, and hybrid retrieval (vector + keyword) with RRF.
  • Includes examples for structured outputs using Pydantic, including enums, nested models, and function calling.
  • Supports multiple OpenAI API backends: Azure OpenAI, OpenAI.com, Ollama, and GitHub models.
  • Features asynchronous API calls using asyncio.gather for concurrent requests.

Maintenance & Community

This repository is maintained by Pamela Fox. Further community engagement or roadmap details are not explicitly mentioned in the README.

Licensing & Compatibility

The repository's license is not specified in the README. Compatibility for commercial use or closed-source linking would depend on the underlying OpenAI API terms of service and any specific licenses for included libraries.

Limitations & Caveats

The repository requires API keys and potentially specific model deployments for Azure OpenAI, which may incur costs. Some advanced RAG features might require additional setup or specific model capabilities.

Health Check
Last commit

1 week ago

Responsiveness

1 day

Pull Requests (30d)
1
Issues (30d)
1
Star History
19 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.