Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

AI Python Backend

This is the Python backend for the AI chat application, built with FastAPI.

Features

  • RESTful API for AI chat functionality
  • Integration with ModelScope AI API (compatible with OpenAI)
  • Function calling support for weather information and calculator
  • CORS support for frontend integration
  • Modular architecture with clear separation of concerns

Project Structure

ai-python-work/
├── app/
│   ├── __init__.py
│   ├── main.py                 # FastAPI应用初始化
│   ├── config/
│   │   ├── __init__.py
│   │   └── settings.py         # 配置管理
│   ├── api/
│   │   ├── __init__.py
│   │   └── routes/
│   │       ├── __init__.py
│   │       └── chat.py         # 聊天API路由
│   ├── services/
│   │   ├── __init__.py
│   │   ├── ai_service.py       # AI服务
│   │   ├── weather_service.py  # 天气服务
│   │   └── calculator_service.py # 计算器服务
│   └── utils/
│       ├── __init__.py
│       └── constants.py        # 常量定义(如城市代码)
├── .env                        # 环境变量
├── requirements.txt            # 依赖包
├── README.md                   # 项目文档
├── run.py                      # 应用启动入口
└── main.py                     # 兼容旧版本的启动方式

Setup

  1. Install dependencies:
pip install -r requirements.txt
  1. Run the application:
python run.py

Or with uvicorn:

uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

API Endpoints

  • GET /api/chat?question={question} - Get AI response for a question

Configuration

The application uses environment variables for configuration:

  • OPENAI_API_KEY - API key for the AI service (defaults to provided key)
  • OPENAI_API_HOST - Host for the AI API (defaults to ModelScope)

Supported Functions

The AI can call these functions:

  1. queryWeather - Get weather information for a city
  2. calculator - Perform basic mathematical operations

Architecture

The project follows a modular architecture with clear separation of concerns:

  • Config Layer: Handles all configuration management
  • API Layer: Defines REST endpoints and handles HTTP requests
  • Service Layer: Contains business logic for different functionalities
  • Utils Layer: Provides utility functions and constants

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages